Sha256: 96c15a2a35e8e1c15d212a8bbe43ea6f4f1c7929e9309271bf77ac0f6b300e4e

Contents?: true

Size: 1.67 KB

Versions: 156

Compression:

Stored size: 1.67 KB

Contents

package queenattack

import "testing"

// Arguments to CanQueenAttack are in algebraic notation.
// See http://en.wikipedia.org/wiki/Algebraic_notation_(chess)

const targetTestVersion = 2

var tests = []struct {
	w, b   string
	attack bool
	ok     bool
}{
	{"b4", "b4", false, false}, // same square
	{"a8", "b9", false, false}, // off board
	{"a0", "b1", false, false},
	{"g3", "i5", false, false},
	{"here", "there", false, false}, // invalid
	{"", "", false, false},

	{"b3", "d7", false, true}, // no attack
	{"a1", "f8", false, true},
	{"b4", "b7", true, true}, // same file
	{"e4", "b4", true, true}, // same rank
	{"a1", "f6", true, true}, // common diagonals
	{"a6", "b7", true, true},
	{"d1", "f3", true, true},
	{"f1", "a6", true, true},
	{"a1", "h8", true, true},
	{"a8", "h1", true, true},
}

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

func TestCanQueenAttack(t *testing.T) {
	for _, test := range tests {
		switch attack, err := CanQueenAttack(test.w, test.b); {
		case err != nil:
			var _ error = err
			if test.ok {
				t.Fatalf("CanQueenAttack(%s, %s) returned error %q.  "+
					"Error not expected.",
					test.w, test.b, err)
			}
		case !test.ok:
			t.Fatalf("CanQueenAttack(%s, %s) = %t, %v.  Expected error.",
				test.w, test.b, attack, err)
		case attack != test.attack:
			t.Fatalf("CanQueenAttack(%s, %s) = %t, want %t.",
				test.w, test.b, attack, test.attack)
		}
	}
}

// Benchmark combined time for all test cases
func BenchmarkCanQueenAttack(b *testing.B) {
	for i := 0; i < b.N; i++ {
		for _, test := range tests {
			CanQueenAttack(test.w, test.b)
		}
	}
}

Version data entries

156 entries across 156 versions & 1 rubygems

Version Path
trackler-2.2.1.36 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.35 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.34 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.33 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.32 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.31 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.30 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.29 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.28 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.27 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.26 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.25 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.24 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.23 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.22 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.21 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.20 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.19 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.18 tracks/go/exercises/queen-attack/queen_attack_test.go
trackler-2.2.1.17 tracks/go/exercises/queen-attack/queen_attack_test.go