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
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct AtlasVersion {
revision_count: u32,
}
impl AtlasVersion {
pub fn new_out_of_date() -> Self {
Self { revision_count: 0 }
}
pub fn is_out_of_date(&self, version: &Self) -> bool {
version.revision_count == 0
|| self.revision_count != version.revision_count
}
pub fn increment(&self) -> Self {
AtlasVersion {
revision_count: self.revision_count + 1,
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn same_versions_should_not_be_out_of_date() {
let v1 = AtlasVersion { revision_count: 1 };
let v2 = AtlasVersion { revision_count: 1 };
assert!(!v1.is_out_of_date(&v2));
}
#[test]
fn a_new_out_of_date_version_should_always_be_out_of_date() {
let v1 = AtlasVersion { revision_count: 0 };
let v2 = AtlasVersion::new_out_of_date();
assert!(v1.is_out_of_date(&v2));
}
#[test]
fn different_versions_should_be_out_of_date() {
let v1 = AtlasVersion { revision_count: 1 };
let v2 = AtlasVersion { revision_count: 2 };
assert!(v1.is_out_of_date(&v2));
}
}