Skip to content

Commit fb70422

Browse files
gigasecond, go-counting, grade-school, grains, grep (#3004)
Co-authored-by: Jagdish Prajapati <[email protected]> [no important files changed]
1 parent 766c84e commit fb70422

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

exercises/practice/gigasecond/src/test/java/GigasecondTest.java

Lines changed: 7 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.time.LocalDate;
@@ -10,6 +11,7 @@
1011
public class GigasecondTest {
1112

1213
@Test
14+
@DisplayName("date only specification of time")
1315
public void modernTime() {
1416
Gigasecond gigaSecond = new Gigasecond(LocalDate.of(2011, Month.APRIL, 25));
1517

@@ -18,6 +20,7 @@ public void modernTime() {
1820

1921
@Disabled("Remove to run test")
2022
@Test
23+
@DisplayName("second test for date only specification of time")
2124
public void afterEpochTime() {
2225
Gigasecond gigaSecond = new Gigasecond(LocalDate.of(1977, Month.JUNE, 13));
2326

@@ -26,6 +29,7 @@ public void afterEpochTime() {
2629

2730
@Disabled("Remove to run test")
2831
@Test
32+
@DisplayName("third test for date only specification of time")
2933
public void beforeEpochTime() {
3034
Gigasecond gigaSecond = new Gigasecond(LocalDate.of(1959, Month.JULY, 19));
3135

@@ -34,6 +38,7 @@ public void beforeEpochTime() {
3438

3539
@Disabled("Remove to run test")
3640
@Test
41+
@DisplayName("full time specified")
3742
public void withFullTimeSpecified() {
3843
Gigasecond gigaSecond = new Gigasecond(LocalDateTime.of(2015, Month.JANUARY, 24, 22, 0, 0));
3944

@@ -42,6 +47,7 @@ public void withFullTimeSpecified() {
4247

4348
@Disabled("Remove to run test")
4449
@Test
50+
@DisplayName("full time with day roll-over")
4551
public void withFullTimeSpecifiedAndDayRollover() {
4652
Gigasecond gigaSecond = new Gigasecond(LocalDateTime.of(2015, Month.JANUARY, 24, 23, 59, 59));
4753

@@ -50,6 +56,7 @@ public void withFullTimeSpecifiedAndDayRollover() {
5056

5157
@Disabled("Remove to run test")
5258
@Test
59+
@DisplayName("does not mutate the input")
5360
public void doesNotMutateInput() {
5461
LocalDateTime input = LocalDateTime.of(2015, Month.JANUARY, 24, 23, 59, 59);
5562
new Gigasecond(input).getDateTime();

exercises/practice/go-counting/src/test/java/GoCountingTest.java

Lines changed: 12 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.awt.*;
@@ -18,6 +19,7 @@ public class GoCountingTest {
1819
" W ";
1920

2021
@Test
22+
@DisplayName("Black corner territory on 5x5 board")
2123
public void blackCorner5x5BoardTest() {
2224
GoCounting gocounting = new GoCounting(board5x5);
2325

@@ -32,6 +34,7 @@ public void blackCorner5x5BoardTest() {
3234

3335
@Disabled("Remove to run test")
3436
@Test
37+
@DisplayName("White center territory on 5x5 board")
3538
public void whiteCenter5x5BoardTest() {
3639
GoCounting gocounting = new GoCounting(board5x5);
3740

@@ -44,6 +47,7 @@ public void whiteCenter5x5BoardTest() {
4447

4548
@Disabled("Remove to run test")
4649
@Test
50+
@DisplayName("Open corner territory on 5x5 board")
4751
public void openCorner5x5BoardTest() {
4852
GoCounting gocounting = new GoCounting(board5x5);
4953

@@ -58,6 +62,7 @@ public void openCorner5x5BoardTest() {
5862

5963
@Disabled("Remove to run test")
6064
@Test
65+
@DisplayName("A stone and not a territory on 5x5 board")
6166
public void stoneNotTerritory5x5Board() {
6267
GoCounting gocounting = new GoCounting(board5x5);
6368

@@ -69,6 +74,7 @@ public void stoneNotTerritory5x5Board() {
6974

7075
@Disabled("Remove to run test")
7176
@Test
77+
@DisplayName("Invalid because X is too low for 5x5 board")
7278
public void invalidXTooLow5x5Board() {
7379
GoCounting gocounting = new GoCounting(board5x5);
7480

@@ -79,6 +85,7 @@ public void invalidXTooLow5x5Board() {
7985

8086
@Disabled("Remove to run test")
8187
@Test
88+
@DisplayName("Invalid because X is too high for 5x5 board")
8289
public void invalidXTooHigh5x5Board() {
8390
GoCounting gocounting = new GoCounting(board5x5);
8491

@@ -89,6 +96,7 @@ public void invalidXTooHigh5x5Board() {
8996

9097
@Disabled("Remove to run test")
9198
@Test
99+
@DisplayName("Invalid because Y is too low for 5x5 board")
92100
public void invalidYTooLow5x5Board() {
93101
GoCounting gocounting = new GoCounting(board5x5);
94102

@@ -99,6 +107,7 @@ public void invalidYTooLow5x5Board() {
99107

100108
@Disabled("Remove to run test")
101109
@Test
110+
@DisplayName("Invalid because Y is too high for 5x5 board")
102111
public void invalidYTooHigh5x5Board() {
103112
GoCounting gocounting = new GoCounting(board5x5);
104113

@@ -109,6 +118,7 @@ public void invalidYTooHigh5x5Board() {
109118

110119
@Disabled("Remove to run test")
111120
@Test
121+
@DisplayName("One territory is the whole board")
112122
public void oneTerritoryIsWholeBoardTest() {
113123
GoCounting gocounting = new GoCounting(" ");
114124

@@ -127,6 +137,7 @@ public void oneTerritoryIsWholeBoardTest() {
127137

128138
@Disabled("Remove to run test")
129139
@Test
140+
@DisplayName("Two territory rectangular board")
130141
public void twoTerritoryRectangularBoardTest() {
131142
GoCounting gocounting = new GoCounting(" BW \n BW ");
132143

@@ -150,6 +161,7 @@ public void twoTerritoryRectangularBoardTest() {
150161

151162
@Disabled("Remove to run test")
152163
@Test
164+
@DisplayName("Two region rectangular board")
153165
public void twoRegionRectangularBoardTest() {
154166
GoCounting gocounting = new GoCounting(" B ");
155167

exercises/practice/grade-school/src/test/java/SchoolTest.java

Lines changed: 20 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;
@@ -13,18 +14,21 @@ public void setUp() {
1314
}
1415

1516
@Test
17+
@DisplayName("Roster is empty when no student is added")
1618
public void rosterReturnsAnEmptyListIfThereAreNoStudentsEnrolled() {
1719
assertThat(school.roster()).isEmpty();
1820
}
1921

2022
@Disabled("Remove to run test")
2123
@Test
24+
@DisplayName("Add a student")
2225
public void addAStudent() {
2326
assertThat(school.add("Aimee", 2)).isTrue();
2427
}
2528

2629
@Disabled("Remove to run test")
2730
@Test
31+
@DisplayName("Student is added to the roster")
2832
public void addingAStudentAddsThemToTheSortedRoster() {
2933
school.add("Aimee", 2);
3034

@@ -33,6 +37,7 @@ public void addingAStudentAddsThemToTheSortedRoster() {
3337

3438
@Disabled("Remove to run test")
3539
@Test
40+
@DisplayName("Adding multiple students in the same grade in the roster")
3641
public void addingMultipleStudentsInTheSameGrade() {
3742
assertThat(school.add("Blair", 2)).isTrue();
3843
assertThat(school.add("James", 2)).isTrue();
@@ -41,6 +46,7 @@ public void addingMultipleStudentsInTheSameGrade() {
4146

4247
@Disabled("Remove to run test")
4348
@Test
49+
@DisplayName("Multiple students in the same grade are added to the roster")
4450
public void addingMoreStudentsAddsThemToTheSameSortedRoster() {
4551
school.add("Blair", 2);
4652
school.add("James", 2);
@@ -51,6 +57,7 @@ public void addingMoreStudentsAddsThemToTheSameSortedRoster() {
5157

5258
@Disabled("Remove to run test")
5359
@Test
60+
@DisplayName("Cannot add student to same grade in the roster more than once")
5461
public void cannotAddStudentsToSameGradeInTheRosterMoreThanOnce() {
5562
assertThat(school.add("Blair", 2)).isTrue();
5663
assertThat(school.add("James", 2)).isTrue();
@@ -60,6 +67,7 @@ public void cannotAddStudentsToSameGradeInTheRosterMoreThanOnce() {
6067

6168
@Disabled("Remove to run test")
6269
@Test
70+
@DisplayName("Student not added to same grade in the roster more than once")
6371
public void studentNotAddedToSameGradeInTheRosterMoreThanOnce() {
6472
school.add("Blair", 2);
6573
school.add("James", 2);
@@ -71,13 +79,15 @@ public void studentNotAddedToSameGradeInTheRosterMoreThanOnce() {
7179

7280
@Disabled("Remove to run test")
7381
@Test
82+
@DisplayName("Adding students in multiple grades")
7483
public void addingStudentsInMultipleGrades() {
7584
assertThat(school.add("Chelsea", 3)).isTrue();
7685
assertThat(school.add("Logan", 7)).isTrue();
7786
}
7887

7988
@Disabled("Remove to run test")
8089
@Test
90+
@DisplayName("Students in multiple grades are added to the roster")
8191
public void addingStudentsToDifferentGradesAddsThemToTheSameSortedRoster() {
8292
school.add("Chelsea", 3);
8393
school.add("Logan", 7);
@@ -87,6 +97,7 @@ public void addingStudentsToDifferentGradesAddsThemToTheSameSortedRoster() {
8797

8898
@Disabled("Remove to run test")
8999
@Test
100+
@DisplayName("Cannot add same student to multiple grades in the roster")
90101
public void cannotAddSameStudentToMultipleGradesInTheRoster() {
91102
assertThat(school.add("Blair", 2)).isTrue();
92103
assertThat(school.add("James", 2)).isTrue();
@@ -96,6 +107,7 @@ public void cannotAddSameStudentToMultipleGradesInTheRoster() {
96107

97108
@Disabled("Remove to run test")
98109
@Test
110+
@DisplayName("Student not added to multiple grades in the roster")
99111
public void studentNotAddedToMultipleGradesInTheRoster() {
100112
school.add("Blair", 2);
101113
school.add("James", 2);
@@ -107,6 +119,7 @@ public void studentNotAddedToMultipleGradesInTheRoster() {
107119

108120
@Disabled("Remove to run test")
109121
@Test
122+
@DisplayName("Students are sorted by grades in the roster")
110123
public void studentsAreSortedByGradeInTheRoster() {
111124
school.add("Jim", 3);
112125
school.add("Peter", 2);
@@ -117,6 +130,7 @@ public void studentsAreSortedByGradeInTheRoster() {
117130

118131
@Disabled("Remove to run test")
119132
@Test
133+
@DisplayName("Students are sorted by name in the roster")
120134
public void studentsAreSortedByNameInTheRoster() {
121135
school.add("Peter", 2);
122136
school.add("Zoe", 2);
@@ -127,6 +141,7 @@ public void studentsAreSortedByNameInTheRoster() {
127141

128142
@Disabled("Remove to run test")
129143
@Test
144+
@DisplayName("Students are sorted by grades and then by name in the roster")
130145
public void studentsAreSortedByGradeAndThenByNameInTheRoster() {
131146
school.add("Peter", 2);
132147
school.add("Anna", 1);
@@ -141,12 +156,14 @@ public void studentsAreSortedByGradeAndThenByNameInTheRoster() {
141156

142157
@Disabled("Remove to run test")
143158
@Test
159+
@DisplayName("Grade is empty if no students in the roster")
144160
public void gradeIsEmptyIfNoStudentsInTheRoster() {
145161
assertThat(school.grade(1)).isEmpty();
146162
}
147163

148164
@Disabled("Remove to run test")
149165
@Test
166+
@DisplayName("Grade is empty if no students in that grade")
150167
public void gradeIsEmptyIfNoStudentsInThatGrade() {
151168
school.add("Peter", 2);
152169
school.add("Zoe", 2);
@@ -158,6 +175,7 @@ public void gradeIsEmptyIfNoStudentsInThatGrade() {
158175

159176
@Disabled("Remove to run test")
160177
@Test
178+
@DisplayName("Student not added to same grade more than once")
161179
public void studentNotAddedToTheSameGradeMoreThanOnce() {
162180
school.add("Blair", 2);
163181
school.add("James", 2);
@@ -169,6 +187,7 @@ public void studentNotAddedToTheSameGradeMoreThanOnce() {
169187

170188
@Disabled("Remove to run test")
171189
@Test
190+
@DisplayName("Student not added to multiple grades")
172191
public void studentNotAddedToMultipleGrades() {
173192
school.add("Blair", 2);
174193
school.add("James", 2);
@@ -181,6 +200,7 @@ public void studentNotAddedToMultipleGrades() {
181200

182201
@Disabled("Remove to run test")
183202
@Test
203+
@DisplayName("Students are sorted by name in a grade")
184204
public void studentsAreSortedByNameInAGrade() {
185205
school.add("Franklin", 5);
186206
school.add("Bradley", 5);

exercises/practice/grains/src/test/java/GrainsTest.java

Lines changed: 12 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.math.BigInteger;
@@ -11,55 +12,63 @@ public class GrainsTest {
1112
private Grains grains = new Grains();
1213

1314
@Test
15+
@DisplayName("returns the number of grains on the square")
1416
public void countAtSquare1() {
1517
BigInteger result = grains.grainsOnSquare(1);
1618
assertThat(result).isEqualTo(new BigInteger("1"));
1719
}
1820

1921
@Disabled("Remove to run test")
2022
@Test
23+
@DisplayName("grains on square 2")
2124
public void countAtSquare2() {
2225
BigInteger result = grains.grainsOnSquare(2);
2326
assertThat(result).isEqualTo(new BigInteger("2"));
2427
}
2528

2629
@Disabled("Remove to run test")
2730
@Test
31+
@DisplayName("grains on square 3")
2832
public void countAtSquare3() {
2933
BigInteger result = grains.grainsOnSquare(3);
3034
assertThat(result).isEqualTo(new BigInteger("4"));
3135
}
3236

3337
@Disabled("Remove to run test")
3438
@Test
39+
@DisplayName("grains on square 4")
3540
public void countAtSquare4() {
3641
BigInteger result = grains.grainsOnSquare(4);
3742
assertThat(result).isEqualTo(new BigInteger("8"));
3843
}
3944

4045
@Disabled("Remove to run test")
4146
@Test
47+
@DisplayName("grains on square 16")
4248
public void countAtSquare16() {
4349
BigInteger result = grains.grainsOnSquare(16);
4450
assertThat(result).isEqualTo(new BigInteger("32768"));
4551
}
4652

4753
@Disabled("Remove to run test")
4854
@Test
55+
@DisplayName("grains on square 32")
4956
public void countAtSquare32() {
5057
BigInteger result = grains.grainsOnSquare(32);
5158
assertThat(result).isEqualTo(new BigInteger("2147483648"));
5259
}
5360

5461
@Disabled("Remove to run test")
5562
@Test
63+
@DisplayName("grains on square 64")
5664
public void countAtSquare64() {
5765
BigInteger result = grains.grainsOnSquare(64);
5866
assertThat(result).isEqualTo(new BigInteger("9223372036854775808"));
5967
}
6068

6169
@Disabled("Remove to run test")
6270
@Test
71+
@DisplayName("square 0 is invalid")
6372
public void errorOnNullBoardSize() {
6473
assertThatExceptionOfType(IllegalArgumentException.class)
6574
.isThrownBy(() -> grains.grainsOnSquare(0))
@@ -68,6 +77,7 @@ public void errorOnNullBoardSize() {
6877

6978
@Disabled("Remove to run test")
7079
@Test
80+
@DisplayName("negative square is invalid")
7181
public void errorOnNegativeBoardSize() {
7282
assertThatExceptionOfType(IllegalArgumentException.class)
7383
.isThrownBy(() -> grains.grainsOnSquare(-1))
@@ -76,6 +86,7 @@ public void errorOnNegativeBoardSize() {
7686

7787
@Disabled("Remove to run test")
7888
@Test
89+
@DisplayName("square greater than 64 is invalid")
7990
public void errorOnExcessiveBoardSize() {
8091
assertThatExceptionOfType(IllegalArgumentException.class)
8192
.isThrownBy(() -> grains.grainsOnSquare(65))
@@ -84,6 +95,7 @@ public void errorOnExcessiveBoardSize() {
8495

8596
@Disabled("Remove to run test")
8697
@Test
98+
@DisplayName("returns the total number of grains on the board")
8799
public void totalNumberOfGrainsOnABoard() {
88100
BigInteger total = grains.grainsOnBoard();
89101
assertThat(total).isEqualTo(new BigInteger("18446744073709551615"));

0 commit comments

Comments
 (0)