add a test for 'PersistentVector.delete' (even though the 'PersistentVector.merge' helper function is unimplemented)
This commit is contained in:
@@ -550,9 +550,9 @@ struct
|
||||
fun delete (start, finish, tree) =
|
||||
let
|
||||
val matchAfterFinish = nextMatch (finish, tree, 1)
|
||||
val left = splitRight (start, tree)
|
||||
val left = splitLeft (start, tree)
|
||||
in
|
||||
if matchAfterFinish = ~1 then
|
||||
if matchAfterFinish = ~1 then
|
||||
(* there is no match after 'finish', so just split left.
|
||||
* No need to decrement or split right,
|
||||
* because the right vector would be empty. *)
|
||||
|
||||
@@ -284,5 +284,39 @@ struct
|
||||
end)
|
||||
]
|
||||
|
||||
val tests = [appendTests, toListTests, splitLeftTests]
|
||||
val deleteTests = describe "PersistentVector.delete"
|
||||
[test
|
||||
"returns the left side of the vector \
|
||||
\when 'finish' is greater than any element in the vector"
|
||||
(fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val inputList =
|
||||
[ {start = 1, finish = 1}
|
||||
, {start = 2, finish = 2}
|
||||
, {start = 3, finish = 3}
|
||||
, {start = 4, finish = 4}
|
||||
, {start = 5, finish = 5}
|
||||
, {start = 6, finish = 6}
|
||||
, {start = 7, finish = 7}
|
||||
, {start = 8, finish = 8}
|
||||
]
|
||||
val pv = PersistentVector.fromList inputList
|
||||
|
||||
(* act *)
|
||||
val pv = PersistentVector.delete (5, 9, pv)
|
||||
|
||||
(* assert *)
|
||||
val outputList = PersistentVector.toList pv
|
||||
val expectedOutput =
|
||||
[ {start = 1, finish = 1}
|
||||
, {start = 2, finish = 2}
|
||||
, {start = 3, finish = 3}
|
||||
, {start = 4, finish = 4}
|
||||
]
|
||||
in
|
||||
Expect.isTrue (outputList = expectedOutput)
|
||||
end)]
|
||||
|
||||
val tests = [appendTests, toListTests, splitLeftTests, deleteTests]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user