Sha256: 45f0c8861d7717f09424487f7eed96eae40dbb82e33478f68747e3f7f9c5e046

Contents?: true

Size: 986 Bytes

Versions: 60

Compression:

Stored size: 986 Bytes

Contents

package hamming

import "testing"

const targetTestVersion = 5

func TestTestVersion(t *testing.T) {
	if testVersion != targetTestVersion {
		t.Fatalf("Found testVersion = %v, want %v.", testVersion, targetTestVersion)
	}
}

func TestHamming(t *testing.T) {
	for _, tc := range testCases {
		got, err := Distance(tc.s1, tc.s2)
		if tc.want < 0 {
			// check if err is of error type
			var _ error = err

			// we expect error
			if err == nil {
				t.Fatalf("Distance(%q, %q). error is nil.",
					tc.s1, tc.s2)
			}
		} else {
			if got != tc.want {
				t.Fatalf("Distance(%q, %q) = %d, want %d.",
					tc.s1, tc.s2, got, tc.want)
			}

			// we do not expect error
			if err != nil {
				t.Fatalf("Distance(%q, %q) returned error: %v when expecting none.",
					tc.s1, tc.s2, err)
			}
		}
	}
}

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)
		}
	}
}

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
trackler-2.0.8.36 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.35 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.34 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.33 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.32 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.31 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.30 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.29 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.28 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.27 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.26 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.24 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.23 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.22 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.21 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.20 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.19 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.18 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.17 tracks/go/exercises/hamming/hamming_test.go
trackler-2.0.8.16 tracks/go/exercises/hamming/hamming_test.go