2 MapTest
:= UnitTest
clone do(
5 self exampleMap
:= Map clone atPut("a", "alpha") atPut("b", "beta")
9 assertNotSame(Map, Map clone)
10 assertEquals(2, exampleMap size
)
11 clonedMap
:= exampleMap
clone
12 assertNotSame(clonedMap
, exampleMap
)
13 assertEquals(2, clonedMap size
)
14 assertEquals(exampleMap
at("a"), clonedMap
at("a"))
15 assertEquals(exampleMap
at("b"), clonedMap
at("b"))
20 assertEquals(0, exampleMap size
)
24 assertRaisesException(exampleMap
at())
25 assertRaisesException(exampleMap
at(nil
))
26 assertEquals("beta", exampleMap
at("b"))
27 assertEquals("alpha", exampleMap
at("a"))
28 assertNil(exampleMap
at("c"))
29 assertNil(exampleMap
at("alpha"))
33 assertRaisesException(exampleMap
atPut(nil
, "thirtythree"))
34 assertRaisesException(exampleMap
atPut(33))
35 assertRaisesException(exampleMap
atPut(33, "thirtythree"))
36 exampleMap
atPut("a", 88)
37 exampleMap
atPut("blah", "fasel")
38 exampleMap
atPut("nil", nil
)
39 assertEquals("fasel", exampleMap
at("blah"))
40 assertEquals(88, exampleMap
at("a"))
41 assertNil(exampleMap
at("nil"))
44 testAtIfAbsentPut
:= method(
45 assertRaisesException(exampleMap
atIfAbsentPut(nil
, "thirtythree"))
46 assertRaisesException(exampleMap
atIfAbsentPut(33))
47 assertRaisesException(exampleMap
atIfAbsentPut(33, "thirtythree"))
48 exampleMap
atIfAbsentPut("a", 88)
49 exampleMap
atIfAbsentPut("blah", "fasel")
50 assertEquals("fasel", exampleMap
at("blah"))
51 assertEquals("alpha", exampleMap
at("a"))
55 assertEquals(0, Map size
)
56 assertEquals(2, exampleMap size
)
57 exampleMap
atPut("blah", "fasel")
58 assertEquals(3, exampleMap size
)
62 assertEquals(List type, exampleMap keys
type)
63 assertEquals(0, Map keys size
)
64 keys
:= exampleMap keys
65 assertEquals(2, keys size
)
66 assertTrue(keys
contains("a"))
67 assertTrue(keys
contains("b"))
71 assertEquals(List type, exampleMap values
type)
72 assertEquals(0, Map values size
)
73 exampleMap
atPut("nil", nil
)
74 values
:= exampleMap values
75 assertEquals(3, values size
)
76 assertTrue(values
contains("alpha"))
77 assertTrue(values
contains("beta"))
78 assertTrue(values
contains(nil
))
81 testForeach
:= method(
83 exampleMap
foreach(key
, value
,
84 //writeln("key = ", key
)
85 //writeln("value = ", value
)
88 //writeln("\ns = [", s
, "]")
89 assertTrue(s
== "aalphabbeta" or s
== "bbetaaalpha" )
93 assertRaisesException(exampleMap
hasKey())
94 assertRaisesException(exampleMap
hasKey(nil
))
95 assertTrue(exampleMap
hasKey("a"))
96 assertTrue(exampleMap
hasKey("b"))
97 assertFalse(exampleMap
hasKey("c"))
100 testHasValue
:= method(
101 assertTrue(exampleMap
hasValue("alpha"))
102 assertTrue(exampleMap
hasValue("beta"))
103 assertFalse(exampleMap
hasValue("whatever"))
106 testRemoveAt
:= method(
107 assertRaisesException(exampleMap
removeAt())
108 assertRaisesException(exampleMap
removeAt(nil
))
109 exampleMap
removeAt("c")
110 assertEquals(2, exampleMap size
)
111 exampleMap
removeAt("a")
112 assertEquals(1, exampleMap size
)
113 //assertFalse(exampleMap
hasKey("a"))