marginal progression woooo

main
bel 2023-11-26 23:32:52 -07:00
parent 6955b7857c
commit 0722a6fc3b
1 changed files with 5 additions and 7 deletions

View File

@ -84,18 +84,14 @@ impl Storage {
fn from(&self, t: SystemTime) -> Storage {
let mut result = Storage{xs: vec![]};
self.xs.iter()
.filter(|x| !x.clone().clone().before(t))
.filter(|x| x.ts() >= t)
.for_each(|x| result.xs.push(x.clone()));
result
}
}
impl X {
fn before(self, t: SystemTime) -> bool {
self.ts() < t
}
fn ts(self) -> SystemTime {
fn ts(&self) -> SystemTime {
UNIX_EPOCH.add(Duration::from_secs(self.t.try_into().unwrap()))
}
}
@ -109,11 +105,13 @@ mod test_storage {
let given = Storage{xs: vec![
X{t: 1, x: "def".to_string(), tag: "abc".to_string()},
X{t: 2, x: "ghi".to_string(), tag: "".to_string()},
X{t: 3, x: "jkl".to_string(), tag: "".to_string()},
]};
let want = Storage{xs: vec![
X{t: 2, x: "ghi".to_string(), tag: "".to_string()},
X{t: 3, x: "jkl".to_string(), tag: "".to_string()},
]};
let got = given.from(UNIX_EPOCH.add(Duration::from_secs(1)));
let got = given.from(UNIX_EPOCH.add(Duration::from_secs(2)));
assert_eq!(got, want);
}
}