Skip to content

Commit 67c4d79

Browse files
committed
circular-buffer, clock, collatz-conjecture
1 parent eb51842 commit 67c4d79

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

exercises/practice/circular-buffer/src/test/java/CircularBufferTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
33

44
import org.junit.jupiter.api.Disabled;
5+
import org.junit.jupiter.api.DisplayName;
56
import org.junit.jupiter.api.Test;
67

78
public class CircularBufferTest {
89

910
@Test
11+
@DisplayName("reading empty buffer should fail")
1012
public void readingFromEmptyBufferShouldThrowException() {
1113
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);
1214

@@ -17,6 +19,7 @@ public void readingFromEmptyBufferShouldThrowException() {
1719

1820
@Disabled("Remove to run test")
1921
@Test
22+
@DisplayName("can read an item just written")
2023
public void canReadItemJustWritten() throws BufferIOException {
2124
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);
2225

@@ -26,6 +29,7 @@ public void canReadItemJustWritten() throws BufferIOException {
2629

2730
@Disabled("Remove to run test")
2831
@Test
32+
@DisplayName("each item may only be read once")
2933
public void canReadItemOnlyOnce() throws BufferIOException {
3034
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);
3135

@@ -39,6 +43,7 @@ public void canReadItemOnlyOnce() throws BufferIOException {
3943

4044
@Disabled("Remove to run test")
4145
@Test
46+
@DisplayName("items are read in the order they are written")
4247
public void readsItemsInOrderWritten() throws BufferIOException {
4348
CircularBuffer<Integer> buffer = new CircularBuffer<>(2);
4449

@@ -50,6 +55,7 @@ public void readsItemsInOrderWritten() throws BufferIOException {
5055

5156
@Disabled("Remove to run test")
5257
@Test
58+
@DisplayName("full buffer can't be written to")
5359
public void fullBufferCantBeWrittenTo() throws BufferIOException {
5460
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);
5561

@@ -62,6 +68,7 @@ public void fullBufferCantBeWrittenTo() throws BufferIOException {
6268

6369
@Disabled("Remove to run test")
6470
@Test
71+
@DisplayName("a read frees up capacity for another write")
6572
public void readFreesUpSpaceForWrite() throws BufferIOException {
6673
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);
6774

@@ -73,6 +80,7 @@ public void readFreesUpSpaceForWrite() throws BufferIOException {
7380

7481
@Disabled("Remove to run test")
7582
@Test
83+
@DisplayName("read position is maintained even across multiple writes")
7684
public void maintainsReadPositionAcrossWrites() throws BufferIOException {
7785
CircularBuffer<Integer> buffer = new CircularBuffer<>(3);
7886

@@ -86,6 +94,7 @@ public void maintainsReadPositionAcrossWrites() throws BufferIOException {
8694

8795
@Disabled("Remove to run test")
8896
@Test
97+
@DisplayName("items cleared out of buffer can't be read")
8998
public void cantReadClearedItems() throws BufferIOException {
9099
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);
91100

@@ -99,6 +108,7 @@ public void cantReadClearedItems() throws BufferIOException {
99108

100109
@Disabled("Remove to run test")
101110
@Test
111+
@DisplayName("clear frees up capacity for another write")
102112
public void clearFreesUpCapacity() throws BufferIOException {
103113
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);
104114

@@ -110,6 +120,7 @@ public void clearFreesUpCapacity() throws BufferIOException {
110120

111121
@Disabled("Remove to run test")
112122
@Test
123+
@DisplayName("clear does nothing on empty buffer")
113124
public void clearDoesNothingOnEmptyBuffer() throws BufferIOException {
114125
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);
115126

@@ -120,6 +131,7 @@ public void clearDoesNothingOnEmptyBuffer() throws BufferIOException {
120131

121132
@Disabled("Remove to run test")
122133
@Test
134+
@DisplayName("overwrite acts like write on non-full buffer")
123135
public void overwriteActsLikeWriteOnNonFullBuffer() throws BufferIOException {
124136
CircularBuffer<Integer> buffer = new CircularBuffer<>(2);
125137

@@ -131,6 +143,7 @@ public void overwriteActsLikeWriteOnNonFullBuffer() throws BufferIOException {
131143

132144
@Disabled("Remove to run test")
133145
@Test
146+
@DisplayName("overwrite replaces the oldest item on full buffer")
134147
public void overwriteRemovesOldestElementOnFullBuffer() throws BufferIOException {
135148
CircularBuffer<Integer> buffer = new CircularBuffer<>(2);
136149

@@ -143,6 +156,7 @@ public void overwriteRemovesOldestElementOnFullBuffer() throws BufferIOException
143156

144157
@Disabled("Remove to run test")
145158
@Test
159+
@DisplayName("overwrite replaces the oldest item remaining in buffer following a read")
146160
public void overwriteDoesntRemoveAnAlreadyReadElement() throws BufferIOException {
147161
CircularBuffer<Integer> buffer = new CircularBuffer<>(3);
148162

@@ -159,6 +173,7 @@ public void overwriteDoesntRemoveAnAlreadyReadElement() throws BufferIOException
159173

160174
@Disabled("Remove to run test")
161175
@Test
176+
@DisplayName("initial clear does not affect wrapping around")
162177
public void initialClearDoesNotAffectWrappingAround() throws BufferIOException {
163178
CircularBuffer<Integer> buffer = new CircularBuffer<>(2);
164179

exercises/practice/clock/src/test/java/ClockAddTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.junit.jupiter.api.Disabled;
2+
import org.junit.jupiter.api.DisplayName;
23
import org.junit.jupiter.api.Test;
34

45
import static org.assertj.core.api.Assertions.assertThat;
@@ -7,6 +8,7 @@ public class ClockAddTest {
78

89
@Disabled("Remove to run test")
910
@Test
11+
@DisplayName("add minutes")
1012
public void addMinutes() {
1113
Clock clock = new Clock(10, 0);
1214
clock.add(3);
@@ -16,6 +18,7 @@ public void addMinutes() {
1618

1719
@Disabled("Remove to run test")
1820
@Test
21+
@DisplayName("add no minutes")
1922
public void addNoMinutes() {
2023
Clock clock = new Clock(6, 41);
2124
clock.add(0);
@@ -25,6 +28,7 @@ public void addNoMinutes() {
2528

2629
@Disabled("Remove to run test")
2730
@Test
31+
@DisplayName("add to next hour")
2832
public void addToNextHour() {
2933
Clock clock = new Clock(0, 45);
3034
clock.add(40);
@@ -34,6 +38,7 @@ public void addToNextHour() {
3438

3539
@Disabled("Remove to run test")
3640
@Test
41+
@DisplayName("add more than one hour")
3742
public void addMoreThanOneHour() {
3843
Clock clock = new Clock(10, 0);
3944
clock.add(61);
@@ -43,6 +48,7 @@ public void addMoreThanOneHour() {
4348

4449
@Disabled("Remove to run test")
4550
@Test
51+
@DisplayName("add more than two hours with carry")
4652
public void addMoreThanTwoHoursWithCarry() {
4753
Clock clock = new Clock(0, 45);
4854
clock.add(160);
@@ -52,6 +58,7 @@ public void addMoreThanTwoHoursWithCarry() {
5258

5359
@Disabled("Remove to run test")
5460
@Test
61+
@DisplayName("add across midnight")
5562
public void addAcrossMidnight() {
5663
Clock clock = new Clock(23, 59);
5764
clock.add(2);
@@ -61,6 +68,7 @@ public void addAcrossMidnight() {
6168

6269
@Disabled("Remove to run test")
6370
@Test
71+
@DisplayName("add more than one day (1500 min = 25 hrs)")
6472
public void addMoreThanOneDay() {
6573
Clock clock = new Clock(5, 32);
6674
clock.add(1500);
@@ -70,6 +78,7 @@ public void addMoreThanOneDay() {
7078

7179
@Disabled("Remove to run test")
7280
@Test
81+
@DisplayName("add more than two days")
7382
public void addMoreThanTwoDays() {
7483
Clock clock = new Clock(1, 1);
7584
clock.add(3500);
@@ -79,6 +88,7 @@ public void addMoreThanTwoDays() {
7988

8089
@Disabled("Remove to run test")
8190
@Test
91+
@DisplayName("subtract minutes")
8292
public void subtractMinutes() {
8393
Clock clock = new Clock(10, 3);
8494
clock.add(-3);
@@ -88,6 +98,7 @@ public void subtractMinutes() {
8898

8999
@Disabled("Remove to run test")
90100
@Test
101+
@DisplayName("subtract to previous hour")
91102
public void subtractToPreviousHour() {
92103
Clock clock = new Clock(10, 3);
93104
clock.add(-30);
@@ -97,6 +108,7 @@ public void subtractToPreviousHour() {
97108

98109
@Disabled("Remove to run test")
99110
@Test
111+
@DisplayName("subtract more than an hour")
100112
public void subtractMoreThanAnHour() {
101113
Clock clock = new Clock(10, 3);
102114
clock.add(-70);
@@ -106,6 +118,7 @@ public void subtractMoreThanAnHour() {
106118

107119
@Disabled("Remove to run test")
108120
@Test
121+
@DisplayName("subtract across midnight")
109122
public void subtractAcrossMidnight() {
110123
Clock clock = new Clock(0, 3);
111124
clock.add(-4);
@@ -115,6 +128,7 @@ public void subtractAcrossMidnight() {
115128

116129
@Disabled("Remove to run test")
117130
@Test
131+
@DisplayName("subtract more than two hours")
118132
public void subtractMoreThanTwoHours() {
119133
Clock clock = new Clock(0, 0);
120134
clock.add(-160);
@@ -124,6 +138,7 @@ public void subtractMoreThanTwoHours() {
124138

125139
@Disabled("Remove to run test")
126140
@Test
141+
@DisplayName("subtract more than two hours with borrow")
127142
public void subtractMoreThanTwoHoursWithBorrow() {
128143
Clock clock = new Clock(6, 15);
129144
clock.add(-160);
@@ -133,6 +148,7 @@ public void subtractMoreThanTwoHoursWithBorrow() {
133148

134149
@Disabled("Remove to run test")
135150
@Test
151+
@DisplayName("subtract more than one day (1500 min = 25 hrs)")
136152
public void subtractMoreThanOneDay() {
137153
Clock clock = new Clock(5, 32);
138154
clock.add(-1500);
@@ -142,6 +158,7 @@ public void subtractMoreThanOneDay() {
142158

143159
@Disabled("Remove to run test")
144160
@Test
161+
@DisplayName("subtract more than two days")
145162
public void subtractMoreThanTwoDays() {
146163
Clock clock = new Clock(2, 20);
147164
clock.add(-3000);

exercises/practice/clock/src/test/java/ClockCreationTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,146 @@
11
import org.junit.jupiter.api.Disabled;
2+
import org.junit.jupiter.api.DisplayName;
23
import org.junit.jupiter.api.Test;
34

45
import static org.assertj.core.api.Assertions.assertThat;
56

67
public class ClockCreationTest {
78

89
@Test
10+
@DisplayName("on the hour")
911
public void canPrintTimeOnTheHour() {
1012
assertThat(new Clock(8, 0).toString()).isEqualTo("08:00");
1113
}
1214

1315
@Disabled("Remove to run test")
1416
@Test
17+
@DisplayName("past the hour")
1518
public void canPrintTimeWithMinutes() {
1619
assertThat(new Clock(11, 9).toString()).isEqualTo("11:09");
1720
}
1821

1922
@Disabled("Remove to run test")
2023
@Test
24+
@DisplayName("midnight is zero hours")
2125
public void midnightPrintsAsZero() {
2226
assertThat(new Clock(24, 0).toString()).isEqualTo("00:00");
2327
}
2428

2529
@Disabled("Remove to run test")
2630
@Test
31+
@DisplayName("hour rolls over")
2732
public void hourRollsOver() {
2833
assertThat(new Clock(25, 0).toString()).isEqualTo("01:00");
2934
}
3035

3136
@Disabled("Remove to run test")
3237
@Test
38+
@DisplayName("hour rolls over continuously")
3339
public void hourRollsOverContinuously() {
3440
assertThat(new Clock(100, 0).toString()).isEqualTo("04:00");
3541
}
3642

3743
@Disabled("Remove to run test")
3844
@Test
45+
@DisplayName("sixty minutes is next hour")
3946
public void sixtyMinutesIsNextHour() {
4047
assertThat(new Clock(1, 60).toString()).isEqualTo("02:00");
4148
}
4249

4350
@Disabled("Remove to run test")
4451
@Test
52+
@DisplayName("minutes roll over")
4553
public void minutesRollOver() {
4654
assertThat(new Clock(0, 160).toString()).isEqualTo("02:40");
4755
}
4856

4957
@Disabled("Remove to run test")
5058
@Test
59+
@DisplayName("minutes roll over continuously")
5160
public void minutesRollOverContinuously() {
5261
assertThat(new Clock(0, 1723).toString()).isEqualTo("04:43");
5362
}
5463

5564
@Disabled("Remove to run test")
5665
@Test
66+
@DisplayName("hour and minutes roll over")
5767
public void hourAndMinutesRollOver() {
5868
assertThat(new Clock(25, 160).toString()).isEqualTo("03:40");
5969
}
6070

6171
@Disabled("Remove to run test")
6272
@Test
73+
@DisplayName("hour and minutes roll over continuously")
6374
public void hourAndMinutesRollOverContinuously() {
6475
assertThat(new Clock(201, 3001).toString()).isEqualTo("11:01");
6576
}
6677

6778
@Disabled("Remove to run test")
6879
@Test
80+
@DisplayName("hour and minutes roll over to exactly midnight")
6981
public void hourAndMinutesRollOverToExactlyMidnight() {
7082
assertThat(new Clock(72, 8640).toString()).isEqualTo("00:00");
7183
}
7284

7385
@Disabled("Remove to run test")
7486
@Test
87+
@DisplayName("negative hour")
7588
public void negativeHour() {
7689
assertThat(new Clock(-1, 15).toString()).isEqualTo("23:15");
7790
}
7891

7992
@Disabled("Remove to run test")
8093
@Test
94+
@DisplayName("negative hour rolls over")
8195
public void negativeHourRollsOver() {
8296
assertThat(new Clock(-25, 0).toString()).isEqualTo("23:00");
8397
}
8498

8599
@Disabled("Remove to run test")
86100
@Test
101+
@DisplayName("negative hour rolls over continuously")
87102
public void negativeHourRollsOverContinuously() {
88103
assertThat(new Clock(-91, 0).toString()).isEqualTo("05:00");
89104
}
90105

91106
@Disabled("Remove to run test")
92107
@Test
108+
@DisplayName("negative minutes")
93109
public void negativeMinutes() {
94110
assertThat(new Clock(1, -40).toString()).isEqualTo("00:20");
95111
}
96112

97113
@Disabled("Remove to run test")
98114
@Test
115+
@DisplayName("negative minutes roll over")
99116
public void negativeMinutesRollOver() {
100117
assertThat(new Clock(1, -160).toString()).isEqualTo("22:20");
101118
}
102119

103120
@Disabled("Remove to run test")
104121
@Test
122+
@DisplayName("negative minutes roll over continuously")
105123
public void negativeMinutesRollOverContinuously() {
106124
assertThat(new Clock(1, -4820).toString()).isEqualTo("16:40");
107125
}
108126

109127
@Disabled("Remove to run test")
110128
@Test
129+
@DisplayName("negative sixty minutes is previous hour")
111130
public void negativeSixtyMinutesIsPreviousHour() {
112131
assertThat(new Clock(2, -60).toString()).isEqualTo("01:00");
113132
}
114133

115134
@Disabled("Remove to run test")
116135
@Test
136+
@DisplayName("negative hour and minutes both roll over")
117137
public void negativeHourAndMinutesBothRollOver() {
118138
assertThat(new Clock(-25, -160).toString()).isEqualTo("20:20");
119139
}
120140

121141
@Disabled("Remove to run test")
122142
@Test
143+
@DisplayName("negative hour and minutes both roll over continuously")
123144
public void negativeHourAndMinutesBothRollOverContinuously() {
124145
assertThat(new Clock(-121, -5810).toString()).isEqualTo("22:10");
125146
}

0 commit comments

Comments
 (0)