mirror of
https://github.com/Smaug123/fsharp-vectors
synced 2025-10-08 04:48:40 +00:00
Tidy up
This commit is contained in:
@@ -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
|
||||
|
@@ -15,7 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="UnitTest1.fs" />
|
||||
<Compile Include="TestVector.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user