Skip to content

Commit 09c2c93

Browse files
kytrinyxkotp
authored andcommitted
Sync queen-attack with problem-specifications
The sync brought in changes to the documentation, new titles for all the tests, and a new test. The regenerated test suite didn't require any changes to the sample solution.
1 parent 6645e37 commit 09c2c93

File tree

3 files changed

+54
-55
lines changed

3 files changed

+54
-55
lines changed
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
# Instructions
22

3-
Given the position of two queens on a chess board, indicate whether or not they
4-
are positioned so that they can attack each other.
3+
Given the position of two queens on a chess board, indicate whether or not they are positioned so that they can attack each other.
54

6-
In the game of chess, a queen can attack pieces which are on the same
7-
row, column, or diagonal.
5+
In the game of chess, a queen can attack pieces which are on the same row, column, or diagonal.
86

97
A chessboard can be represented by an 8 by 8 array.
108

11-
So if you're told the white queen is at (2, 3) and the black queen at
12-
(5, 6), then you'd know you've got a set-up like so:
9+
So if you are told the white queen is at `c5` (zero-indexed at column 2, row 3) and the black queen at `f2` (zero-indexed at column 5, row 6), then you know that the set-up is like so:
1310

1411
```text
15-
_ _ _ _ _ _ _ _
16-
_ _ _ _ _ _ _ _
17-
_ _ _ W _ _ _ _
18-
_ _ _ _ _ _ _ _
19-
_ _ _ _ _ _ _ _
20-
_ _ _ _ _ _ B _
21-
_ _ _ _ _ _ _ _
22-
_ _ _ _ _ _ _ _
12+
a b c d e f g h
13+
8 _ _ _ _ _ _ _ _ 8
14+
7 _ _ _ _ _ _ _ _ 7
15+
6 _ _ _ _ _ _ _ _ 6
16+
5 _ _ W _ _ _ _ _ 5
17+
4 _ _ _ _ _ _ _ _ 4
18+
3 _ _ _ _ _ _ _ _ 3
19+
2 _ _ _ _ _ B _ _ 2
20+
1 _ _ _ _ _ _ _ _ 1
21+
a b c d e f g h
2322
```
2423

25-
You'd also be able to answer whether the queens can attack each other.
26-
In this case, that answer would be yes, they can, because both pieces
27-
share a diagonal.
24+
You are also be able to answer whether the queens can attack each other.
25+
In this case, that answer would be yes, they can, because both pieces share a diagonal.

exercises/practice/queen-attack/.meta/tests.toml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,40 @@
1010
# is regenerated, comments can be added via a `comment` key.
1111

1212
[3ac4f735-d36c-44c4-a3e2-316f79704203]
13-
description = "queen with a valid position"
13+
description = "Test creation of Queens with valid and invalid positions -> queen with a valid position"
1414

1515
[4e812d5d-b974-4e38-9a6b-8e0492bfa7be]
16-
description = "queen must have positive row"
16+
description = "Test creation of Queens with valid and invalid positions -> queen must have positive row"
1717

1818
[f07b7536-b66b-4f08-beb9-4d70d891d5c8]
19-
description = "queen must have row on board"
19+
description = "Test creation of Queens with valid and invalid positions -> queen must have row on board"
2020

2121
[15a10794-36d9-4907-ae6b-e5a0d4c54ebe]
22-
description = "queen must have positive column"
22+
description = "Test creation of Queens with valid and invalid positions -> queen must have positive column"
2323

2424
[6907762d-0e8a-4c38-87fb-12f2f65f0ce4]
25-
description = "queen must have column on board"
25+
description = "Test creation of Queens with valid and invalid positions -> queen must have column on board"
2626

2727
[33ae4113-d237-42ee-bac1-e1e699c0c007]
28-
description = "can not attack"
28+
description = "Test the ability of one queen to attack another -> cannot attack"
2929

3030
[eaa65540-ea7c-4152-8c21-003c7a68c914]
31-
description = "can attack on same row"
31+
description = "Test the ability of one queen to attack another -> can attack on same row"
3232

3333
[bae6f609-2c0e-4154-af71-af82b7c31cea]
34-
description = "can attack on same column"
34+
description = "Test the ability of one queen to attack another -> can attack on same column"
3535

3636
[0e1b4139-b90d-4562-bd58-dfa04f1746c7]
37-
description = "can attack on first diagonal"
37+
description = "Test the ability of one queen to attack another -> can attack on first diagonal"
3838

3939
[ff9b7ed4-e4b6-401b-8d16-bc894d6d3dcd]
40-
description = "can attack on second diagonal"
40+
description = "Test the ability of one queen to attack another -> can attack on second diagonal"
4141

