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
73
74
75
76
77
78
extern crate bincode;
mod language_profiler;
pub use self::language_profiler::Profiler as ChineseDetection;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn classify_english() {
let profiler = ChineseDetection::new();
let test_cases = vec!["this is a test",
"test",
"exam",
"whats up",
"desk",
"window",
"student"];
for test in test_cases {
assert_eq!("EN", profiler.classify(test.to_string()));
}
}
#[test]
fn classify_pinyin() {
let profiler = ChineseDetection::new();
let test_cases = vec!["zhe shi ge shiyan",
"shiyan",
"kaoshi",
"zenmeyang",
"zhuozi",
"chuanghu",
"xuesheng"];
for test in test_cases {
assert_eq!("PY", profiler.classify(test.to_string()));
}
}
#[test]
fn classify_chinese() {
let profiler = ChineseDetection::new();
let test_cases = vec!["这是个实验",
"实验",
"考试",
"怎么样",
"桌子",
"窗户",
"学生"];
for test in test_cases {
assert_eq!("ZH", profiler.classify(test.to_string()));
}
}
}