@@ -4,6 +4,62 @@ import org.scalatest.prop.TableDrivenPropertyChecks.Table
4
4
5
5
class CgsuiteUtilTest extends CgscriptSpec {
6
6
7
+ " cgsuite.util.MutableList" should " implement methods correctly" in {
8
+
9
+ executeTests(Table (
10
+ header,
11
+ (" MutableList: Construction (empty)" , " MutableList()" , " MutableList()" ),
12
+ (" MutableList: Construction (seeded)" , " x := MutableList([3,4,5])" , " MutableList(3, 4, 5)" ),
13
+ (" MutableList: Lookup" , " x[2]" , " 4" ),
14
+ (" MutableList: Lookup (not in list)" , " x[0]" , " !!List index out of bounds: 0" ),
15
+ (" MutableList: Add" , " x.Add(*); x" , " MutableList(3, 4, 5, *)" ),
16
+ (" MutableList: AddAll" , " x.AddAll([1/2, 1/4, *2, *3, 1/2, 1/4, *3]); x" , " MutableList(3, 4, 5, *, 1/2, 1/4, *2, *3, 1/2, 1/4, *3)" ),
17
+ (" MutableList: Contains" , " x.Contains(*3)" , " true" ),
18
+ (" MutableList: Remove" , " x.Remove(1/2); x" , " MutableList(3, 4, 5, *, 1/4, *2, *3, 1/2, 1/4, *3)" ),
19
+ (" MutableList: RemoveAll" , " x.RemoveAll([4, *2]); x" , " MutableList(3, 5, *, 1/4, *3, 1/2, 1/4, *3)" ),
20
+ (" MutableList: RemoveAll (multi)" , " x.RemoveAll([1/4, 1/4]); x" , " MutableList(3, 5, *, *3, 1/2, *3)" ),
21
+ (" MutableList: RemoveAt" , " x.RemoveAt(2); x" , " MutableList(3, *, *3, 1/2, *3)" ),
22
+ (" MutableList: Sort" , " x.Sort(); x" , " MutableList(1/2, 3, *, *3, *3)" ),
23
+ (" MutableList: SortWith" , " x.SortWith((a, b) -> if a < b then -1 elseif a > b then 1 else 0 end)" , " MutableList(*, *3, *3, 1/2, 3)" ),
24
+ (" MutableList: Clear" , " x.Clear(); x" , " MutableList()" ),
25
+
26
+ ))
27
+
28
+ }
29
+
30
+ " cgsuite.util.MutableSet" should " implement methods correctly" in {
31
+
32
+ executeTests(Table (
33
+ header,
34
+ (" MutableSet: Construction (empty)" , " MutableSet()" , " MutableSet()" ),
35
+ (" MutableSet: Construction (seeded)" , " x := MutableSet([3,4,5])" , " MutableSet(3, 4, 5)" ),
36
+ (" MutableSet: Add" , " x.Add(*); x" , " MutableSet(3, 4, 5, *)" ),
37
+ (" MutableSet: AddAll" , " x.AddAll([1/2, 1/4, *2, *3, 1/2, 1/4, *3]); x" , " MutableSet(1/4, 1/2, 3, 4, 5, *, *2, *3)" ),
38
+ (" MutableSet: Contains" , " x.Contains(*3)" , " true" ),
39
+ (" MutableSet: Remove" , " x.Remove(1/4); x" , " MutableSet(1/2, 3, 4, 5, *, *2, *3)" ),
40
+ (" MutableSet: RemoveAll" , " x.RemoveAll([3, 5, *2, 5, 19]); x" , " MutableSet(1/2, 4, *, *3)" ),
41
+ (" MutableSet: Clear" , " x.Clear(); x" , " MutableSet()" )
42
+ ))
43
+
44
+ }
45
+ " cgsuite.util.MutableMap" should " implement methods correctly" in {
46
+
47
+ executeTests(Table (
48
+ header,
49
+ (" MutableMap: Construction (empty)" , " MutableMap()" , " MutableMap()" ),
50
+ (" MutableMap: Construction (seeded)" , " x := MutableMap({3 => true, 5 => Left})" , " MutableMap(3 => true, 5 => Left)" ),
51
+ (" MutableMap: Lookup" , " x[5]" , " Left" ),
52
+ (" MutableMap: Lookup (not in map)" , " x[*]" , " !!Key not found: *" ),
53
+ (" MutableMap: ContainsKey" , " x.ContainsKey(5)" , " true" ),
54
+ (" MutableMap: Entries" , " x.Entries" , " {3 => true,5 => Left}" ),
55
+ (" MutableMap: Put 1" , " x.Put(3, false); x" , " MutableMap(3 => false, 5 => Left)" ),
56
+ (" MutableMap: Put 2" , " x.Put(*, 101); x" , " MutableMap(3 => false, 5 => Left, * => 101)" ),
57
+ (" MutableMap: PutAll" , " x.PutAll({Right => 1474, 3 => 1/7}); x" , " MutableMap(3 => 1/7, 5 => Left, * => 101, Right => 1474)" ),
58
+ (" MutableMap: Clear" , " x.Clear(); x" , " MutableMap()" )
59
+ ))
60
+
61
+ }
62
+
7
63
" cgsuite.util.Strip" should " implement methods correctly" in {
8
64
9
65
executeTests(Table (
0 commit comments