-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunit_tests.rs
98 lines (83 loc) · 2.89 KB
/
unit_tests.rs
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#[cfg(test)]
mod unit_tests {
use plox::{
rules::Order,
sorter::{self, Sorter},
*,
};
fn init() {
let env = env_logger::Env::default()
.default_filter_or(log_level_to_str(ELogLevel::Debug))
.default_write_style_or("always");
let _ = env_logger::Builder::from_env(env).is_test(true).try_init();
}
fn new_stable_full_sorter() -> Sorter {
Sorter::new(sorter::ESortType::StableFull, 1000)
}
#[test]
fn test_cycle() {
init();
let order = [
Order::from("a", "b").into(),
Order::from("b", "c").into(),
Order::from("d", "e").into(),
Order::from("b", "a").into(),
];
let mods: Vec<PluginData> = ["a", "b", "c", "d", "e", "f", "g"]
.iter()
.map(|e| PluginData::new(e.to_string(), 0))
.collect();
assert!(
sorter::new_unstable_sorter()
.topo_sort(ESupportedGame::Morrowind, &mods, &order, &[])
.is_err(),
"unstable rules do not contain a cycle"
);
assert!(
new_stable_full_sorter()
.topo_sort(ESupportedGame::Morrowind, &mods, &order, &[])
.is_err(),
"stable(false) rules do not contain a cycle"
);
assert!(
sorter::new_stable_sorter()
.topo_sort(ESupportedGame::Morrowind, &mods, &order, &[])
.is_err(),
"stable(true) rules do not contain a cycle"
);
}
#[test]
fn test_ordering() {
init();
let order = [
Order::from("b", "a").into(),
Order::from("b", "c").into(),
Order::from("d", "e").into(),
Order::from("e", "c").into(),
Order::from("test.archive", "test2.archive").into(),
];
let mods: Vec<PluginData> = ["d", "e", "f", "g", "a", "b", "c"]
.iter()
.map(|e| PluginData::new(e.to_string(), 0))
.collect();
match sorter::new_unstable_sorter().topo_sort(ESupportedGame::Morrowind, &mods, &order, &[])
{
Ok(result) => {
assert!(check_order(&result, &order), "stable(true) order is wrong");
}
Err(e) => panic!("Error: {}", e),
}
match new_stable_full_sorter().topo_sort(ESupportedGame::Morrowind, &mods, &order, &[]) {
Ok(result) => {
assert!(check_order(&result, &order), "stable(true) order is wrong");
}
Err(e) => panic!("Error: {}", e),
}
match sorter::new_stable_sorter().topo_sort(ESupportedGame::Morrowind, &mods, &order, &[]) {
Ok(result) => {
assert!(check_order(&result, &order), "stable(true) order is wrong");
}
Err(e) => panic!("Error: {}", e),
}
}
}