ソースを参照

Merge pull request #609 from exercism/clock-assertions

clock: prefer assert(Not)Equals to assert(True|False)
FridaTveit 9 年 前
コミット
438f8120e8
共有2 個のファイルを変更した21 個の追加17 個の削除を含む
  1. 3
    0
      exercises/clock/HINT.md
  2. 18
    17
      exercises/clock/src/test/java/ClockEqualTest.java

+ 3
- 0
exercises/clock/HINT.md ファイルの表示

1
+In order to satisfy the requirement that two clocks are considered equal just when they are set to the same time, you will need to override the [`equals`](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals(java.lang.Object)) and [`hashcode`](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode) methods in your `Clock` class.
2
+ 
3
+For more information on how to override these methods, see [this JavaWorld article](https://web.archive.org/web/20170528222153/http://www.javaworld.com/article/2072762/java-app-dev/object-equality.html).

+ 18
- 17
exercises/clock/src/test/java/ClockEqualTest.java ファイルの表示

1
 import org.junit.Ignore;
1
 import org.junit.Ignore;
2
 import org.junit.Test;
2
 import org.junit.Test;
3
 
3
 
4
-import static org.junit.Assert.assertFalse;
5
-import static org.junit.Assert.assertTrue;
4
+import static org.junit.Assert.assertNotEquals;
5
+import static org.junit.Assert.assertEquals;
6
 
6
 
7
 public class ClockEqualTest {
7
 public class ClockEqualTest {
8
 
8
 
9
     @Ignore("Remove to run test")
9
     @Ignore("Remove to run test")
10
     @Test
10
     @Test
11
     public void clocksWithSameTimeAreEqual() {
11
     public void clocksWithSameTimeAreEqual() {
12
-        assertTrue(new Clock(15, 37).equals(new Clock(15, 37)));
12
+        assertEquals(new Clock(15, 37), new Clock(15, 37));
13
     }
13
     }
14
 
14
 
15
     @Ignore("Remove to run test")
15
     @Ignore("Remove to run test")
16
     @Test
16
     @Test
17
     public void clocksAMinuteApartAreNotEqual() {
17
     public void clocksAMinuteApartAreNotEqual() {
18
-        assertFalse(new Clock(15, 36).equals(new Clock(15, 37)));
18
+        assertNotEquals(new Clock(15, 36), new Clock(15, 37));
19
     }
19
     }
20
 
20
 
21
     @Ignore("Remove to run test")
21
     @Ignore("Remove to run test")
22
     @Test
22
     @Test
23
     public void clocksAnHourApartAreNotEqual() {
23
     public void clocksAnHourApartAreNotEqual() {
24
-        assertFalse(new Clock(14, 37).equals(new Clock(15, 37)));
24
+        assertNotEquals(new Clock(14, 37), new Clock(15, 37));
25
     }
25
     }
26
 
26
 
27
     @Ignore("Remove to run test")
27
     @Ignore("Remove to run test")
28
     @Test
28
     @Test
29
     public void clocksWithHourOverflow() {
29
     public void clocksWithHourOverflow() {
30
-        assertTrue(new Clock(10, 37).equals(new Clock(34, 37)));
30
+        assertEquals(new Clock(10, 37), new Clock(34, 37));
31
     }
31
     }
32
 
32
 
33
     @Ignore("Remove to run test")
33
     @Ignore("Remove to run test")
34
     @Test
34
     @Test
35
     public void clocksWithHourOverflowBySeveralDays() {
35
     public void clocksWithHourOverflowBySeveralDays() {
36
-        assertTrue(new Clock(3, 11).equals(new Clock(99, 11)));
36
+        assertEquals(new Clock(3, 11), new Clock(99, 11));
37
     }
37
     }
38
 
38
 
39
     @Ignore("Remove to run test")
39
     @Ignore("Remove to run test")
40
     @Test
40
     @Test
41
     public void clocksWithNegateHour() {
41
     public void clocksWithNegateHour() {
42
-        assertTrue(new Clock(22, 40).equals(new Clock(-2, 40)));
42
+        assertEquals(new Clock(22, 40), new Clock(-2, 40));
43
     }
43
     }
44
 
44
 
45
     @Ignore("Remove to run test")
45
     @Ignore("Remove to run test")
46
     @Test
46
     @Test
47
     public void clocksWithNegativeHourThatWraps() {
47
     public void clocksWithNegativeHourThatWraps() {
48
-        assertTrue(new Clock(17, 3).equals(new Clock(-31, 3)));
48
+        assertEquals(new Clock(17, 3), new Clock(-31, 3));
49
     }
49
     }
50
 
50
 
51
     @Ignore("Remove to run test")
51
     @Ignore("Remove to run test")
52
     @Test
52
     @Test
53
     public void clocksWithNegativeHourThatWrapsMultipleTimes() {
53
     public void clocksWithNegativeHourThatWrapsMultipleTimes() {
54
-        assertTrue(new Clock(13, 49).equals(new Clock(-83, 49)));
54
+        assertEquals(new Clock(13, 49), new Clock(-83, 49));
55
     }
55
     }
56
 
56
 
57
     @Ignore("Remove to run test")
57
     @Ignore("Remove to run test")
58
     @Test
58
     @Test
59
     public void clocksWithMinuteOverflow() {
59
     public void clocksWithMinuteOverflow() {
60
-        assertTrue(new Clock(0, 1).equals(new Clock(0, 1441)));
60
+        assertEquals(new Clock(0, 1), new Clock(0, 1441));
61
     }
61
     }
62
 
62
 
63
     @Ignore("Remove to run test")
63
     @Ignore("Remove to run test")
64
     @Test
64
     @Test
65
     public void clocksWithMinuteOverflowBySeveralDays() {
65
     public void clocksWithMinuteOverflowBySeveralDays() {
66
-        assertTrue(new Clock(2, 2).equals(new Clock(2, 4322)));
66
+        assertEquals(new Clock(2, 2), new Clock(2, 4322));
67
     }
67
     }
68
 
68
 
69
     @Ignore("Remove to run test")
69
     @Ignore("Remove to run test")
70
     @Test
70
     @Test
71
     public void clocksWithNegativeMinutes() {
71
     public void clocksWithNegativeMinutes() {
72
-        assertTrue(new Clock(2, 40).equals(new Clock(3, -20)));
72
+        assertEquals(new Clock(2, 40), new Clock(3, -20));
73
     }
73
     }
74
 
74
 
75
     @Ignore("Remove to run test")
75
     @Ignore("Remove to run test")
76
     @Test
76
     @Test
77
     public void clocksWithNegativeMinutesThatWraps() {
77
     public void clocksWithNegativeMinutesThatWraps() {
78
-        assertTrue(new Clock(4, 10).equals(new Clock(5, -1490)));
78
+        assertEquals(new Clock(4, 10), new Clock(5, -1490));
79
     }
79
     }
80
 
80
 
81
     @Ignore("Remove to run test")
81
     @Ignore("Remove to run test")
82
     @Test
82
     @Test
83
     public void clocksWithNegativeMinutesThatWrapsMultipleTimes() {
83
     public void clocksWithNegativeMinutesThatWrapsMultipleTimes() {
84
-        assertTrue(new Clock(6, 15).equals(new Clock(6, -4305)));
84
+        assertEquals(new Clock(6, 15), new Clock(6, -4305));
85
     }
85
     }
86
 
86
 
87
     @Ignore("Remove to run test")
87
     @Ignore("Remove to run test")
88
     @Test
88
     @Test
89
     public void clocksWithNegativeHoursAndMinutes() {
89
     public void clocksWithNegativeHoursAndMinutes() {
90
-        assertTrue(new Clock(7, 32).equals(new Clock(-12, -268)));
90
+        assertEquals(new Clock(7, 32), new Clock(-12, -268));
91
     }
91
     }
92
 
92
 
93
     @Ignore("Remove to run test")
93
     @Ignore("Remove to run test")
94
     @Test
94
     @Test
95
     public void clocksWithNegativeHoursAndMinutesThatWrap() {
95
     public void clocksWithNegativeHoursAndMinutesThatWrap() {
96
-        assertTrue(new Clock(18, 7).equals(new Clock(-54, -11513)));
96
+        assertEquals(new Clock(18, 7), new Clock(-54, -11513));
97
     }
97
     }
98
+
98
 }
99
 }