13
type _Adler32Test struct {
12
var golden = []struct {
18
var golden = []_Adler32Test{
25
{0x81e0256, "abcdef"},
26
{0xadb02bd, "abcdefg"},
27
{0xe000325, "abcdefgh"},
21
{0x05c801f0, "abcde"},
22
{0x081e0256, "abcdef"},
23
{0x0adb02bd, "abcdefg"},
24
{0x0e000325, "abcdefgh"},
28
25
{0x118e038e, "abcdefghi"},
29
26
{0x158603f8, "abcdefghij"},
30
27
{0x3f090f02, "Discard medicine more than two years old."},
48
45
{0x91dd304f, "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule"},
49
46
{0x2e5d1316, "How can you write a big system without C++? -Paul Glick"},
50
47
{0xd0201df6, "'Invariant assertions' is the most elegant programming technique! -Tom Szymanski"},
48
{0x211297c8, strings.Repeat("\xff", 5548) + "8"},
49
{0xbaa198c8, strings.Repeat("\xff", 5549) + "9"},
50
{0x553499be, strings.Repeat("\xff", 5550) + "0"},
51
{0xf0c19abe, strings.Repeat("\xff", 5551) + "1"},
52
{0x8d5c9bbe, strings.Repeat("\xff", 5552) + "2"},
53
{0x2af69cbe, strings.Repeat("\xff", 5553) + "3"},
54
{0xc9809dbe, strings.Repeat("\xff", 5554) + "4"},
55
{0x69189ebe, strings.Repeat("\xff", 5555) + "5"},
56
{0x86af0001, strings.Repeat("\x00", 1e5)},
57
{0x79660b4d, strings.Repeat("a", 1e5)},
58
{0x110588ee, strings.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1e4)},
61
// checksum is a slow but simple implementation of the Adler-32 checksum.
62
// It is a straight port of the sample code in RFC 1950 section 9.
63
func checksum(p []byte) uint32 {
64
s1, s2 := uint32(1), uint32(0)
66
s1 = (s1 + uint32(x)) % mod
53
72
func TestGolden(t *testing.T) {
54
for i := 0; i < len(golden); i++ {
57
io.WriteString(c, g.in)
60
t.Errorf("adler32(%s) = 0x%x want 0x%x", g.in, s, g.out)
66
func BenchmarkGolden(b *testing.B) {
70
73
for _, g := range golden {
71
buf.Write([]byte(g.in))
76
in = in[:100] + "..." + in[len(in)-100:]
79
if got := checksum(p); got != g.out {
80
t.Errorf("simple implementation: checksum(%q) = 0x%x want 0x%x", in, got, g.out)
83
if got := Checksum(p); got != g.out {
84
t.Errorf("optimized implementation: Checksum(%q) = 0x%x want 0x%x", in, got, g.out)
90
func BenchmarkAdler32KB(b *testing.B) {
92
data := make([]byte, 1024)
97
in := make([]byte, 0, h.Size())
74
100
for i := 0; i < b.N; i++ {