Example #1
0
func TestMoveWall(t *testing.T) {
	moves := []game.MoveWall{
		{
			Wall: game.NewWall(3, 0, game.HORIZONTAL),
		},
		{
			Wall: game.NewWall(3, 2, game.HORIZONTAL),
		},
		{
			Wall: game.NewWall(3, 4, game.HORIZONTAL),
		},
		{
			Wall: game.NewWall(2, 4, game.VERTICAL),
		},
		{
			Wall: game.NewWall(0, 4, game.VERTICAL),
		},
	}

	g := game.NewGame()
	for i, move := range moves {
		expected := i != len(moves)-1
		if expected != g.Move(move) {
			t.Errorf("(%v) Expected move %v to be %v", i, move, expected)
		}
	}
}
Example #2
0
func TestPlaceAndRemoveWall(t *testing.T) {
	testCases := []struct {
		wallsToPlace      []game.Wall
		adjacenciesToLose [][]game.Position
	}{
		{
			wallsToPlace: []game.Wall{
				game.NewWall(1, 1, game.HORIZONTAL),
			},
			adjacenciesToLose: [][]game.Position{
				newAdjacency(1, 1, 2, 1),
				newAdjacency(1, 2, 2, 2),
			},
		},
		{
			wallsToPlace: []game.Wall{
				game.NewWall(1, 1, game.VERTICAL),
			},
			adjacenciesToLose: [][]game.Position{
				newAdjacency(1, 1, 1, 2),
				newAdjacency(2, 1, 2, 2),
			},
		},
	}

	for _, tc := range testCases {
		board := game.NewBoard(3)
		for _, adj := range tc.adjacenciesToLose {
			if !board.Adjacent(adj[0], adj[1]) {
				t.Errorf("Expected to be adjacent: %v", adj)
			}
		}
		for _, wallToPlace := range tc.wallsToPlace {
			board.PlaceWall(wallToPlace)
		}
		for _, adj := range tc.adjacenciesToLose {
			if board.Adjacent(adj[0], adj[1]) {
				t.Errorf("Expected not to be adjacent: %v", adj)
			}
		}
		for _, wallToPlace := range tc.wallsToPlace {
			board.RemoveWall(wallToPlace)
		}
		for _, adj := range tc.adjacenciesToLose {
			if !board.Adjacent(adj[0], adj[1]) {
				t.Errorf("Expected to be adjacent: %v", adj)
			}
		}
	}
}