Skip to content
This repository was archived by the owner on Jul 15, 2018. It is now read-only.

Commit b658294

Browse files
committed
use assert.Contains in cmap_test
1 parent 88481fc commit b658294

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

common/cmap_test.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,26 @@ func TestIterateKeysWithValues(t *testing.T) {
1616
}
1717

1818
// Testing size
19-
assert.Equal(t, cmap.Size(), 10, "overall size should be 10")
20-
assert.Equal(t, len(cmap.Keys()), 10, "should be 10 keys")
21-
assert.Equal(t, len(cmap.Values()), 10, "should be 10 values")
19+
assert.Equal(t, 10, cmap.Size())
20+
assert.Equal(t, 10, len(cmap.Keys()))
21+
assert.Equal(t, 10, len(cmap.Values()))
2222

2323
// Iterating Keys, checking for matching Value
2424
for _, key := range cmap.Keys() {
2525
val := strings.Replace(key, "key", "value", -1)
26-
assert.Equal(t, cmap.Get(key), val)
26+
assert.Equal(t, val, cmap.Get(key))
2727
}
2828

2929
// Test if all keys are within []Keys()
3030
keys := cmap.Keys()
3131
for i := 1; i <= 10; i++ {
32-
assert.True(t, contains(keys, fmt.Sprintf("key%d", i)), "cmap.Keys() should contain key")
32+
assert.Contains(t, keys, fmt.Sprintf("key%d", i), "cmap.Keys() should contain key")
3333
}
3434

3535
// Delete 1 Key
3636
cmap.Delete("key1")
3737

3838
assert.NotEqual(t, len(keys), len(cmap.Keys()), "[]keys and []Keys() should not be equal, they are copies, one item was removed")
39-
4039
}
4140

4241
func TestContains(t *testing.T) {
@@ -45,19 +44,10 @@ func TestContains(t *testing.T) {
4544
cmap.Set("key1", "value1")
4645

4746
// Test for known values
48-
assert.True(t, cmap.Has("key1"), "should contain key1")
49-
assert.Equal(t, cmap.Get("key1"), "value1", "key1.value() should be value1")
47+
assert.True(t, cmap.Has("key1"))
48+
assert.Equal(t, "value1", cmap.Get("key1"))
5049

5150
// Test for unknown values
52-
assert.False(t, cmap.Has("key2"), "should not contain key2")
53-
assert.Nil(t, cmap.Get("key2"), "does not contain key2")
54-
}
55-
56-
func contains(array []string, value string) (bool) {
57-
for _, val := range array {
58-
if val == value {
59-
return true
60-
}
61-
}
62-
return false
51+
assert.False(t, cmap.Has("key2"))
52+
assert.Nil(t, cmap.Get("key2"))
6353
}

0 commit comments

Comments
 (0)