add some unittests and bug fix

This commit is contained in:
hdt3213
2021-05-02 18:48:44 +08:00
parent 37779717e4
commit 9f3ac88b36
19 changed files with 256 additions and 146 deletions

View File

@@ -0,0 +1,17 @@
package consistenthash
import "testing"
func TestHash(t *testing.T) {
m := New(3, nil)
m.AddNode("a", "b", "c", "d")
if m.PickNode("zxc") != "a" {
t.Error("wrong answer")
}
if m.PickNode("123{abc}") != "b" {
t.Error("wrong answer")
}
if m.PickNode("abc") != "b" {
t.Error("wrong answer")
}
}