Sha256: d51a15779aee7cfb14eef8e3bc4c0445f6b44430fc259bb28a556e0e2ea5ad62

Contents?: true

Size: 1.51 KB

Versions: 190

Compression:

Stored size: 1.51 KB

Contents

package wordy

import "testing"

const targetTestVersion = 1

var tests = []struct {
	q  string
	a  int
	ok bool
}{
	{"What is 1 plus 1?", 2, true},
	{"What is 53 plus 2?", 55, true},
	{"What is -1 plus -10?", -11, true},
	{"What is 123 plus 45678?", 45801, true},
	{"What is 4 minus -12?", 16, true},
	{"What is -3 multiplied by 25?", -75, true},
	{"What is 33 divided by -3?", -11, true},
	{"What is 1 plus 1 plus 1?", 3, true},
	{"What is 1 plus 5 minus -2?", 8, true},
	{"What is 20 minus 4 minus 13?", 3, true},
	{"What is 17 minus 6 plus 3?", 14, true},
	{"What is 2 multiplied by -2 multiplied by 3?", -12, true},
	{"What is -3 plus 7 multiplied by -2?", -8, true},
	{"What is -12 divided by 2 divided by -3?", 2, true},
	{"What is 53 cubed?", 0, false},
	{"Who is the president of the United States?", 0, false},
}

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

func TestAnswer(t *testing.T) {
	for _, test := range tests {
		switch a, ok := Answer(test.q); {
		case !ok:
			if test.ok {
				t.Errorf("Answer(%q) returned ok = false, expecting true.", test.q)
			}
		case !test.ok:
			t.Errorf("Answer(%q) = %d, %t, expecting ok = false.", test.q, a, ok)
		case a != test.a:
			t.Errorf("Answer(%q) = %d, want %d.", test.q, a, test.a)
		}
	}
}

// Benchmark combined time to answer all questions.
func BenchmarkAnswer(b *testing.B) {
	for i := 0; i < b.N; i++ {
		for _, test := range tests {
			Answer(test.q)
		}
	}
}

Version data entries

190 entries across 190 versions & 1 rubygems

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