Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class CircularBufferTest {

@Test
@DisplayName("reading empty buffer should fail")
public void readingFromEmptyBufferShouldThrowException() {
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Expand Down
17 changes: 17 additions & 0 deletions exercises/practice/clock/src/test/java/ClockAddTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

@Disabled("Remove to run test")
@Test
@DisplayName("add minutes")
public void addMinutes() {
Clock clock = new Clock(10, 0);
clock.add(3);
Expand All @@ -16,6 +18,7 @@ public void addMinutes() {

@Disabled("Remove to run test")
@Test
@DisplayName("add no minutes")
public void addNoMinutes() {
Clock clock = new Clock(6, 41);
clock.add(0);
Expand All @@ -25,6 +28,7 @@ public void addNoMinutes() {

@Disabled("Remove to run test")
@Test
@DisplayName("add to next hour")
public void addToNextHour() {
Clock clock = new Clock(0, 45);
clock.add(40);
Expand All @@ -34,6 +38,7 @@ public void addToNextHour() {

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

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

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

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

@Disabled("Remove to run test")
@Test
@DisplayName("add more than two days")
public void addMoreThanTwoDays() {
Clock clock = new Clock(1, 1);
clock.add(3500);
Expand All @@ -79,6 +88,7 @@ public void addMoreThanTwoDays() {

@Disabled("Remove to run test")
@Test
@DisplayName("subtract minutes")
public void subtractMinutes() {
Clock clock = new Clock(10, 3);
clock.add(-3);
Expand All @@ -88,6 +98,7 @@ public void subtractMinutes() {

@Disabled("Remove to run test")
@Test
@DisplayName("subtract to previous hour")
public void subtractToPreviousHour() {
Clock clock = new Clock(10, 3);
clock.add(-30);
Expand All @@ -97,6 +108,7 @@ public void subtractToPreviousHour() {

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

@Disabled("Remove to run test")
@Test
@DisplayName("subtract across midnight")
public void subtractAcrossMidnight() {
Clock clock = new Clock(0, 3);
clock.add(-4);
Expand All @@ -115,6 +128,7 @@ public void subtractAcrossMidnight() {

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

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

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

@Disabled("Remove to run test")
@Test
@DisplayName("subtract more than two days")
public void subtractMoreThanTwoDays() {
Clock clock = new Clock(2, 20);
clock.add(-3000);
Expand Down
21 changes: 21 additions & 0 deletions exercises/practice/clock/src/test/java/ClockCreationTest.java
Original file line number Diff line number Diff line change
@@ -1,125 +1,146 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

public class ClockCreationTest {

@Test
@DisplayName("on the hour")
public void canPrintTimeOnTheHour() {
assertThat(new Clock(8, 0).toString()).isEqualTo("08:00");
}

@Disabled("Remove to run test")
@Test
@DisplayName("past the hour")
public void canPrintTimeWithMinutes() {
assertThat(new Clock(11, 9).toString()).isEqualTo("11:09");
}

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

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

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

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

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

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

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

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

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

@Disabled("Remove to run test")
@Test
@DisplayName("negative hour")
public void negativeHour() {
assertThat(new Clock(-1, 15).toString()).isEqualTo("23:15");
}

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

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

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

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

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

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

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

@Disabled("Remove to run test")
@Test
@DisplayName("negative hour and minutes both roll over continuously")
public void negativeHourAndMinutesBothRollOverContinuously() {
assertThat(new Clock(-121, -5810).toString()).isEqualTo("22:10");
}
Expand Down
Loading