Skip to content

Commit 03bfe74

Browse files
kindergarten-garden, knapsack, largest-series-product, leap (#3014)
* kindergarten-garten, knapsack, largest-series-product, leap * Update KindergartenGardenTest.java * Update KnapsackTest.java [no important files changed] --------- Co-authored-by: Jagdish Prajapati <[email protected]>
1 parent b4a8b9f commit 03bfe74

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

exercises/practice/kindergarten-garden/src/test/java/KindergartenGardenTest.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
2-
import org.junit.jupiter.api.Test;
31
import org.junit.jupiter.api.Disabled;
4-
2+
import org.junit.jupiter.api.DisplayName;
3+
import org.junit.jupiter.api.Test;
54
import static org.assertj.core.api.Assertions.assertThat;
65

76
public class KindergartenGardenTest {
87

98
@Test
9+
@DisplayName("garden with single student")
1010
public void singleStudent() {
1111
String garden = "RC\nGG";
1212
String student = "Alice";
@@ -17,6 +17,7 @@ public void singleStudent() {
1717

1818
@Disabled("Remove to run test")
1919
@Test
20+
@DisplayName("different garden with single student")
2021
public void singleStudent2() {
2122
String garden = "VC\nRC";
2223
String student = "Alice";
@@ -27,6 +28,7 @@ public void singleStudent2() {
2728

2829
@Disabled("Remove to run test")
2930
@Test
31+
@DisplayName("garden with two students")
3032
public void twoStudents() {
3133
String garden = "VVCG\nVVRC";
3234
String student = "Bob";
@@ -37,6 +39,7 @@ public void twoStudents() {
3739

3840
@Disabled("Remove to run test")
3941
@Test
42+
@DisplayName("second student's garden")
4043
public void oneGardenSecondStudent() {
4144
String garden = "VVCCGG\nVVCCGG";
4245
String student = "Bob";
@@ -47,6 +50,7 @@ public void oneGardenSecondStudent() {
4750

4851
@Disabled("Remove to run test")
4952
@Test
53+
@DisplayName("third student's garden")
5054
public void oneGardenThirdStudent() {
5155
String garden = "VVCCGG\nVVCCGG";
5256
String student = "Charlie";
@@ -57,6 +61,7 @@ public void oneGardenThirdStudent() {
5761

5862
@Disabled("Remove to run test")
5963
@Test
64+
@DisplayName("for Alice, first student's garden")
6065
public void fullGardenForAlice() {
6166
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
6267
String student = "Alice";
@@ -67,6 +72,7 @@ public void fullGardenForAlice() {
6772

6873
@Disabled("Remove to run test")
6974
@Test
75+
@DisplayName("for Bob, second student's garden")
7076
public void fullGardenForBob() {
7177
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
7278
String student = "Bob";
@@ -77,6 +83,7 @@ public void fullGardenForBob() {
7783

7884
@Disabled("Remove to run test")
7985
@Test
86+
@DisplayName("for Charlie")
8087
public void fullGardenForCharlie() {
8188
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
8289
String student = "Charlie";
@@ -87,6 +94,7 @@ public void fullGardenForCharlie() {
8794

8895
@Disabled("Remove to run test")
8996
@Test
97+
@DisplayName("for David")
9098
public void fullGardenForDavid() {
9199
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
92100
String student = "David";
@@ -97,6 +105,7 @@ public void fullGardenForDavid() {
97105

98106
@Disabled("Remove to run test")
99107
@Test
108+
@DisplayName("for Eve")
100109
public void fullGardenForEve() {
101110
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
102111
String student = "Eve";
@@ -107,6 +116,7 @@ public void fullGardenForEve() {
107116

108117
@Disabled("Remove to run test")
109118
@Test
119+
@DisplayName("for Fred")
110120
public void fullGardenForFred() {
111121
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
112122
String student = "Fred";
@@ -117,6 +127,7 @@ public void fullGardenForFred() {
117127

118128
@Disabled("Remove to run test")
119129
@Test
130+
@DisplayName("for Ginny")
120131
public void fullGardenForGinny() {
121132
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
122133
String student = "Ginny";
@@ -127,6 +138,7 @@ public void fullGardenForGinny() {
127138

128139
@Disabled("Remove to run test")
129140
@Test
141+
@DisplayName("for Harriet")
130142
public void fullGardenForHarriet() {
131143
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
132144
String student = "Harriet";
@@ -137,6 +149,7 @@ public void fullGardenForHarriet() {
137149

138150
@Disabled("Remove to run test")
139151
@Test
152+
@DisplayName("for Ileana")
140153
public void fullGardenForIleana() {
141154
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
142155
String student = "Ileana";
@@ -147,6 +160,7 @@ public void fullGardenForIleana() {
147160

148161
@Disabled("Remove to run test")
149162
@Test
163+
@DisplayName("for Joseph")
150164
public void fullGardenForJoseph() {
151165
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
152166
String student = "Joseph";
@@ -157,6 +171,7 @@ public void fullGardenForJoseph() {
157171

158172
@Disabled("Remove to run test")
159173
@Test
174+
@DisplayName("for Kincaid, second to last student's garden")
160175
public void fullGardenForKincaid() {
161176
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
162177
String student = "Kincaid";
@@ -167,6 +182,7 @@ public void fullGardenForKincaid() {
167182

168183
@Disabled("Remove to run test")
169184
@Test
185+
@DisplayName("for Larry, last student's garden")
170186
public void fullGardenForLarry() {
171187
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
172188
String student = "Larry";

exercises/practice/knapsack/src/test/java/KnapsackTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import org.junit.jupiter.api.Disabled;
21
import org.junit.jupiter.api.BeforeEach;
2+
import org.junit.jupiter.api.Disabled;
3+
import org.junit.jupiter.api.DisplayName;
34
import org.junit.jupiter.api.Test;
45

56
import java.util.List;
@@ -17,13 +18,15 @@ public void setup() {
1718
}
1819

1920
@Test
21+
@DisplayName("no items")
2022
public void testNoItems() {
2123
List<Item> items = List.of();
2224
assertThat(knapsack.maximumValue(100, items)).isEqualTo(0);
2325
}
2426

2527
@Disabled("Remove to run test")
2628
@Test
29+
@DisplayName("one item, too heavy")
2730
public void testOneItemTooHeavy() {
2831
List<Item> items = List.of(
2932
new Item(100, 1)
@@ -34,6 +37,7 @@ public void testOneItemTooHeavy() {
3437

3538
@Disabled("Remove to run test")
3639
@Test
40+
@DisplayName("five items (cannot be greedy by weight)")
3741
public void testFiveItemsCannotBeGreedyByWeight() {
3842
List<Item> items = List.of(
3943
new Item(2, 5),
@@ -48,6 +52,7 @@ public void testFiveItemsCannotBeGreedyByWeight() {
4852

4953
@Disabled("Remove to run test")
5054
@Test
55+
@DisplayName("five items (cannot be greedy by value)")
5156
public void testFiveItemsCannotBeGreedyByValue() {
5257
List<Item> items = List.of(
5358
new Item(2, 20),
@@ -62,6 +67,7 @@ public void testFiveItemsCannotBeGreedyByValue() {
6267

6368
@Disabled("Remove to run test")
6469
@Test
70+
@DisplayName("example knapsack")
6571
public void testExampleKnapsack() {
6672
List<Item> items = List.of(
6773
new Item(5, 10),
@@ -75,6 +81,7 @@ public void testExampleKnapsack() {
7581

7682
@Disabled("Remove to run test")
7783
@Test
84+
@DisplayName("8 items")
7885
public void testEightItems() {
7986
List<Item> items = List.of(
8087
new Item(25, 350),
@@ -92,6 +99,7 @@ public void testEightItems() {
9299

93100
@Disabled("Remove to run test")
94101
@Test
102+
@DisplayName("15 items")
95103
public void testFifteenItems() {
96104
List<Item> items = List.of(
97105
new Item(70, 135),

exercises/practice/largest-series-product/src/test/java/LargestSeriesProductCalculatorTest.java

Lines changed: 15 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 @@
78
public class LargestSeriesProductCalculatorTest {
89

910
@Test
11+
@DisplayName("finds the largest product if span equals length")
1012
public void testCorrectlyCalculatesLargestProductWhenSeriesLengthEqualsStringToSearchLength() {
1113
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("29");
1214
long expectedProduct = 18;
@@ -18,6 +20,7 @@ public void testCorrectlyCalculatesLargestProductWhenSeriesLengthEqualsStringToS
1820

1921
@Disabled("Remove to run test")
2022
@Test
23+
@DisplayName("can find the largest product of 2 with numbers in order")
2124
public void testCorrectlyCalculatesLargestProductOfLengthTwoWithNumbersInOrder() {
2225
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0123456789");
2326
long expectedProduct = 72;
@@ -29,6 +32,7 @@ public void testCorrectlyCalculatesLargestProductOfLengthTwoWithNumbersInOrder()
2932

3033
@Disabled("Remove to run test")
3134
@Test
35+
@DisplayName("can find the largest product of 2")
3236
public void testCorrectlyCalculatesLargestProductOfLengthTwoWithNumbersNotInOrder() {
3337
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("576802143");
3438
long expectedProduct = 48;
@@ -40,6 +44,7 @@ public void testCorrectlyCalculatesLargestProductOfLengthTwoWithNumbersNotInOrde
4044

4145
@Disabled("Remove to run test")
4246
@Test
47+
@DisplayName("can find the largest product of 3 with numbers in order")
4348
public void testCorrectlyCalculatesLargestProductOfLengthThreeWithNumbersInOrder() {
4449
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0123456789");
4550
long expectedProduct = 504;
@@ -51,6 +56,7 @@ public void testCorrectlyCalculatesLargestProductOfLengthThreeWithNumbersInOrder
5156

5257
@Disabled("Remove to run test")
5358
@Test
59+
@DisplayName("can find the largest product of 3")
5460
public void testCorrectlyCalculatesLargestProductOfLengthThreeWithNumbersNotInOrder() {
5561
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("1027839564");
5662
long expectedProduct = 270;
@@ -62,6 +68,7 @@ public void testCorrectlyCalculatesLargestProductOfLengthThreeWithNumbersNotInOr
6268

6369
@Disabled("Remove to run test")
6470
@Test
71+
@DisplayName("can find the largest product of 5 with numbers in order")
6572
public void testCorrectlyCalculatesLargestProductOfLengthFiveWithNumbersInOrder() {
6673
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0123456789");
6774
long expectedProduct = 15120;
@@ -73,6 +80,7 @@ public void testCorrectlyCalculatesLargestProductOfLengthFiveWithNumbersInOrder(
7380

7481
@Disabled("Remove to run test")
7582
@Test
83+
@DisplayName("can get the largest product of a big number")
7684
public void testCorrectlyCalculatesLargestProductInLongStringToSearchV1() {
7785
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator(
7886
"73167176531330624919225119674426574742355349194934");
@@ -86,6 +94,7 @@ public void testCorrectlyCalculatesLargestProductInLongStringToSearchV1() {
8694

8795
@Disabled("Remove to run test")
8896
@Test
97+
@DisplayName("reports zero if the only digits are zero")
8998
public void testCorrectlyCalculatesLargestProductOfZeroIfAllDigitsAreZeroes() {
9099
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0000");
91100
long expectedProduct = 0;
@@ -97,6 +106,7 @@ public void testCorrectlyCalculatesLargestProductOfZeroIfAllDigitsAreZeroes() {
97106

98107
@Disabled("Remove to run test")
99108
@Test
109+
@DisplayName("reports zero if all spans include zero")
100110
public void testCorrectlyCalculatesLargestProductOfZeroIfAllSeriesOfGivenLengthContainZero() {
101111
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("99099");
102112
long expectedProduct = 0;
@@ -108,6 +118,7 @@ public void testCorrectlyCalculatesLargestProductOfZeroIfAllSeriesOfGivenLengthC
108118

109119
@Disabled("Remove to run test")
110120
@Test
121+
@DisplayName("rejects span longer than string length")
111122
public void testSeriesLengthLongerThanLengthOfStringToTestIsRejected() {
112123
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("123");
113124

@@ -118,6 +129,7 @@ public void testSeriesLengthLongerThanLengthOfStringToTestIsRejected() {
118129

119130
@Disabled("Remove to run test")
120131
@Test
132+
@DisplayName("reports 1 for empty string and empty product (0 span)")
121133
public void testEmptyStringToSearchAndSeriesOfNonZeroLengthIsRejected() {
122134
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("");
123135

@@ -128,6 +140,7 @@ public void testEmptyStringToSearchAndSeriesOfNonZeroLengthIsRejected() {
128140

129141
@Disabled("Remove to run test")
130142
@Test
143+
@DisplayName("rejects invalid character in digits")
131144
public void testStringToSearchContainingNonDigitCharacterIsRejected() {
132145
assertThatExceptionOfType(IllegalArgumentException.class)
133146
.isThrownBy(() -> new LargestSeriesProductCalculator("1234a5"))
@@ -136,6 +149,7 @@ public void testStringToSearchContainingNonDigitCharacterIsRejected() {
136149

137150
@Disabled("Remove to run test")
138151
@Test
152+
@DisplayName("rejects negative span")
139153
public void testNegativeSeriesLengthIsRejected() {
140154
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("12345");
141155

@@ -146,6 +160,7 @@ public void testNegativeSeriesLengthIsRejected() {
146160

147161
@Disabled("Remove to run test")
148162
@Test
163+
@DisplayName("integer overflow")
149164
public void testForIntegerOverflow() {
150165
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("9999999999");
151166
long expectedProduct = 3486784401L;

exercises/practice/leap/src/test/java/LeapTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.junit.jupiter.api.BeforeEach;
22
import org.junit.jupiter.api.Disabled;
3+
import org.junit.jupiter.api.DisplayName;
34
import org.junit.jupiter.api.Test;
45

56
import static org.assertj.core.api.Assertions.assertThat;
@@ -14,54 +15,63 @@ public void setup() {
1415
}
1516

1617
@Test
18+
@DisplayName("year not divisible by 4 in common year")
1719
public void testYearNotDivBy4InCommonYear() {
1820
assertThat(leap.isLeapYear(2015)).isFalse();
1921
}
2022

2123
@Disabled("Remove to run test")
2224
@Test
25+
@DisplayName("year divisible by 2, not divisible by 4 in common year\"")
2326
public void testYearDivBy2NotDivBy4InCommonYear() {
2427
assertThat(leap.isLeapYear(1970)).isFalse();
2528
}
2629

2730
@Disabled("Remove to run test")
2831
@Test
32+
@DisplayName("year divisible by 4, not divisible by 100 in leap year")
2933
public void testYearDivBy4NotDivBy100InLeapYear() {
3034
assertThat(leap.isLeapYear(1996)).isTrue();
3135
}
3236

3337
@Disabled("Remove to run test")
3438
@Test
39+
@DisplayName("year divisible by 4 and 5 is still a leap year")
3540
public void testYearDivBy4And5InLeapYear() {
3641
assertThat(leap.isLeapYear(1960)).isTrue();
3742
}
3843

3944
@Disabled("Remove to run test")
4045
@Test
46+
@DisplayName("year divisible by 100, not divisible by 400 in common year")
4147
public void testYearDivBy100NotDivBy400InCommonYear() {
4248
assertThat(leap.isLeapYear(2100)).isFalse();
4349
}
4450

4551
@Disabled("Remove to run test")
4652
@Test
53+
@DisplayName("year divisible by 100 but not by 3 is still not a leap year")
4754
public void testYearDivBy100NotDivBy3IsNotLeapYear() {
4855
assertThat(leap.isLeapYear(1900)).isFalse();
4956
}
5057

5158
@Disabled("Remove to run test")
5259
@Test
60+
@DisplayName("year divisible by 400 is leap year")
5361
public void testYearDivBy400InLeapYear() {
5462
assertThat(leap.isLeapYear(2000)).isTrue();
5563
}
5664

5765
@Disabled("Remove to run test")
5866
@Test
67+
@DisplayName("year divisible by 400 but not by 125 is still a leap year")
5968
public void testYearDivBy400NotDivBy125IsLeapYear() {
6069
assertThat(leap.isLeapYear(2400)).isTrue();
6170
}
6271

6372
@Disabled("Remove to run test")
6473
@Test
74+
@DisplayName("year divisible by 200, not divisible by 400 in common year")
6575
public void testYearDivBy200NotDivBy400InCommonYear() {
6676
assertThat(leap.isLeapYear(1800)).isFalse();
6777
}

0 commit comments

Comments
 (0)