Skip to content

Commit 0246421

Browse files
complex-numbers, connect, crypto-square (#2996)
Co-authored-by: Jagdish Prajapati <[email protected]> [no important files changed]
1 parent 5ecbd3b commit 0246421

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

exercises/practice/complex-numbers/src/test/java/ComplexNumberTest.java

Lines changed: 32 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;
@@ -24,6 +25,7 @@ private void assertComplexNumbersEqual(ComplexNumber c1, ComplexNumber c2) {
2425
// Tests
2526

2627
@Test
28+
@DisplayName("Real part of a purely real number")
2729
public void testRealPartOfPurelyRealNumber() {
2830
double expected = 1.0;
2931
double actual = new ComplexNumber(1.0, 0).getReal();
@@ -32,6 +34,7 @@ public void testRealPartOfPurelyRealNumber() {
3234

3335
@Disabled("Remove to run test")
3436
@Test
37+
@DisplayName("Real part of a purely imaginary number")
3538
public void testRealPartOfPurelyImaginaryNumber() {
3639
double expected = 0.0;
3740
double actual = new ComplexNumber(0, 1.0).getReal();
@@ -40,6 +43,7 @@ public void testRealPartOfPurelyImaginaryNumber() {
4043

4144
@Disabled("Remove to run test")
4245
@Test
46+
@DisplayName("Real part of a number with real and imaginary part")
4347
public void testRealPartOfNumberWithRealAndImaginaryParts() {
4448
double expected = 1.0;
4549
double actual = new ComplexNumber(1.0, 2.0).getReal();
@@ -48,6 +52,7 @@ public void testRealPartOfNumberWithRealAndImaginaryParts() {
4852

4953
@Disabled("Remove to run test")
5054
@Test
55+
@DisplayName("Imaginary part of a purely real number")
5156
public void testImaginaryPartOfPurelyRealNumber() {
5257
double expected = 0.0;
5358
double actual = new ComplexNumber(1.0, 0).getImaginary();
@@ -56,6 +61,7 @@ public void testImaginaryPartOfPurelyRealNumber() {
5661

5762
@Disabled("Remove to run test")
5863
@Test
64+
@DisplayName("Imaginary part of a purely imaginary number")
5965
public void testImaginaryPartOfPurelyImaginaryNumber() {
6066
double expected = 1.0;
6167
double actual = new ComplexNumber(0, 1.0).getImaginary();
@@ -64,6 +70,7 @@ public void testImaginaryPartOfPurelyImaginaryNumber() {
6470

6571
@Disabled("Remove to run test")
6672
@Test
73+
@DisplayName("Imaginary part of a number with real and imaginary part")
6774
public void testImaginaryPartOfNumberWithRealAndImaginaryParts() {
6875
double expected = 2.0;
6976
double actual = new ComplexNumber(1.0, 2.0).getImaginary();
@@ -72,6 +79,7 @@ public void testImaginaryPartOfNumberWithRealAndImaginaryParts() {
7279

7380
@Disabled("Remove to run test")
7481
@Test
82+
@DisplayName("Imaginary unit")
7583
public void testImaginaryUnitExhibitsDefiningProperty() {
7684
ComplexNumber expected = new ComplexNumber(-1.0, 0);
7785
ComplexNumber actual = new ComplexNumber(0, 1.0).multiply(new ComplexNumber(0, 1.0));
@@ -80,6 +88,7 @@ public void testImaginaryUnitExhibitsDefiningProperty() {
8088

8189
@Disabled("Remove to run test")
8290
@Test
91+
@DisplayName("Add purely real numbers")
8392
public void testAdditionWithPurelyRealNumbers() {
8493
ComplexNumber expected = new ComplexNumber(3.0, 0);
8594
ComplexNumber actual = new ComplexNumber(1.0, 0).add(new ComplexNumber(2.0, 0));
@@ -88,6 +97,7 @@ public void testAdditionWithPurelyRealNumbers() {
8897

8998
@Disabled("Remove to run test")
9099
@Test
100+
@DisplayName("Add purely imaginary numbers")
91101
public void testAdditionWithPurelyImaginaryNumbers() {
92102
ComplexNumber expected = new ComplexNumber(0, 3.0);
93103
ComplexNumber actual = new ComplexNumber(0, 1.0).add(new ComplexNumber(0, 2.0));
@@ -96,6 +106,7 @@ public void testAdditionWithPurelyImaginaryNumbers() {
96106

97107
@Disabled("Remove to run test")
98108
@Test
109+
@DisplayName("Add numbers with real and imaginary part")
99110
public void testAdditionWithRealAndImaginaryParts() {
100111
ComplexNumber expected = new ComplexNumber(4.0, 6.0);
101112
ComplexNumber actual = new ComplexNumber(1.0, 2.0).add(new ComplexNumber(3.0, 4.0));
@@ -104,6 +115,7 @@ public void testAdditionWithRealAndImaginaryParts() {
104115

105116
@Disabled("Remove to run test")
106117
@Test
118+
@DisplayName("Subtract purely real numbers")
107119
public void testSubtractionWithPurelyRealNumbers() {
108120
ComplexNumber expected = new ComplexNumber(-1.0, 0.0);
109121
ComplexNumber actual = new ComplexNumber(1.0, 0.0).subtract(new ComplexNumber(2.0, 0.0));
@@ -112,6 +124,7 @@ public void testSubtractionWithPurelyRealNumbers() {
112124

113125
@Disabled("Remove to run test")
114126
@Test
127+
@DisplayName("Subtract purely imaginary numbers")
115128
public void testSubtractionWithPurelyImaginaryNumbers() {
116129
ComplexNumber expected = new ComplexNumber(0, -1.0);
117130
ComplexNumber actual = new ComplexNumber(0, 1.0).subtract(new ComplexNumber(0, 2.0));
@@ -120,6 +133,7 @@ public void testSubtractionWithPurelyImaginaryNumbers() {
120133

121134
@Disabled("Remove to run test")
122135
@Test
136+
@DisplayName("Subtract numbers with real and imaginary part")
123137
public void testSubtractionWithRealAndImaginaryParts() {
124138
ComplexNumber expected = new ComplexNumber(-2.0, -2.0);
125139
ComplexNumber actual = new ComplexNumber(1.0, 2.0).subtract(new ComplexNumber(3.0, 4.0));
@@ -128,6 +142,7 @@ public void testSubtractionWithRealAndImaginaryParts() {
128142

129143
@Disabled("Remove to run test")
130144
@Test
145+
@DisplayName("Multiply purely real numbers")
131146
public void testMultiplicationWithPurelyRealNumbers() {
132147
ComplexNumber expected = new ComplexNumber(2.0, 0);
133148
ComplexNumber actual = new ComplexNumber(1.0, 0).multiply(new ComplexNumber(2.0, 0));
@@ -136,6 +151,7 @@ public void testMultiplicationWithPurelyRealNumbers() {
136151

137152
@Disabled("Remove to run test")
138153
@Test
154+
@DisplayName("Multiply purely imaginary numbers")
139155
public void testMultiplicationWithPurelyImaginaryNumbers() {
140156
ComplexNumber expected = new ComplexNumber(-2.0, 0);
141157
ComplexNumber actual = new ComplexNumber(0, 1.0).multiply(new ComplexNumber(0, 2.0));
@@ -144,6 +160,7 @@ public void testMultiplicationWithPurelyImaginaryNumbers() {
144160

145161
@Disabled("Remove to run test")
146162
@Test
163+
@DisplayName("Multiply numbers with real and imaginary part")
147164
public void testMultiplicationWithRealAndImaginaryParts() {
148165
ComplexNumber expected = new ComplexNumber(-5.0, 10.0);
149166
ComplexNumber actual = new ComplexNumber(1.0, 2.0).multiply(new ComplexNumber(3.0, 4.0));
@@ -152,6 +169,7 @@ public void testMultiplicationWithRealAndImaginaryParts() {
152169

153170
@Disabled("Remove to run test")
154171
@Test
172+
@DisplayName("Divide purely real numbers")
155173
public void testDivisionWithPurelyRealNumbers() {
156174
ComplexNumber expected = new ComplexNumber(0.5, 0);
157175
ComplexNumber actual = new ComplexNumber(1.0, 0).divide(new ComplexNumber(2.0, 0));
@@ -160,6 +178,7 @@ public void testDivisionWithPurelyRealNumbers() {
160178

161179
@Disabled("Remove to run test")
162180
@Test
181+
@DisplayName("Divide purely imaginary numbers")
163182
public void testDivisionWithPurelyImaginaryNumbers() {
164183
ComplexNumber expected = new ComplexNumber(0.5, 0);
165184
ComplexNumber actual = new ComplexNumber(0, 1.0).divide(new ComplexNumber(0, 2.0));
@@ -168,6 +187,7 @@ public void testDivisionWithPurelyImaginaryNumbers() {
168187

169188
@Disabled("Remove to run test")
170189
@Test
190+
@DisplayName("Divide numbers with real and imaginary part")
171191
public void testDivisionWithRealAndImaginaryParts() {
172192
ComplexNumber expected = new ComplexNumber(0.44, 0.08);
173193
ComplexNumber actual = new ComplexNumber(1.0, 2.0).divide(new ComplexNumber(3.0, 4.0));
@@ -176,6 +196,7 @@ public void testDivisionWithRealAndImaginaryParts() {
176196

177197
@Disabled("Remove to run test")
178198
@Test
199+
@DisplayName("Absolute value of a positive purely real number")
179200
public void testAbsoluteValueOfPositivePurelyRealNumber() {
180201
double expected = 5.0;
181202
double actual = new ComplexNumber(5.0, 0).abs();
@@ -184,6 +205,7 @@ public void testAbsoluteValueOfPositivePurelyRealNumber() {
184205

185206
@Disabled("Remove to run test")
186207
@Test
208+
@DisplayName("Absolute value of a negative purely real number")
187209
public void testAbsoluteValueOfNegativePurelyRealNumber() {
188210
double expected = 5.0;
189211
double actual = new ComplexNumber(-5.0, 0).abs();
@@ -192,6 +214,7 @@ public void testAbsoluteValueOfNegativePurelyRealNumber() {
192214

193215
@Disabled("Remove to run test")
194216
@Test
217+
@DisplayName("Absolute value of a purely imaginary number with positive imaginary part")
195218
public void testAbsoluteValueOfPurelyImaginaryNumberWithPositiveImaginaryPart() {
196219
double expected = 5.0;
197220
double actual = new ComplexNumber(0, 5.0).abs();
@@ -200,6 +223,7 @@ public void testAbsoluteValueOfPurelyImaginaryNumberWithPositiveImaginaryPart()
200223

201224
@Disabled("Remove to run test")
202225
@Test
226+
@DisplayName("Absolute value of a purely imaginary number with negative imaginary part")
203227
public void testAbsoluteValueOfPurelyImaginaryNumberWithNegativeImaginaryPart() {
204228
double expected = 5.0;
205229
double actual = new ComplexNumber(0, -5.0).abs();
@@ -208,6 +232,7 @@ public void testAbsoluteValueOfPurelyImaginaryNumberWithNegativeImaginaryPart()
208232

209233
@Disabled("Remove to run test")
210234
@Test
235+
@DisplayName("Absolute value of a number with real and imaginary part")
211236
public void testAbsoluteValueOfNumberWithRealAndImaginaryParts() {
212237
double expected = 5.0;
213238
double actual = new ComplexNumber(3.0, 4.0).abs();
@@ -216,6 +241,7 @@ public void testAbsoluteValueOfNumberWithRealAndImaginaryParts() {
216241

217242
@Disabled("Remove to run test")
218243
@Test
244+
@DisplayName("Conjugate a purely real number")
219245
public void testConjugationOfPurelyRealNumber() {
220246
ComplexNumber expected = new ComplexNumber(5.0, 0);
221247
ComplexNumber actual = new ComplexNumber(5.0, 0).conjugate();
@@ -224,6 +250,7 @@ public void testConjugationOfPurelyRealNumber() {
224250

225251
@Disabled("Remove to run test")
226252
@Test
253+
@DisplayName("Conjugate a purely imaginary number")
227254
public void testConjugationOfPurelyImaginaryNumber() {
228255
ComplexNumber expected = new ComplexNumber(0, -5.0);
229256
ComplexNumber actual = new ComplexNumber(0, 5.0).conjugate();
@@ -232,6 +259,7 @@ public void testConjugationOfPurelyImaginaryNumber() {
232259

233260
@Disabled("Remove to run test")
234261
@Test
262+
@DisplayName("Conjugate a number with real and imaginary part")
235263
public void testConjugationOfNumberWithRealAndImaginaryParts() {
236264
ComplexNumber expected = new ComplexNumber(1.0, -1.0);
237265
ComplexNumber actual = new ComplexNumber(1.0, 1.0).conjugate();
@@ -240,6 +268,7 @@ public void testConjugationOfNumberWithRealAndImaginaryParts() {
240268

241269
@Disabled("Remove to run test")
242270
@Test
271+
@DisplayName("Euler's identity/formula")
243272
public void testExponentialOfPurelyImaginaryNumber() {
244273
ComplexNumber expected = new ComplexNumber(-1.0, 0);
245274
ComplexNumber actual = new ComplexNumber(0, Math.PI).exponentialOf();
@@ -248,6 +277,7 @@ public void testExponentialOfPurelyImaginaryNumber() {
248277

249278
@Disabled("Remove to run test")
250279
@Test
280+
@DisplayName("Exponential of 0")
251281
public void testExponentialOfZero() {
252282
ComplexNumber expected = new ComplexNumber(1.0, 0);
253283
ComplexNumber actual = new ComplexNumber(0, 0).exponentialOf();
@@ -256,6 +286,7 @@ public void testExponentialOfZero() {
256286

257287
@Disabled("Remove to run test")
258288
@Test
289+
@DisplayName("Exponential of a purely real number")
259290
public void testExponentialOfPurelyRealNumber() {
260291
ComplexNumber expected = new ComplexNumber(Math.E, 0);
261292
ComplexNumber actual = new ComplexNumber(1.0, 0).exponentialOf();
@@ -264,6 +295,7 @@ public void testExponentialOfPurelyRealNumber() {
264295

265296
@Disabled("Remove to run test")
266297
@Test
298+
@DisplayName("Exponential resulting in a number with real and imaginary part")
267299
public void testExponentialOfNumberWithRealAndImaginaryParts() {
268300
ComplexNumber expected = new ComplexNumber(1, 1);
269301
ComplexNumber actual = new ComplexNumber(Math.log(2.0) / 2, Math.PI / 4).exponentialOf();

exercises/practice/connect/src/test/java/ConnectTest.java

Lines changed: 11 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 ConnectTest {
78

89
@Test
10+
@DisplayName("an empty board has no winner")
911
public void anEmptyBoardHasNoWinner() {
1012

1113
//GIVEN
@@ -27,6 +29,7 @@ public void anEmptyBoardHasNoWinner() {
2729

2830
@Disabled("Remove to run test")
2931
@Test
32+
@DisplayName("X can win on a 1x1 board")
3033
public void xCanWinOnA1x1Board() {
3134

3235
//GIVEN
@@ -45,6 +48,7 @@ public void xCanWinOnA1x1Board() {
4548

4649
@Disabled("Remove to run test")
4750
@Test
51+
@DisplayName("O can win on a 1x1 board")
4852
public void oCanWinOnA1x1Board() {
4953

5054
//GIVEN
@@ -63,6 +67,7 @@ public void oCanWinOnA1x1Board() {
6367

6468
@Disabled("Remove to run test")
6569
@Test
70+
@DisplayName("only edges does not make a winner")
6671
public void onlyEdgesDoesNotMakeAWinner() {
6772

6873
//GIVEN
@@ -84,6 +89,7 @@ public void onlyEdgesDoesNotMakeAWinner() {
8489

8590
@Disabled("Remove to run test")
8691
@Test
92+
@DisplayName("illegal diagonal does not make a winner")
8793
public void illegalDiagonalDoesNotMakeAWinner() {
8894

8995
//GIVEN
@@ -106,6 +112,7 @@ public void illegalDiagonalDoesNotMakeAWinner() {
106112

107113
@Disabled("Remove to run test")
108114
@Test
115+
@DisplayName("nobody wins crossing adjacent angles")
109116
public void nobodyWinsCrossingAdjacentAngles() {
110117

111118
//GIVEN
@@ -128,6 +135,7 @@ public void nobodyWinsCrossingAdjacentAngles() {
128135

129136
@Disabled("Remove to run test")
130137
@Test
138+
@DisplayName("X wins crossing from left to right")
131139
public void xWinsCrossingFromLeftToRight() {
132140

133141
//GIVEN
@@ -150,6 +158,7 @@ public void xWinsCrossingFromLeftToRight() {
150158

151159
@Disabled("Remove to run test")
152160
@Test
161+
@DisplayName("O wins crossing from top to bottom")
153162
public void oWinsCrossingFromTopToBottom() {
154163

155164
//GIVEN
@@ -172,6 +181,7 @@ public void oWinsCrossingFromTopToBottom() {
172181

173182
@Disabled("Remove to run test")
174183
@Test
184+
@DisplayName("X wins using a convoluted path")
175185
public void xWinsUsingConvolutedPath() {
176186

177187
//GIVEN
@@ -194,6 +204,7 @@ public void xWinsUsingConvolutedPath() {
194204

195205
@Disabled("Remove to run test")
196206
@Test
207+
@DisplayName("X wins using a spiral path")
197208
public void xWinsUsingASpiralPath() {
198209

199210
//GIVEN

0 commit comments

Comments
 (0)