From 102f2788a1e57abdf45036d743d2283b2afe5faa Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 9 Dec 2025 12:27:23 +0000 Subject: [PATCH] add basic tests for PersistentVector.delete --- test/persistent-vector-tests.sml | 65 ++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/test/persistent-vector-tests.sml b/test/persistent-vector-tests.sml index c16b311..4cb53d8 100644 --- a/test/persistent-vector-tests.sml +++ b/test/persistent-vector-tests.sml @@ -33,23 +33,58 @@ struct end val deleteTests = describe "PersistentVector.delete" - [test - "deletes last value correctly \ - \when only last value is in deletion range" - (fn _ => - let - (* arrange *) - val pv = Pv.fromList [(0, 0), (3, 3), (5, 5)] + [ test + "deletes last value correctly \ + \when only last value is in deletion range" + (fn _ => + let + (* arrange *) + val pv = Pv.fromList [(0, 0), (3, 3), (5, 5)] - (* act *) - val pv = Pv.delete (5, 1, pv) + (* act *) + val pv = Pv.delete (5, 1, pv) - (* assert *) - val outputList = Pv.toList pv - val expectedList = [(0, 0), (3, 3)] - in - Expect.isTrue (outputList = expectedList) - end)] + (* assert *) + val outputList = Pv.toList pv + val expectedList = [(0, 0), (3, 3)] + in + Expect.isTrue (outputList = expectedList) + end) + , test + "deletes middle value correctly \ + \and adjusts values-after-middle as well" + (fn _ => + let + (* arrange *) + val pv = Pv.fromList [(0, 0), (3, 3), (5, 5)] + + (* act *) + val pv = Pv.delete (3, 1, pv) + + (* assert *) + val outputList = Pv.toList pv + val expectedList = [(0, 0), (4, 4)] + in + Expect.isTrue (outputList = expectedList) + end) + , test + "deletes first value correctly \ + \and adjusts values-after-first as well" + (fn _ => + let + (* arrange *) + val pv = Pv.fromList [(0, 0), (3, 3), (5, 5)] + + (* act *) + val pv = Pv.delete (0, 1, pv) + + (* assert *) + val outputList = Pv.toList pv + val expectedList = [(2, 2), (4, 4)] + in + Expect.isTrue (outputList = expectedList) + end) + ] val tests = [appendTests, deleteTests] end