40 lines
925 B
Go
40 lines
925 B
Go
package hamming
|
|
|
|
import "testing"
|
|
|
|
const testVersion = 2
|
|
|
|
// Retired testVersions
|
|
// (none) df178dc24b57f7d4ccf54d47430192749d56898f
|
|
// 1 4f6fe21682f7f2a7845683cb26ff557208153ffe
|
|
|
|
func TestHamming(t *testing.T) {
|
|
if TestVersion != testVersion {
|
|
t.Errorf("Found TestVersion = %v, want %v.", TestVersion, testVersion)
|
|
}
|
|
for _, tc := range testCases {
|
|
switch got, err := Distance(tc.s1, tc.s2); {
|
|
case err != nil:
|
|
if tc.want >= 0 {
|
|
t.Fatalf("Distance(%q, %q) returned error: %v",
|
|
tc.s1, tc.s2, err)
|
|
}
|
|
case tc.want < 0:
|
|
t.Fatalf("Distance(%q, %q) = %d. Expected error.",
|
|
tc.s1, tc.s2, got)
|
|
case got != tc.want:
|
|
t.Fatalf("Distance(%q, %q) = %d, want %d.",
|
|
tc.s1, tc.s2, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkHamming(b *testing.B) {
|
|
// bench combined time to run through all test cases
|
|
for i := 0; i < b.N; i++ {
|
|
for _, tc := range testCases {
|
|
Distance(tc.s1, tc.s2)
|
|
}
|
|
}
|
|
}
|