tests: Added tests for overlapping insertions.

Fortune for parapop's current commit: Future blessing − 末吉
master
Avril 3 years ago
parent 729786a568
commit 4a08c836aa
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -109,4 +109,38 @@ mod iteration {
"0", "1", "2", "3", "4",
], "Bad order of elements");
}
#[test]
fn single_threaded_overlapping_trivial()
{
let pop = Populator::new(10);
for (i, x) in (0..).zip(pop.iter_slice(0..5)) {
_ = x.try_insert(i);
}
for (i, x) in (0..).zip(pop.iter_slice(3..10)) {
_ = x.try_insert(i);
}
assert!(pop.try_insert(3, 100).is_err(), "Insertion of completed populator successed when it shouldn't have");
assert_eq!(&pop.complete()[..],
[0, 1, 2, 3, 4, 2, 3, 4, 5, 6],
"Overlapping insertions failed");
}
#[test]
fn single_threaded_overlapping_nontrivial()
{
let pop = Populator::new(10);
for (i, x) in (0..).zip(pop.iter_slice(0..5)) {
_ = x.try_insert(i.to_string());
}
for (i, x) in (0..).zip(pop.iter_slice(3..10)) {
_ = x.try_insert(i.to_string());
}
assert!(pop.try_insert(3, "hiya".to_string()).is_err(), "Insertion of completed populator successed when it shouldn't have");
assert_eq!(&pop.complete()[..],
["0", "1", "2", "3", "4",
"2", "3", "4", "5", "6"],
"Overlapping insertions failed");
}
//TODO: multi-threaded overlapping
}

Loading…
Cancel
Save