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
pub mod codes;
pub mod ic;
pub mod random;
pub use codes::{get_loc_code, LOC_CODES, REGION_CODES, SIGN_CODES, VERIFY_CODES};
pub use ic::{compute_verify_code, IdentityCard};
pub use random::generate_identitycard;
#[cfg(test)]
mod tests {
use crate::{generate_identitycard, IdentityCard};
use std::str::FromStr;
#[test]
fn test_random() {
let ic = generate_identitycard("610102".to_string(), "19910201".to_string());
assert_eq!(ic.to_string().starts_with("610102"), true);
assert_eq!(ic.to_string().starts_with("61010219910201"), true);
assert_eq!(ic.verify_ic(), true);
}
#[test]
fn test_fromstr() {
let ic_number = "440222199602175492";
let ic = IdentityCard::from_str(ic_number).unwrap();
println!("{:#?}\n{}", ic, ic);
assert_eq!(ic.to_string(), ic_number.to_string());
assert_eq!(ic.verify_ic(), true);
}
#[test]
fn test_leap() {
let ic = generate_identitycard("西安市".to_string(), "202002".to_string());
println!("{:#?}", ic);
assert_eq!(ic.verify_ic(), true)
}
}