Sha256: 0b8ce0fcffbb1721f92040692a3e1d18642597d54cb23a220a52c6db282c6590

Contents?: true

Size: 986 Bytes

Versions: 118

Compression:

Stored size: 986 Bytes

Contents

package hamming

import "testing"

const targetTestVersion = 6

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

118 entries across 118 versions & 1 rubygems

Version Path
trackler-2.2.1.56 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.55 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.54 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.53 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.52 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.51 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.50 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.49 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.48 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.47 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.46 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.45 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.44 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.43 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.42 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.41 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.40 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.39 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.38 tracks/go/exercises/hamming/hamming_test.go
trackler-2.2.1.37 tracks/go/exercises/hamming/hamming_test.go