From 4a08c836aa3f37ae4dccb43751a831b8a0ea1ab6 Mon Sep 17 00:00:00 2001 From: Avril Date: Sat, 26 Feb 2022 20:21:25 +0000 Subject: [PATCH] tests: Added tests for overlapping insertions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for parapop's current commit: Future blessing − 末吉 --- src/tests.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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 }