From 509c5063d66e8bbef4ec1def1c99c318be51aceb Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 25 Aug 2016 03:13:39 +0200 Subject: Initial import --- go/hamming/hamming_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 go/hamming/hamming_test.go (limited to 'go/hamming/hamming_test.go') diff --git a/go/hamming/hamming_test.go b/go/hamming/hamming_test.go new file mode 100644 index 0000000..bfee705 --- /dev/null +++ b/go/hamming/hamming_test.go @@ -0,0 +1,36 @@ +package hamming + +import "testing" + +const targetTestVersion = 4 + +func TestHamming(t *testing.T) { + if testVersion != targetTestVersion { + t.Errorf("Found testVersion = %v, want %v.", testVersion, targetTestVersion) + } + for _, tc := range testCases { + switch got, err := Distance(tc.s1, tc.s2); { + case err != nil: + var _ error = err + 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) + } + } +} -- cgit v1.2.3