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

queen-attack: update to v2.0.0

https://github.com/exercism/problem-specifications/commit/44a1e12aedb1a9acff3ee79c0413ecf3093401a6#diff-96b36309ff1b4f05ed51e0af6563ed56
Stuart Kent 9 лет назад
Родитель
Сommit
d88f700da2

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

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
         validateInputs();
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
     private void validateInputs() throws IllegalArgumentException {
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
     private void validateCoordinateComponent(final int value, final String componentName)
27
     private void validateCoordinateComponent(final int value, final String componentName)

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

1
-public final class QueenAttackCalculator {
1
+final class QueenAttackCalculator {
2
 
2
 
3
     private final BoardCoordinate whiteQueenCoordinate;
3
     private final BoardCoordinate whiteQueenCoordinate;
4
 
4
 
5
     private final BoardCoordinate blackQueenCoordinate;
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
             throws IllegalArgumentException {
8
             throws IllegalArgumentException {
9
 
9
 
10
         this.whiteQueenCoordinate = whiteQueenCoordinate;
10
         this.whiteQueenCoordinate = whiteQueenCoordinate;
13
         validateInputs();
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
     private void validateInputs() throws IllegalArgumentException {
20
     private void validateInputs() throws IllegalArgumentException {
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
     private boolean queensShareBoardCoordinate() {
38
     private boolean queensShareBoardCoordinate() {
39
-        return queensShareRank() && queensShareFile();
39
+        return queensShareRow() && queensShareColumn();
40
     }
40
     }
41
 
41
 
42
     private boolean queensShareDiagonal() {
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.0.0
1
+2.0.0

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

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