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
16 changes: 14 additions & 2 deletions exercises/practice/ledger/src/test/java/LedgerTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.Test;

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

Expand All @@ -23,6 +24,7 @@ public void setUp() throws Exception {

@Disabled("Remove to run test")
@Test
@DisplayName("empty ledger")
public void emptyLedgerUS() {
var entries = new Ledger.LedgerEntry[] {};

Expand All @@ -34,6 +36,7 @@ public void emptyLedgerUS() {

@Disabled("Remove to run test")
@Test
@DisplayName("one entry")
public void oneEntry() {
var entries = new Ledger.LedgerEntry[] {
ledger.createLedgerEntry("2015-01-01", "Buy present", -1000)
Expand All @@ -48,6 +51,7 @@ public void oneEntry() {

@Disabled("Remove to run test")
@Test
@DisplayName("credit and debit")
public void creditAndDebit() {
var entries = new Ledger.LedgerEntry[] {
ledger.createLedgerEntry("2015-01-02", "Get present", 1000),
Expand All @@ -65,6 +69,7 @@ public void creditAndDebit() {

@Disabled("Remove to run test")
@Test
@DisplayName("multiple entries on same date ordered by description")
public void multipleEntriesOnSameDateOrderedByDescription() {
var entries = new Ledger.LedgerEntry[] {
ledger.createLedgerEntry("2015-01-01", "Get present", 1000),
Expand All @@ -82,6 +87,7 @@ public void multipleEntriesOnSameDateOrderedByDescription() {

@Disabled("Remove to run test")
@Test
@DisplayName("final order tie breaker is change")
public void finalOrderTieBreakerIsChange() {
var entries = new Ledger.LedgerEntry[] {
ledger.createLedgerEntry("2015-01-01", "Something", 0),
Expand All @@ -101,6 +107,7 @@ public void finalOrderTieBreakerIsChange() {

@Disabled("Remove to run test")
@Test
@DisplayName("overlong description is truncated")
public void overlongDescriptions() {
var entries = new Ledger.LedgerEntry[] {
ledger.createLedgerEntry("2015-01-01", "Freude schoner Gotterfunken", -123456)
Expand All @@ -116,6 +123,7 @@ public void overlongDescriptions() {

@Disabled("Remove to run test")
@Test
@DisplayName("euros")
public void euros() {
var entries = new Ledger.LedgerEntry[] {
ledger.createLedgerEntry("2015-01-01", "Buy present", -1000)
Expand All @@ -131,6 +139,7 @@ public void euros() {

@Disabled("Remove to run test")
@Test
@DisplayName("Dutch locale")
public void dutchLocale() {
var entries = new Ledger.LedgerEntry[] {
ledger.createLedgerEntry("2015-03-12", "Buy present", 123456)
Expand All @@ -146,6 +155,7 @@ public void dutchLocale() {

@Disabled("Remove to run test")
@Test
@DisplayName("Dutch locale and euros")
public void dutchLocaleAndEuros() {
var entries = new Ledger.LedgerEntry[] {
ledger.createLedgerEntry("2015-03-12", "Buy present", 123456)
Expand All @@ -161,6 +171,7 @@ public void dutchLocaleAndEuros() {

@Disabled("Remove to run test")
@Test
@DisplayName("Dutch negative number with 3 digits before decimal point")
public void dutchNegativeNumberWith3DigitsBeforeDecimalPoint() {
var entries = new Ledger.LedgerEntry[] {
ledger.createLedgerEntry("2015-03-12", "Buy present", -12345)
Expand All @@ -176,6 +187,7 @@ public void dutchNegativeNumberWith3DigitsBeforeDecimalPoint() {

@Disabled("Remove to run test")
@Test
@DisplayName("American negative number with 3 digits before decimal point")
public void americanNegativeNumberWith3DigitsBeforeDecimalPoint() {
var entries = new Ledger.LedgerEntry[] {
ledger.createLedgerEntry("2015-03-12", "Buy present", -12345)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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 DoublyLinkedListTest {

@Test
@DisplayName("pop gets element from the list")
public void popGetsElementFromTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

Expand All @@ -16,6 +18,7 @@ public void popGetsElementFromTheList() {

@Disabled("Remove to run test")
@Test
@DisplayName("push/pop respectively add/remove at the end of the list")
public void pushAndPopRespectivelyAddsAndRemovesAtEndOfList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

Expand All @@ -28,6 +31,7 @@ public void pushAndPopRespectivelyAddsAndRemovesAtEndOfList() {

@Disabled("Remove to run test")
@Test
@DisplayName("shift gets an element from the list")
public void shiftGetsAnElementFromTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

Expand All @@ -38,6 +42,7 @@ public void shiftGetsAnElementFromTheList() {

@Disabled("Remove to run test")
@Test
@DisplayName("shift gets first element from the list")
public void shiftGetsFirstElementFromTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

Expand All @@ -50,6 +55,7 @@ public void shiftGetsFirstElementFromTheList() {

@Disabled("Remove to run test")
@Test
@DisplayName("unshift adds element at start of the list")
public void unshiftAddsElementAtStartOfTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

Expand All @@ -62,6 +68,7 @@ public void unshiftAddsElementAtStartOfTheList() {

@Disabled("Remove to run test")
@Test
@DisplayName("pop push shift unshift can be used in any order")
public void popPushShiftUnshiftCanBeUsedInAnyOrder() {
DoublyLinkedList<String> list = new DoublyLinkedList<>();

Expand All @@ -84,6 +91,7 @@ public void popPushShiftUnshiftCanBeUsedInAnyOrder() {

@Disabled("Remove to run test")
@Test
@DisplayName("popping to empty doesn't break the list")
public void poppingToEmptyDoesNotBreakTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

Expand All @@ -98,6 +106,7 @@ public void poppingToEmptyDoesNotBreakTheList() {

@Disabled("Remove to run test")
@Test
@DisplayName("shifting to empty doesn't break the list")
public void shiftingToEmptyDoesNotBreakTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

Expand Down
23 changes: 23 additions & 0 deletions exercises/practice/list-ops/src/test/java/ListOpsTest.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 java.util.List;
Expand All @@ -8,39 +9,45 @@
public class ListOpsTest {

@Test
@DisplayName("empty lists")
public void testAppendingEmptyLists() {
assertThat(ListOps.append(List.of(), List.of())).isEmpty();
}

@Disabled("Remove to run test")
@Test
@DisplayName("list to empty list")
public void testAppendingListToEmptyList() {
assertThat(ListOps.append(List.of(), List.of('1', '2', '3', '4')))
.containsExactly('1', '2', '3', '4');
}

@Disabled("Remove to run test")
@Test
@DisplayName("empty list to list")
public void testAppendingEmptyListToList() {
assertThat(ListOps.append(List.of('1', '2', '3', '4'), List.of()))
.containsExactly('1', '2', '3', '4');
}

@Disabled("Remove to run test")
@Test
@DisplayName("non-empty lists")
public void testAppendingNonEmptyLists() {
assertThat(ListOps.append(List.of("1", "2"), List.of("2", "3", "4", "5")))
.containsExactly("1", "2", "2", "3", "4", "5");
}

@Disabled("Remove to run test")
@Test
@DisplayName("empty list")
public void testConcatEmptyList() {
assertThat(ListOps.concat(List.of())).isEmpty();
}

@Disabled("Remove to run test")
@Test
@DisplayName("list of lists")
public void testConcatListOfLists() {
List<List<Character>> listOfLists = List.of(
List.of('1', '2'),
Expand All @@ -54,6 +61,7 @@ public void testConcatListOfLists() {

@Disabled("Remove to run test")
@Test
@DisplayName("list of nested lists")
public void testConcatListOfNestedLists() {
List<List<List<Character>>> listOfNestedLists = List.of(
List.of(
Expand Down Expand Up @@ -82,45 +90,52 @@ public void testConcatListOfNestedLists() {

@Disabled("Remove to run test")
@Test
@DisplayName("empty list")
public void testFilteringEmptyList() {
assertThat(ListOps.filter(List.<Integer>of(), integer -> integer % 2 == 1))
.isEmpty();
}

@Disabled("Remove to run test")
@Test
@DisplayName("non-empty list")
public void testFilteringNonEmptyList() {
assertThat(ListOps.filter(List.of(1, 2, 3, 5), integer -> integer % 2 == 1))
.containsExactly(1, 3, 5);
}

@Disabled("Remove to run test")
@Test
@DisplayName("empty list")
public void testSizeOfEmptyList() {
assertThat(ListOps.size(List.of())).isEqualTo(0);
}

@Disabled("Remove to run test")
@Test
@DisplayName("non-empty list")
public void testSizeOfNonEmptyList() {
assertThat(ListOps.size(List.of("one", "two", "three", "four"))).isEqualTo(4);
}

@Disabled("Remove to run test")
@Test
@DisplayName("empty list")
public void testTransformingEmptyList() {
assertThat(ListOps.map(List.<Integer>of(), integer -> integer + 1)).isEmpty();
}

@Disabled("Remove to run test")
@Test
@DisplayName("non-empty list")
public void testTransformingNonEmptyList() {
assertThat(ListOps.map(List.of(1, 3, 5, 7), integer -> integer + 1))
.containsExactly(2, 4, 6, 8);
}

@Disabled("Remove to run test")
@Test
@DisplayName("empty list")
public void testFoldLeftEmptyList() {
assertThat(
ListOps.foldLeft(
Expand All @@ -132,6 +147,7 @@ public void testFoldLeftEmptyList() {

@Disabled("Remove to run test")
@Test
@DisplayName("direction independent function applied to non-empty list")
public void testFoldLeftDirectionIndependentFunctionAppliedToNonEmptyList() {
assertThat(
ListOps.foldLeft(
Expand All @@ -143,6 +159,7 @@ public void testFoldLeftDirectionIndependentFunctionAppliedToNonEmptyList() {

@Disabled("Remove to run test")
@Test
@DisplayName("direction dependent function applied to non-empty list")
public void testFoldLeftDirectionDependentFunctionAppliedToNonEmptyList() {
assertThat(
ListOps.foldLeft(
Expand All @@ -154,6 +171,7 @@ public void testFoldLeftDirectionDependentFunctionAppliedToNonEmptyList() {

@Disabled("Remove to run test")
@Test
@DisplayName("empty list")
public void testFoldRightEmptyList() {
assertThat(
ListOps.foldRight(
Expand All @@ -165,6 +183,7 @@ public void testFoldRightEmptyList() {

@Disabled("Remove to run test")
@Test
@DisplayName("direction independent function applied to non-empty list")
public void testFoldRightDirectionIndependentFunctionAppliedToNonEmptyList() {
assertThat(
ListOps.foldRight(
Expand All @@ -176,6 +195,7 @@ public void testFoldRightDirectionIndependentFunctionAppliedToNonEmptyList() {

@Disabled("Remove to run test")
@Test
@DisplayName("direction dependent function applied to non-empty list")
public void testFoldRightDirectionDependentFunctionAppliedToNonEmptyList() {
assertThat(
ListOps.foldRight(
Expand All @@ -187,19 +207,22 @@ public void testFoldRightDirectionDependentFunctionAppliedToNonEmptyList() {

@Disabled("Remove to run test")
@Test
@DisplayName("empty list")
public void testReversingEmptyList() {
assertThat(ListOps.reverse(List.of())).isEmpty();
}

@Disabled("Remove to run test")
@Test
@DisplayName("non-empty list")
public void testReversingNonEmptyList() {
assertThat(ListOps.reverse(List.of('1', '3', '5', '7')))
.containsExactly('7', '5', '3', '1');
}

@Disabled("Remove to run test")
@Test
@DisplayName("list of lists is not flattened")
public void testReversingListOfListIsNotFlattened() {
List<List<Character>> listOfLists = List.of(
List.of('1', '2'),
Expand Down