diff --git a/src/tests.rs b/src/tests.rs index 2c7a5f4..182c336 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -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 }