Skip to content

Commit d88f700

Browse files
committed
1 parent 5680047 commit d88f700

4 files changed

Lines changed: 38 additions & 38 deletions

File tree

exercises/queen-attack/.meta/src/reference/java/BoardCoordinate.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
public final class BoardCoordinate {
1+
final class BoardCoordinate {
22

3-
private final int rank;
3+
private final int row;
44

5-
private final int file;
5+
private final int column;
66

7-
public BoardCoordinate(final int rank, final int file) throws IllegalArgumentException {
8-
this.rank = rank;
9-
this.file = file;
7+
BoardCoordinate(final int row, final int column) throws IllegalArgumentException {
8+
this.row = row;
9+
this.column = column;
1010

1111
validateInputs();
1212
}
1313

14-
public int getRank() {
15-
return rank;
14+
int getRow() {
15+
return row;
1616
}
1717

18-
public int getFile() {
19-
return file;
18+
int getColumn() {
19+
return column;
2020
}
2121

2222
private void validateInputs() throws IllegalArgumentException {
23-
validateCoordinateComponent(rank, "rank");
24-
validateCoordinateComponent(file, "file");
23+
validateCoordinateComponent(row, "row");
24+
validateCoordinateComponent(column, "column");
2525
}
2626

2727
private void validateCoordinateComponent(final int value, final String componentName)
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
public final class QueenAttackCalculator {
1+
final class QueenAttackCalculator {
22

33
private final BoardCoordinate whiteQueenCoordinate;
44

55
private final BoardCoordinate blackQueenCoordinate;
66

7-
public QueenAttackCalculator(final BoardCoordinate whiteQueenCoordinate, final BoardCoordinate blackQueenCoordinate)
7+
QueenAttackCalculator(final BoardCoordinate whiteQueenCoordinate, final BoardCoordinate blackQueenCoordinate)
88
throws IllegalArgumentException {
99

1010
this.whiteQueenCoordinate = whiteQueenCoordinate;
@@ -13,8 +13,8 @@ public QueenAttackCalculator(final BoardCoordinate whiteQueenCoordinate, final B
1313
validateInputs();
1414
}
1515

16-
public boolean canQueensAttackOneAnother() {
17-
return queensShareFile() || queensShareRank() || queensShareDiagonal();
16+
boolean canQueensAttackOneAnother() {
17+
return queensShareColumn() || queensShareRow() || queensShareDiagonal();
1818
}
1919

2020
private void validateInputs() throws IllegalArgumentException {
@@ -27,28 +27,28 @@ private void validateInputs() throws IllegalArgumentException {
2727
}
2828
}
2929

30-
private boolean queensShareRank() {
31-
return differenceBetweenRanks() == 0;
30+
private boolean queensShareRow() {
31+
return differenceBetweenRows() == 0;
3232
}
3333

34-
private boolean queensShareFile() {
35-
return differenceBetweenFiles() == 0;
34+
private boolean queensShareColumn() {
35+
return differenceBetweenColumns() == 0;
3636
}
3737

3838
private boolean queensShareBoardCoordinate() {
39-
return queensShareRank() && queensShareFile();
39+
return queensShareRow() && queensShareColumn();
4040
}
4141

4242
private boolean queensShareDiagonal() {
43-
return differenceBetweenRanks() == differenceBetweenFiles();
43+
return differenceBetweenRows() == differenceBetweenColumns();
4444
}
4545

46-
private int differenceBetweenRanks() {
47-
return Math.abs(whiteQueenCoordinate.getRank() - blackQueenCoordinate.getRank());
46+
private int differenceBetweenRows() {
47+
return Math.abs(whiteQueenCoordinate.getRow() - blackQueenCoordinate.getRow());
4848
}
4949

50-
private int differenceBetweenFiles() {
51-
return Math.abs(whiteQueenCoordinate.getFile() - blackQueenCoordinate.getFile());
50+
private int differenceBetweenColumns() {
51+
return Math.abs(whiteQueenCoordinate.getColumn() - blackQueenCoordinate.getColumn());
5252
}
5353

5454
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
2.0.0

exercises/queen-attack/src/test/java/QueenAttackCalculatorTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class QueenAttackCalculatorTest {
1212
public ExpectedException expectedException = ExpectedException.none();
1313

1414
@Test
15-
public void testQueensThatDoNotShareRankFileOrDiagonalCannotAttack() {
15+
public void testQueensThatDoNotShareRowColumnOrDiagonalCannotAttack() {
1616
final QueenAttackCalculator calculator
1717
= new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(6, 6));
1818

@@ -21,7 +21,7 @@ public void testQueensThatDoNotShareRankFileOrDiagonalCannotAttack() {
2121

2222
@Ignore("Remove to run test")
2323
@Test
24-
public void testQueensCanAttackOnTheSameRank() {
24+
public void testQueensCanAttackOnTheSameRow() {
2525
final QueenAttackCalculator calculator
2626
= new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(2, 6));
2727

@@ -30,7 +30,7 @@ public void testQueensCanAttackOnTheSameRank() {
3030

3131
@Ignore("Remove to run test")
3232
@Test
33-
public void testQueensCanAttackOnTheSameFile() {
33+
public void testQueensCanAttackOnTheSameColumn() {
3434
final QueenAttackCalculator calculator
3535
= new QueenAttackCalculator(new BoardCoordinate(4, 5), new BoardCoordinate(2, 5));
3636

@@ -75,36 +75,36 @@ public void testQueensCanAttackOnFourthDiagonal() {
7575

7676
@Ignore("Remove to run test")
7777
@Test
78-
public void testCoordinateWithNegativeRankNotAllowed() {
78+
public void testCoordinateWithNegativeRowNotAllowed() {
7979
expectedException.expect(IllegalArgumentException.class);
80-
expectedException.expectMessage("Coordinate must have positive rank.");
80+
expectedException.expectMessage("Coordinate must have positive row.");
8181

8282
new BoardCoordinate(-2, 2);
8383
}
8484

8585
@Ignore("Remove to run test")
8686
@Test
87-
public void testCoordinateWithRankGreaterThan7NotAllowed() {
87+
public void testCoordinateWithRowGreaterThan7NotAllowed() {
8888
expectedException.expect(IllegalArgumentException.class);
89-
expectedException.expectMessage("Coordinate must have rank <= 7.");
89+
expectedException.expectMessage("Coordinate must have row <= 7.");
9090

9191
new BoardCoordinate(8, 4);
9292
}
9393

9494
@Ignore("Remove to run test")
9595
@Test
96-
public void testCoordinateWithNegativeFileNotAllowed() {
96+
public void testCoordinateWithNegativeColumnNotAllowed() {
9797
expectedException.expect(IllegalArgumentException.class);
98-
expectedException.expectMessage("Coordinate must have positive file.");
98+
expectedException.expectMessage("Coordinate must have positive column.");
9999

100100
new BoardCoordinate(2, -2);
101101
}
102102

103103
@Ignore("Remove to run test")
104104
@Test
105-
public void testCoordinateWithFileGreaterThan7NotAllowed() {
105+
public void testCoordinateWithColumnGreaterThan7NotAllowed() {
106106
expectedException.expect(IllegalArgumentException.class);
107-
expectedException.expectMessage("Coordinate must have file <= 7.");
107+
expectedException.expectMessage("Coordinate must have column <= 7.");
108108

109109
new BoardCoordinate(4, 8);
110110
}

0 commit comments

Comments
 (0)