-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCollectionsTests.fs
98 lines (77 loc) · 3.12 KB
/
CollectionsTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/// <summary>
/// Collections used in Starling.
/// </summary>
module Starling.Tests.Collections
open Starling.Collections
/// <summary>
/// Tests for collections.
/// </summary>
module Tests =
open NUnit.Framework
module Multiset =
module TestOfFlatList =
let check flatList lst =
let mset = Map.ofList lst |> MSet
Assert.AreEqual (Multiset.ofFlatList flatList, mset)
[<Test>]
let ``Multiset.ofFlatList creates empty multiset`` () =
check [] []
[<Test>]
let ``Multiset.ofFlatList multiple values`` () =
check [1; 1] [ (1, 2) ]
[<Test>]
let ``Multiset.ofFlatList multiple keys`` () =
check [1; 1; 2; 5; 2; 5; 7; 1]
<| [ (1, 3)
(2, 2)
(5, 2)
(7, 1) ]
module TestToFlatList =
let check lst flatList =
let mset = Map.ofList lst |> MSet
Assert.AreEqual(flatList, Multiset.toFlatList mset)
[<Test>]
let ``Multiset.toFlatList empty`` () =
check [] []
[<Test>]
let ``Multiset.toFlatList singleton`` () =
check [ (1, 1) ]
[ 1 ]
[<Test>]
let ``Multiset.toFlatList multiple`` () =
check [ (1, 2) ]
[ 1; 1 ]
[<Test>]
let ``Multiset.toFlatList repeated`` () =
check [ (1, 2); ]
[ 1; 1; ]
[<Test>]
let ``Multiset.toFlatList big`` () =
check [ (1, 2); (3, 1); (4, 5); ]
[ 1; 1; 3; 4; 4; 4; 4; 4; ]
module TestMultisetAppend =
let check inputMapList appendList outputMapList =
let mset = MSet <| Map.ofList inputMapList
let finalMSet = MSet <| Map.ofList outputMapList
let appendMset = Multiset.ofFlatList appendList
Assert.AreEqual(Multiset.append mset appendMset, finalMSet)
[<Test>]
let ``Multiset.append empty lhs`` () =
check [] [1] [ (1, 1) ]
[<Test>]
let ``Multiset.append empty rhs`` () =
check [ (1, 1) ] [] [ (1, 1) ]
[<Test>]
let ``Multiset.append increment`` () =
check [ (1, 1) ] [1] [ (1, 2) ]
[<Test>]
let ``Multiset.append big`` () =
check [ (1, 2); (2, 1); (3, 4) ] [1] [ (1, 3); (2, 1); (3, 4) ]
module TestMultisetFold =
let check inputFolderFunc inputMapList initial expectedOutput =
let mset = MSet <| Map.ofList inputMapList
let output = Multiset.fold inputFolderFunc initial mset
Assert.AreEqual(output, expectedOutput)
[<Test>]
let ``Multiset.append empty lhs`` () =
check (fun s _ _-> s) [] [] []