MCPcopy Create free account
hub / github.com/cloud-native-go/examples / TestShardingKeys

Function TestShardingKeys

ch04/sharding_test.go:73–107  ·  view source on GitHub ↗

TestShardingKeys tests the Keys method by adding 5 values to the map and checking that each one exists in the keys list exactly once.

(t *testing.T)

Source from the content-addressed store, hash-verified

71// TestShardingKeys tests the Keys method by adding 5 values to the map and checking
72// that each one exists in the keys list exactly once.
73func TestShardingKeys(t *testing.T) {
74 const BUCKETS = 17
75
76 sMap := NewShardedMap[string, int](BUCKETS)
77
78 truthMap := map[string]int{
79 "alpha": 1,
80 "beta": 2,
81 "gamma": 3,
82 "delta": 4,
83 "epsilon": 5,
84 }
85
86 for k, v := range truthMap {
87 sMap.Set(k, v)
88 }
89
90 keys := sMap.Keys()
91
92 if len(truthMap) != len(keys) {
93 t.Error("Map/keys mismatch")
94 }
95
96 for _, key := range sMap.Keys() {
97 if _, ok := truthMap[key]; !ok {
98 t.Error("Key", key, "not in truthMap")
99 }
100
101 delete(truthMap, key)
102 }
103
104 if len(truthMap) != 0 {
105 t.Error("Key mismatch")
106 }
107}
108
109// TestShardingDelete tests the Delete method by adding and then removing five values.
110func TestShardingDelete(t *testing.T) {

Callers

nothing calls this directly

Calls 2

SetMethod · 0.80
KeysMethod · 0.80

Tested by

no test coverage detected