1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Kani proofs for char contract types.
use elicitation::{CharAlphabetic, CharNumeric, ValidationError};
// Char Contract Proofs
// ============================================================================
// Proof: Wrapper logic for alphabetic chars
#[kani::proof]
fn verify_char_alphabetic_accepts() {
let value: char = kani::any();
// Trust stdlib: if construction succeeds, the char is alphabetic
let result = CharAlphabetic::new(value);
if let Ok(alphabetic) = result {
// Verify: get() returns the original value
assert_eq!(alphabetic.get(), value);
assert_eq!(alphabetic.into_inner(), value);
}
}
// Proof: Wrapper logic for non-alphabetic chars
#[kani::proof]
fn verify_char_alphabetic_rejects() {
let value: char = kani::any();
let result = CharAlphabetic::new(value);
// Verify: if it fails, we get the correct error
if let Err(e) = result {
match e {
ValidationError::NotAlphabetic(_) => {
// Correct error type
}
_ => panic!("Wrong error type"),
}
}
}
// Proof: Wrapper logic for numeric chars
#[kani::proof]
fn verify_char_numeric_accepts() {
let value: char = kani::any();
let result = CharNumeric::new(value);
if let Ok(numeric) = result {
assert_eq!(numeric.get(), value);
assert_eq!(numeric.into_inner(), value);
}
}
// Proof: Wrapper logic for non-numeric chars
#[kani::proof]
fn verify_char_numeric_rejects() {
let value: char = kani::any();
let result = CharNumeric::new(value);
if let Err(e) = result {
match e {
ValidationError::NotNumeric(_) => {
// Correct error type
}
_ => panic!("Wrong error type"),
}
}
}
// ============================================================================
// Duration Contract Proofs