begin adding tests for persistent-vector.sml, and add bug fix to 'PersistentVector.delete' in light of one of the tests. (We were decrementing by the wrong value previously, but I fixed it and added a comment of how we arrive at the value we want to decrement by
This commit is contained in:
55
test/persistent-vector-tests.sml
Normal file
55
test/persistent-vector-tests.sml
Normal file
@@ -0,0 +1,55 @@
|
||||
structure PersistentVectorTests =
|
||||
struct
|
||||
open Railroad
|
||||
open Railroad.Test
|
||||
|
||||
structure Pv = PersistentVector
|
||||
|
||||
val appendTests = describe "PersistentVector.append"
|
||||
[test "appends new values to end" (fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val pv = Pv.fromList [(1, 1), (3, 3)]
|
||||
|
||||
(* act *)
|
||||
val pv = Pv.append (5, 7, pv)
|
||||
|
||||
(* assert *)
|
||||
val outputList = Pv.toList pv
|
||||
val expectedList = [(1, 1), (3, 3), (5, 7)]
|
||||
in
|
||||
Expect.isTrue (outputList = expectedList)
|
||||
end)]
|
||||
|
||||
fun printList lst =
|
||||
let
|
||||
val str =
|
||||
List.map
|
||||
(fn (start, finish) =>
|
||||
"(" ^ Int.toString start ^ ", " ^ Int.toString finish ^ ")") lst
|
||||
val str = "[" ^ String.concatWith ", " str ^ "]\n"
|
||||
in
|
||||
print str
|
||||
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)]
|
||||
|
||||
(* 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)]
|
||||
|
||||
val tests = [appendTests, deleteTests]
|
||||
end
|
||||
@@ -5,13 +5,13 @@ struct
|
||||
|
||||
fun main () =
|
||||
let
|
||||
val tests =
|
||||
List.concat
|
||||
[ NormalMove.tests
|
||||
, NormalDelete.tests
|
||||
, Regression.tests
|
||||
, RegexTests.tests
|
||||
]
|
||||
val tests = List.concat
|
||||
[ NormalMove.tests
|
||||
, NormalDelete.tests
|
||||
, Regression.tests
|
||||
, RegexTests.tests
|
||||
, PersistentVectorTests.tests
|
||||
]
|
||||
val tests = concat tests
|
||||
in
|
||||
runWithConfig [Configuration.PrintPassed false] tests
|
||||
|
||||
Reference in New Issue
Block a user