This commit is contained in:
Smaug123
2020-05-02 15:21:31 +01:00
parent 6a62871778
commit 8e3cd2a1a1
5 changed files with 85 additions and 64 deletions

View File

@@ -7,7 +7,7 @@ open FsUnitTyped
[<TestFixture>]
module TestVector =
[<Test>]
let example1 () =
let ``Basic construction`` () =
let v1 =
Vector.empty
|> Vector.cons 3
@@ -18,15 +18,32 @@ module TestVector =
let v2 = Vector.empty |> Vector.cons "hi" |> Vector.cons "bye"
v2 |> Vector.toList |> shouldEqual ["bye" ; "hi"]
[<Test>]
let ``Pattern matching`` () =
match Vector.empty with
| Empty () -> ()
//| Vec (a, b) -> failwith "" -- doesn't compile
let v1 =
Vector.empty
|> Vector.cons 3
|> Vector.cons 5
|> Vector.cons 6
match v1 with
| Vec (a , b) ->
a |> shouldEqual 6
b |> Vector.toList |> shouldEqual [5 ; 3]
match b with
| Vec (b, c) ->
b |> shouldEqual 5
match c with
| Vec (c, d) ->
c |> shouldEqual 3
match d with
| Empty () -> ()
[<Test>]
let ``Vector concatenation`` () =
let v1 =
Vector.empty
|> Vector.cons 3
@@ -43,24 +60,16 @@ module TestVector =
|> Vector.cons 5
|> Vector.cons 6
// They are equal vectors...
twice |> Vector.toList
|> shouldEqual (otherTwice |> Vector.toList)
// but their equality doesn't typecheck.
// twice |> shouldEqual otherTwice
// But sufficient safe casting can make it typecheck.
twice
|> Vector.cast
|> Vector.cast
|> Vector.cast
|> Vector.cast
|> shouldEqual otherTwice
[<Test>]
let foo () =
let v1 = Vector.empty |> Vector.cons 1
let twice = Vector.append v1 v1
let twiceAgain = Vector.empty |> Vector.cons 1 |> Vector.cons 1
twice
|> Vector.cast
|> Vector.cast
|> shouldEqual twiceAgain

View File

@@ -15,7 +15,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="UnitTest1.fs" />
<Compile Include="TestVector.fs" />
</ItemGroup>
<ItemGroup>