Beispiel #1
0
func Example() {
	sum := fnv.New()
	sum = fnv.Add(sum, "Row, row, row your boat,")
	sum = fnv.Add(sum, "Gently down the stream.")
	fmt.Printf("sum: %d", sum)
	// Output:
	// sum: 13308045931649024798
}
Beispiel #2
0
func TestBytes(t *testing.T) {
	for _, src := range [][]byte{
		[]byte(""),
		[]byte("hello world"),
	} {
		h := theirlib.New64a()
		h.Write(src)
		theirs := h.Sum64()

		ours := ourlib.New()
		ours = ourlib.AddBytes(ours, src)

		if have, want := ours, theirs; have != want {
			t.Errorf("have %d, want %d. case %q", have, want, src)
		}
	}
}
Beispiel #3
0
func TestString(t *testing.T) {
	for _, src := range []string{
		"",
		"hello world",
	} {
		h := theirlib.New64a()
		h.Write([]byte(src))
		theirs := h.Sum64()

		ours := ourlib.New()
		ours = ourlib.Add(ours, src)

		if have, want := ours, theirs; have != want {
			t.Errorf("have %d, want %d. case %q", have, want, src)
		}
	}
}
Beispiel #4
0
func TestStrings(t *testing.T) {
	for _, src := range [][]string{
		{},
		{""},
		{"hello", "world"},
	} {
		h := theirlib.New64a()
		for _, s := range src {
			h.Write([]byte(s))
		}
		theirs := h.Sum64()

		ours := ourlib.New()
		for _, s := range src {
			ours = ourlib.Add(ours, s)
		}

		if have, want := ours, theirs; have != want {
			t.Errorf("have %d, want %d. case %q", have, want, src)
		}
	}
}