1// Copyright 2014-2017 Ulrich Kunitz. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package hash
6
7import "testing"
8
9func TestCyclicPolySimple(t *testing.T) {
10	p := []byte("abcde")
11	r := NewCyclicPoly(4)
12	h2 := Hashes(r, p)
13	for i, h := range h2 {
14		w := Hashes(r, p[i:i+4])[0]
15		t.Logf("%d h=%#016x w=%#016x", i, h, w)
16		if h != w {
17			t.Errorf("rolling hash %d: %#016x; want %#016x",
18				i, h, w)
19		}
20	}
21}
22
23func BenchmarkCyclicPoly(b *testing.B) {
24	p := makeBenchmarkBytes(4096)
25	r := NewCyclicPoly(4)
26	b.ResetTimer()
27	for i := 0; i < b.N; i++ {
28		Hashes(r, p)
29	}
30}
31