Skip to content

Commit 84c050c

Browse files
ledger, linked-list, list-ops (#3016)
* ledger, linked-list, list-ops * Update LedgerTest.java [no important files changed] --------- Co-authored-by: Jagdish Prajapati <[email protected]>
1 parent cb30e85 commit 84c050c

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

exercises/practice/ledger/src/test/java/LedgerTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import org.junit.jupiter.api.Test;
2-
import org.junit.jupiter.api.extension.ExtendWith;
31
import org.junit.jupiter.api.BeforeEach;
42
import org.junit.jupiter.api.Disabled;
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.api.extension.ExtendWith;
5+
import org.junit.jupiter.api.Test;
56

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

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

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

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

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

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

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

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

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

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

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

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

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

177188
@Disabled("Remove to run test")
178189
@Test
190+
@DisplayName("American negative number with 3 digits before decimal point")
179191
public void americanNegativeNumberWith3DigitsBeforeDecimalPoint() {
180192
var entries = new Ledger.LedgerEntry[] {
181193
ledger.createLedgerEntry("2015-03-12", "Buy present", -12345)

exercises/practice/linked-list/src/test/java/DoublyLinkedListTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
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 DoublyLinkedListTest {
78

89
@Test
10+
@DisplayName("pop gets element from the list")
911
public void popGetsElementFromTheList() {
1012
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
1113

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

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

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

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

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

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

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

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

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

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

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

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

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

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

exercises/practice/list-ops/src/test/java/ListOpsTest.java

Lines changed: 23 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 java.util.List;
@@ -8,39 +9,45 @@
89
public class ListOpsTest {
910

1011
@Test
12+
@DisplayName("empty lists")
1113
public void testAppendingEmptyLists() {
1214
assertThat(ListOps.append(List.of(), List.of())).isEmpty();
1315
}
1416

1517
@Disabled("Remove to run test")
1618
@Test
19+
@DisplayName("list to empty list")
1720
public void testAppendingListToEmptyList() {
1821
assertThat(ListOps.append(List.of(), List.of('1', '2', '3', '4')))
1922
.containsExactly('1', '2', '3', '4');
2023
}
2124

2225
@Disabled("Remove to run test")
2326
@Test
27+
@DisplayName("empty list to list")
2428
public void testAppendingEmptyListToList() {
2529
assertThat(ListOps.append(List.of('1', '2', '3', '4'), List.of()))
2630
.containsExactly('1', '2', '3', '4');
2731
}
2832

2933
@Disabled("Remove to run test")
3034
@Test
35+
@DisplayName("non-empty lists")
3136
public void testAppendingNonEmptyLists() {
3237
assertThat(ListOps.append(List.of("1", "2"), List.of("2", "3", "4", "5")))
3338
.containsExactly("1", "2", "2", "3", "4", "5");
3439
}
3540

3641
@Disabled("Remove to run test")
3742
@Test
43+
@DisplayName("empty list")
3844
public void testConcatEmptyList() {
3945
assertThat(ListOps.concat(List.of())).isEmpty();
4046
}
4147

4248
@Disabled("Remove to run test")
4349
@Test
50+
@DisplayName("list of lists")
4451
public void testConcatListOfLists() {
4552
List<List<Character>> listOfLists = List.of(
4653
List.of('1', '2'),
@@ -54,6 +61,7 @@ public void testConcatListOfLists() {
5461

5562
@Disabled("Remove to run test")
5663
@Test
64+
@DisplayName("list of nested lists")
5765
public void testConcatListOfNestedLists() {
5866
List<List<List<Character>>> listOfNestedLists = List.of(
5967
List.of(
@@ -82,45 +90,52 @@ public void testConcatListOfNestedLists() {
8290

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

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

97107
@Disabled("Remove to run test")
98108
@Test
109+
@DisplayName("empty list")
99110
public void testSizeOfEmptyList() {
100111
assertThat(ListOps.size(List.of())).isEqualTo(0);
101112
}
102113

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

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

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

122136
@Disabled("Remove to run test")
123137
@Test
138+
@DisplayName("empty list")
124139
public void testFoldLeftEmptyList() {
125140
assertThat(
126141
ListOps.foldLeft(
@@ -132,6 +147,7 @@ public void testFoldLeftEmptyList() {
132147

133148
@Disabled("Remove to run test")
134149
@Test
150+
@DisplayName("direction independent function applied to non-empty list")
135151
public void testFoldLeftDirectionIndependentFunctionAppliedToNonEmptyList() {
136152
assertThat(
137153
ListOps.foldLeft(
@@ -143,6 +159,7 @@ public void testFoldLeftDirectionIndependentFunctionAppliedToNonEmptyList() {
143159

144160
@Disabled("Remove to run test")
145161
@Test
162+
@DisplayName("direction dependent function applied to non-empty list")
146163
public void testFoldLeftDirectionDependentFunctionAppliedToNonEmptyList() {
147164
assertThat(
148165
ListOps.foldLeft(
@@ -154,6 +171,7 @@ public void testFoldLeftDirectionDependentFunctionAppliedToNonEmptyList() {
154171

155172
@Disabled("Remove to run test")
156173
@Test
174+
@DisplayName("empty list")
157175
public void testFoldRightEmptyList() {
158176
assertThat(
159177
ListOps.foldRight(
@@ -165,6 +183,7 @@ public void testFoldRightEmptyList() {
165183

166184
@Disabled("Remove to run test")
167185
@Test
186+
@DisplayName("direction independent function applied to non-empty list")
168187
public void testFoldRightDirectionIndependentFunctionAppliedToNonEmptyList() {
169188
assertThat(
170189
ListOps.foldRight(
@@ -176,6 +195,7 @@ public void testFoldRightDirectionIndependentFunctionAppliedToNonEmptyList() {
176195

177196
@Disabled("Remove to run test")
178197
@Test
198+
@DisplayName("direction dependent function applied to non-empty list")
179199
public void testFoldRightDirectionDependentFunctionAppliedToNonEmptyList() {
180200
assertThat(
181201
ListOps.foldRight(
@@ -187,19 +207,22 @@ public void testFoldRightDirectionDependentFunctionAppliedToNonEmptyList() {
187207

188208
@Disabled("Remove to run test")
189209
@Test
210+
@DisplayName("empty list")
190211
public void testReversingEmptyList() {
191212
assertThat(ListOps.reverse(List.of())).isEmpty();
192213
}
193214

194215
@Disabled("Remove to run test")
195216
@Test
217+
@DisplayName("non-empty list")
196218
public void testReversingNonEmptyList() {
197219
assertThat(ListOps.reverse(List.of('1', '3', '5', '7')))
198220
.containsExactly('7', '5', '3', '1');
199221
}
200222

201223
@Disabled("Remove to run test")
202224
@Test
225+
@DisplayName("list of lists is not flattened")
203226
public void testReversingListOfListIsNotFlattened() {
204227
List<List<Character>> listOfLists = List.of(
205228
List.of('1', '2'),

0 commit comments

Comments
 (0)