|
|
|
@ -41,4 +41,41 @@ func TestShardedMap(t *testing.T) {
|
|
|
|
|
if g, w := m.Len(), 0; g != w {
|
|
|
|
|
t.Errorf("got Len %v; want %v", g, w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mutation adding an entry.
|
|
|
|
|
if v := m.Mutate(1, func(was string, ok bool) (string, bool) {
|
|
|
|
|
if ok {
|
|
|
|
|
t.Fatal("was okay")
|
|
|
|
|
}
|
|
|
|
|
return "ONE", true
|
|
|
|
|
}); v != 1 {
|
|
|
|
|
t.Errorf("Mutate = %v; want 1", v)
|
|
|
|
|
}
|
|
|
|
|
if g, w := m.Get(1), "ONE"; g != w {
|
|
|
|
|
t.Errorf("got %q; want %q", g, w)
|
|
|
|
|
}
|
|
|
|
|
// Mutation changing an entry.
|
|
|
|
|
if v := m.Mutate(1, func(was string, ok bool) (string, bool) {
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatal("wasn't okay")
|
|
|
|
|
}
|
|
|
|
|
return was + "-" + was, true
|
|
|
|
|
}); v != 0 {
|
|
|
|
|
t.Errorf("Mutate = %v; want 0", v)
|
|
|
|
|
}
|
|
|
|
|
if g, w := m.Get(1), "ONE-ONE"; g != w {
|
|
|
|
|
t.Errorf("got %q; want %q", g, w)
|
|
|
|
|
}
|
|
|
|
|
// Mutation removing an entry.
|
|
|
|
|
if v := m.Mutate(1, func(was string, ok bool) (string, bool) {
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatal("wasn't okay")
|
|
|
|
|
}
|
|
|
|
|
return "", false
|
|
|
|
|
}); v != -1 {
|
|
|
|
|
t.Errorf("Mutate = %v; want -1", v)
|
|
|
|
|
}
|
|
|
|
|
if g, w := m.Get(1), ""; g != w {
|
|
|
|
|
t.Errorf("got %q; want %q", g, w)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|