Просмотр исходного кода

Merge pull request #968 from exercism/queen-attack-update

queen-attack: update to v2.0.0
Stuart Kent 9 лет назад
Родитель
Сommit
50fb59e41a

+ 12
- 12
exercises/queen-attack/.meta/src/reference/java/BoardCoordinate.java Просмотреть файл

@@ -1,27 +1,27 @@
1
-public final class BoardCoordinate {
1
+final class BoardCoordinate {
2 2
 
3
-    private final int rank;
3
+    private final int row;
4 4
 
5
-    private final int file;
5
+    private final int column;
6 6
 
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;
10 10
 
11 11
         validateInputs();
12 12
     }
13 13
 
14
-    public int getRank() {
15
-        return rank;
14
+    int getRow() {
15
+        return row;
16 16
     }
17 17
 
18
-    public int getFile() {
19
-        return file;
18
+    int getColumn() {
19
+        return column;
20 20
     }
21 21
 
22 22
     private void validateInputs() throws IllegalArgumentException {
23
-        validateCoordinateComponent(rank, "rank");
24
-        validateCoordinateComponent(file, "file");
23
+        validateCoordinateComponent(row, "row");
24
+        validateCoordinateComponent(column, "column");
25 25
     }
26 26
 
27 27
     private void validateCoordinateComponent(final int value, final String componentName)

+ 14
- 14
exercises/queen-attack/.meta/src/reference/java/QueenAttackCalculator.java Просмотреть файл

@@ -1,10 +1,10 @@
1
-public final class QueenAttackCalculator {
1
+final class QueenAttackCalculator {
2 2
 
3 3
     private final BoardCoordinate whiteQueenCoordinate;
4 4
 
5 5
     private final BoardCoordinate blackQueenCoordinate;
6 6
 
7
-    public QueenAttackCalculator(final BoardCoordinate whiteQueenCoordinate, final BoardCoordinate blackQueenCoordinate)
7
+    QueenAttackCalculator(final BoardCoordinate whiteQueenCoordinate, final BoardCoordinate blackQueenCoordinate)
8 8
             throws IllegalArgumentException {
9 9
 
10 10
         this.whiteQueenCoordinate = whiteQueenCoordinate;
@@ -13,8 +13,8 @@ public final class QueenAttackCalculator {
13 13
         validateInputs();
14 14
     }
15 15
 
16
-    public boolean canQueensAttackOneAnother() {
17
-        return queensShareFile() || queensShareRank() || queensShareDiagonal();
16
+    boolean canQueensAttackOneAnother() {
17
+        return queensShareColumn() || queensShareRow() || queensShareDiagonal();
18 18
     }
19 19
 
20 20
     private void validateInputs() throws IllegalArgumentException {
@@ -27,28 +27,28 @@ public final class QueenAttackCalculator {
27 27
         }
28 28
     }
29 29
 
30
-    private boolean queensShareRank() {
31
-        return differenceBetweenRanks() == 0;
30
+    private boolean queensShareRow() {
31
+        return differenceBetweenRows() == 0;
32 32
     }
33 33
 
34
-    private boolean queensShareFile() {
35
-        return differenceBetweenFiles() == 0;
34
+    private boolean queensShareColumn() {
35
+        return differenceBetweenColumns() == 0;
36 36
     }
37 37
 
38 38
     private boolean queensShareBoardCoordinate() {
39
-        return queensShareRank() && queensShareFile();
39
+        return queensShareRow() && queensShareColumn();
40 40
     }
41 41
 
42 42
     private boolean queensShareDiagonal() {
43
-        return differenceBetweenRanks() == differenceBetweenFiles();
43
+        return differenceBetweenRows() == differenceBetweenColumns();
44 44
     }
45 45
 
46
-    private int differenceBetweenRanks() {
47
-        return Math.abs(whiteQueenCoordinate.getRank() - blackQueenCoordinate.getRank());
46
+    private int differenceBetweenRows() {
47
+        return Math.abs(whiteQueenCoordinate.getRow() - blackQueenCoordinate.getRow());
48 48
     }
49 49
 
50
-    private int differenceBetweenFiles() {
51
-        return Math.abs(whiteQueenCoordinate.getFile() - blackQueenCoordinate.getFile());
50
+    private int differenceBetweenColumns() {
51
+        return Math.abs(whiteQueenCoordinate.getColumn() - blackQueenCoordinate.getColumn());
52 52
     }
53 53
 
54 54
 }

+ 1
- 1
exercises/queen-attack/.meta/version Просмотреть файл

@@ -1 +1 @@
1
-1.0.0
1
+2.0.0

+ 11
- 11
exercises/queen-attack/src/test/java/QueenAttackCalculatorTest.java Просмотреть файл

@@ -12,7 +12,7 @@ public class QueenAttackCalculatorTest {
12 12
     public ExpectedException expectedException = ExpectedException.none();
13 13
 
14 14
     @Test
15
-    public void testQueensThatDoNotShareRankFileOrDiagonalCannotAttack() {
15
+    public void testQueensThatDoNotShareRowColumnOrDiagonalCannotAttack() {
16 16
         final QueenAttackCalculator calculator
17 17
                 = new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(6, 6));
18 18
 
@@ -21,7 +21,7 @@ public class QueenAttackCalculatorTest {
21 21
 
22 22
     @Ignore("Remove to run test")
23 23
     @Test
24
-    public void testQueensCanAttackOnTheSameRank() {
24
+    public void testQueensCanAttackOnTheSameRow() {
25 25
         final QueenAttackCalculator calculator
26 26
                 = new QueenAttackCalculator(new BoardCoordinate(2, 4), new BoardCoordinate(2, 6));
27 27
 
@@ -30,7 +30,7 @@ public class QueenAttackCalculatorTest {
30 30
 
31 31
     @Ignore("Remove to run test")
32 32
     @Test
33
-    public void testQueensCanAttackOnTheSameFile() {
33
+    public void testQueensCanAttackOnTheSameColumn() {
34 34
         final QueenAttackCalculator calculator
35 35
                 = new QueenAttackCalculator(new BoardCoordinate(4, 5), new BoardCoordinate(2, 5));
36 36
 
@@ -75,36 +75,36 @@ public class QueenAttackCalculatorTest {
75 75
 
76 76
     @Ignore("Remove to run test")
77 77
     @Test
78
-    public void testCoordinateWithNegativeRankNotAllowed() {
78
+    public void testCoordinateWithNegativeRowNotAllowed() {
79 79
         expectedException.expect(IllegalArgumentException.class);
80
-        expectedException.expectMessage("Coordinate must have positive rank.");
80
+        expectedException.expectMessage("Coordinate must have positive row.");
81 81
 
82 82
         new BoardCoordinate(-2, 2);
83 83
     }
84 84
 
85 85
     @Ignore("Remove to run test")
86 86
     @Test
87
-    public void testCoordinateWithRankGreaterThan7NotAllowed() {
87
+    public void testCoordinateWithRowGreaterThan7NotAllowed() {
88 88
         expectedException.expect(IllegalArgumentException.class);
89
-        expectedException.expectMessage("Coordinate must have rank <= 7.");
89
+        expectedException.expectMessage("Coordinate must have row <= 7.");
90 90
 
91 91
         new BoardCoordinate(8, 4);
92 92
     }
93 93
 
94 94
     @Ignore("Remove to run test")
95 95
     @Test
96
-    public void testCoordinateWithNegativeFileNotAllowed() {
96
+    public void testCoordinateWithNegativeColumnNotAllowed() {
97 97
         expectedException.expect(IllegalArgumentException.class);
98
-        expectedException.expectMessage("Coordinate must have positive file.");
98
+        expectedException.expectMessage("Coordinate must have positive column.");
99 99
 
100 100
         new BoardCoordinate(2, -2);
101 101
     }
102 102
 
103 103
     @Ignore("Remove to run test")
104 104
     @Test
105
-    public void testCoordinateWithFileGreaterThan7NotAllowed() {
105
+    public void testCoordinateWithColumnGreaterThan7NotAllowed() {
106 106
         expectedException.expect(IllegalArgumentException.class);
107
-        expectedException.expectMessage("Coordinate must have file <= 7.");
107
+        expectedException.expectMessage("Coordinate must have column <= 7.");
108 108
 
109 109
         new BoardCoordinate(4, 8);
110 110
     }