LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package md5 | 5 package md5 |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "io" | 9 "io" |
10 "testing" | 10 "testing" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 s := fmt.Sprintf("%x", c.Sum(nil)) | 75 s := fmt.Sprintf("%x", c.Sum(nil)) |
76 if s != g.out { | 76 if s != g.out { |
77 t.Fatalf("md5[%d](%s) = %s want %s", j, g.in, s,
g.out) | 77 t.Fatalf("md5[%d](%s) = %s want %s", j, g.in, s,
g.out) |
78 } | 78 } |
79 c.Reset() | 79 c.Reset() |
80 } | 80 } |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
| 84 func TestLarge(t *testing.T) { |
| 85 const N = 10000 |
| 86 ok := "2bb571599a4180e1d542f76904adc3df" // md5sum of "0123456789" * 100
0 |
| 87 block := make([]byte, 10004) |
| 88 c := New() |
| 89 for offset := 0; offset < 4; offset++ { |
| 90 for i := 0; i < N; i++ { |
| 91 block[offset+i] = '0' + byte(i%10) |
| 92 } |
| 93 for blockSize := 10; blockSize <= N; blockSize *= 10 { |
| 94 blocks := N / blockSize |
| 95 b := block[offset : offset+blockSize] |
| 96 c.Reset() |
| 97 for i := 0; i < blocks; i++ { |
| 98 c.Write(b) |
| 99 } |
| 100 s := fmt.Sprintf("%x", c.Sum(nil)) |
| 101 if s != ok { |
| 102 t.Fatalf("md5 TestLarge offset=%d, blockSize=%d
= %s want %s", offset, blockSize, s, ok) |
| 103 } |
| 104 } |
| 105 } |
| 106 } |
| 107 |
84 func ExampleNew() { | 108 func ExampleNew() { |
85 h := New() | 109 h := New() |
86 io.WriteString(h, "The fog is getting thicker!") | 110 io.WriteString(h, "The fog is getting thicker!") |
87 io.WriteString(h, "And Leon's getting laaarger!") | 111 io.WriteString(h, "And Leon's getting laaarger!") |
88 fmt.Printf("%x", h.Sum(nil)) | 112 fmt.Printf("%x", h.Sum(nil)) |
89 // Output: e2c569be17396eca2a2e3c11578123ed | 113 // Output: e2c569be17396eca2a2e3c11578123ed |
90 } | 114 } |
91 | 115 |
92 var bench = New() | 116 var bench = New() |
93 var buf = make([]byte, 8192+1) | 117 var buf = make([]byte, 8192+1) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 benchmarkSize(b, 8, true) | 149 benchmarkSize(b, 8, true) |
126 } | 150 } |
127 | 151 |
128 func BenchmarkHash1KUnaligned(b *testing.B) { | 152 func BenchmarkHash1KUnaligned(b *testing.B) { |
129 benchmarkSize(b, 1024, true) | 153 benchmarkSize(b, 1024, true) |
130 } | 154 } |
131 | 155 |
132 func BenchmarkHash8KUnaligned(b *testing.B) { | 156 func BenchmarkHash8KUnaligned(b *testing.B) { |
133 benchmarkSize(b, 8192, true) | 157 benchmarkSize(b, 8192, true) |
134 } | 158 } |
LEFT | RIGHT |