4242
[0a71e605-6e28-4cc2-aa47-d20a2e71037a]
43-
description = "can attack on third diagonal"
43+
description = "Test the ability of one queen to attack another -> can attack on third diagonal"
4444

4545
[0790b588-ae73-4f1f-a968-dd0b34f45f86]
46-
description = "can attack on fourth diagonal"
46+
description = "Test the ability of one queen to attack another -> can attack on fourth diagonal"
47+
48+
[543f8fd4-2597-4aad-8d77-cbdab63619f8]
49+
description = "Test the ability of one queen to attack another -> cannot attack if falling diagonals are only the same when reflected across the longest falling diagonal"

exercises/practice/queen-attack/queen_attack_test.rb

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,76 @@
22
require_relative 'queen_attack'
33

44
class QueenAttackTest < Minitest::Test
5-
def test_queen_with_a_valid_position
5+
def test_new_queen_with_a_valid_position
66
# skip
77
assert Queens.new(white: [2, 2])
88
end
99

10-
def test_queen_must_have_positive_row
10+
def test_new_queen_must_have_positive_row
1111
skip
1212
assert_raises(ArgumentError) do
1313
Queens.new(white: [-2, 2])
1414
end
1515
end
1616

17-
def test_queen_must_have_row_on_board
17+
def test_new_queen_must_have_row_on_board
1818
skip
1919
assert_raises(ArgumentError) do
2020
Queens.new(white: [8, 4])
2121
end
2222
end
2323

24-
def test_queen_must_have_positive_column
24+
def test_new_queen_must_have_positive_column
2525
skip
2626
assert_raises(ArgumentError) do
2727
Queens.new(white: [2, -2])
2828
end
2929
end
3030

31-
def test_queen_must_have_column_on_board
31+
def test_new_queen_must_have_column_on_board
3232
skip
3333
assert_raises(ArgumentError) do
3434
Queens.new(white: [4, 8])
3535
end
3636
end
3737

38-
def test_can_not_attack
38+
def test_queens_cannot_attack
3939
skip
40-
queens = Queens.new(white: [2, 4], black: [6, 6])
41-
refute queens.attack?
40+
refute Queens.new(white: [2, 4], black: [6, 6]).attack?
4241
end
4342

44-
def test_can_attack_on_same_row
43+
def test_queens_can_attack_on_same_row
4544
skip
46-
queens = Queens.new(white: [2, 4], black: [2, 6])
47-
assert queens.attack?
45+
assert Queens.new(white: [2, 4], black: [2, 6]).attack?
4846
end
4947

50-
def test_can_attack_on_same_column
48+
def test_queens_can_attack_on_same_column
5149
skip
52-
queens = Queens.new(white: [4, 5], black: [2, 5])
53-
assert queens.attack?
50+
assert Queens.new(white: [4, 5], black: [2, 5]).attack?
5451
end
5552

56-
def test_can_attack_on_first_diagonal
53+
def test_queens_can_attack_on_first_diagonal
5754
skip
58-
queens = Queens.new(white: [2, 2], black: [0, 4])
59-
assert queens.attack?
55+
assert Queens.new(white: [2, 2], black: [0, 4]).attack?
6056
end
6157

62-
def test_can_attack_on_second_diagonal
58+
def test_queens_can_attack_on_second_diagonal
6359
skip
64-
queens = Queens.new(white: [2, 2], black: [3, 1])
65-
assert queens.attack?
60+
assert Queens.new(white: [2, 2], black: [3, 1]).attack?
6661
end
6762

68-
def test_can_attack_on_third_diagonal
63+
def test_queens_can_attack_on_third_diagonal
6964
skip
70-
queens = Queens.new(white: [2, 2], black: [1, 1])
71-
assert queens.attack?
65+
assert Queens.new(white: [2, 2], black: [1, 1]).attack?
7266
end
7367

74-
def test_can_attack_on_fourth_diagonal
68+
def test_queens_can_attack_on_fourth_diagonal
7569
skip
76-
queens = Queens.new(white: [2, 2], black: [5, 5])
77-
assert queens.attack?
70+
assert Queens.new(white: [1, 7], black: [0, 6]).attack?
71+
end
72+
73+
def test_queens_cannot_attack_if_falling_diagonals_are_only_the_same_when_reflected_across_the_longest_falling_diagonal
74+
skip
75+
refute Queens.new(white: [4, 1], black: [2, 5]).attack?
7876
end
7977
end

0 commit comments

Comments
 (0)