Skip to content

Commit f55e221

Browse files
committed
Fix
1 parent 5015c29 commit f55e221

File tree

1 file changed

+35
-38
lines changed

1 file changed

+35
-38
lines changed

src/test/java/com/thealgorithms/others/MiniMaxAlgorithmTest.java

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void testConstructorCreatesValidScores() {
4242

4343
@Test
4444
void testConstructorWithValidScores() {
45-
int[] validScores = { 10, 20, 30, 40 };
45+
int[] validScores = {10, 20, 30, 40};
4646
MiniMaxAlgorithm customMiniMax = new MiniMaxAlgorithm(validScores);
4747

4848
Assertions.assertArrayEquals(validScores, customMiniMax.getScores());
@@ -51,14 +51,14 @@ void testConstructorWithValidScores() {
5151

5252
@Test
5353
void testConstructorWithInvalidScoresThrowsException() {
54-
int[] invalidScores = { 10, 20, 30 }; // Length 3 is not a power of 2
54+
int[] invalidScores = {10, 20, 30}; // Length 3 is not a power of 2
5555
Assertions.assertThrows(IllegalArgumentException.class, () -> new MiniMaxAlgorithm(invalidScores));
5656
}
5757

5858
@Test
5959
void testConstructorDoesNotModifyOriginalArray() {
60-
int[] originalScores = { 10, 20, 30, 40 };
61-
int[] copyOfOriginal = { 10, 20, 30, 40 };
60+
int[] originalScores = {10, 20, 30, 40};
61+
int[] copyOfOriginal = {10, 20, 30, 40};
6262
MiniMaxAlgorithm customMiniMax = new MiniMaxAlgorithm(originalScores);
6363

6464
// Modify the original array
@@ -70,7 +70,7 @@ void testConstructorDoesNotModifyOriginalArray() {
7070

7171
@Test
7272
void testSetScoresWithValidPowerOfTwo() {
73-
int[] validScores = { 10, 20, 30, 40 };
73+
int[] validScores = {10, 20, 30, 40};
7474
miniMax.setScores(validScores);
7575

7676
Assertions.assertArrayEquals(validScores, miniMax.getScores());
@@ -79,7 +79,7 @@ void testSetScoresWithValidPowerOfTwo() {
7979

8080
@Test
8181
void testSetScoresWithInvalidLength() {
82-
int[] invalidScores = { 10, 20, 30 }; // Length 3 is not a power of 2
82+
int[] invalidScores = {10, 20, 30}; // Length 3 is not a power of 2
8383
Assertions.assertThrows(IllegalArgumentException.class, () -> miniMax.setScores(invalidScores));
8484

8585
// Scores should remain unchanged (original length 8)
@@ -100,17 +100,16 @@ void testSetScoresWithVariousInvalidLengths() {
100100
// Test multiple invalid lengths to ensure isPowerOfTwo function is fully
101101
// covered
102102
int[][] invalidScoreArrays = {
103-
{ 1, 2, 3, 4, 5 }, // Length 5
104-
{ 1, 2, 3, 4, 5, 6 }, // Length 6
105-
{ 1, 2, 3, 4, 5, 6, 7 }, // Length 7
106-
new int[9], // Length 9
107-
new int[10], // Length 10
108-
new int[15] // Length 15
103+
{1, 2, 3, 4, 5}, // Length 5
104+
{1, 2, 3, 4, 5, 6}, // Length 6
105+
{1, 2, 3, 4, 5, 6, 7}, // Length 7
106+
new int[9], // Length 9
107+
new int[10], // Length 10
108+
new int[15] // Length 15
109109
};
110110

111111
for (int[] invalidScores : invalidScoreArrays) {
112-
Assertions.assertThrows(IllegalArgumentException.class, () -> miniMax.setScores(invalidScores),
113-
"Failed for array length: " + invalidScores.length);
112+
Assertions.assertThrows(IllegalArgumentException.class, () -> miniMax.setScores(invalidScores), "Failed for array length: " + invalidScores.length);
114113
}
115114

116115
// Scores should remain unchanged (original length 8)
@@ -119,7 +118,7 @@ void testSetScoresWithVariousInvalidLengths() {
119118

120119
@Test
121120
void testSetScoresWithSingleElement() {
122-
int[] singleScore = { 42 };
121+
int[] singleScore = {42};
123122
miniMax.setScores(singleScore);
124123

125124
Assertions.assertArrayEquals(singleScore, miniMax.getScores());
@@ -129,7 +128,7 @@ void testSetScoresWithSingleElement() {
129128
@Test
130129
void testMiniMaxWithKnownScores() {
131130
// Test with a known game tree: [3, 12, 8, 2]
132-
int[] testScores = { 3, 12, 8, 2 };
131+
int[] testScores = {3, 12, 8, 2};
133132
miniMax.setScores(testScores);
134133

135134
// Maximizer starts: should choose max(min(3,12), min(8,2)) = max(3, 2) = 3
@@ -140,7 +139,7 @@ void testMiniMaxWithKnownScores() {
140139
@Test
141140
void testMiniMaxWithMinimizerFirst() {
142141
// Test with minimizer starting first
143-
int[] testScores = { 3, 12, 8, 2 };
142+
int[] testScores = {3, 12, 8, 2};
144143
miniMax.setScores(testScores);
145144

146145
// Minimizer starts: should choose min(max(3,12), max(8,2)) = min(12, 8) = 8
@@ -151,7 +150,7 @@ void testMiniMaxWithMinimizerFirst() {
151150
@Test
152151
void testMiniMaxWithLargerTree() {
153152
// Test with 8 elements: [5, 6, 7, 4, 5, 3, 6, 2]
154-
int[] testScores = { 5, 6, 7, 4, 5, 3, 6, 2 };
153+
int[] testScores = {5, 6, 7, 4, 5, 3, 6, 2};
155154
miniMax.setScores(testScores);
156155

157156
// Maximizer starts
@@ -163,7 +162,7 @@ void testMiniMaxWithLargerTree() {
163162

164163
@Test
165164
void testMiniMaxVerboseOutput() {
166-
int[] testScores = { 3, 12, 8, 2 };
165+
int[] testScores = {3, 12, 8, 2};
167166
miniMax.setScores(testScores);
168167

169168
miniMax.miniMax(0, true, 0, true);
@@ -209,7 +208,7 @@ void testMainMethod() {
209208
@Test
210209
void testHeightCalculation() {
211210
// Test height calculation for different array sizes
212-
int[] scores2 = { 1, 2 };
211+
int[] scores2 = {1, 2};
213212
miniMax.setScores(scores2);
214213
Assertions.assertEquals(1, miniMax.getHeight()); // log2(2) = 1
215214

@@ -220,7 +219,7 @@ void testHeightCalculation() {
220219

221220
@Test
222221
void testEdgeCaseWithZeroScores() {
223-
int[] zeroScores = { 0, 0, 0, 0 };
222+
int[] zeroScores = {0, 0, 0, 0};
224223
miniMax.setScores(zeroScores);
225224

226225
int result = miniMax.miniMax(0, true, 0, false);
@@ -229,7 +228,7 @@ void testEdgeCaseWithZeroScores() {
229228

230229
@Test
231230
void testEdgeCaseWithNegativeScores() {
232-
int[] negativeScores = { -5, -2, -8, -1 };
231+
int[] negativeScores = {-5, -2, -8, -1};
233232
miniMax.setScores(negativeScores);
234233

235234
// Tree evaluation with maximizer first:
@@ -269,28 +268,26 @@ void testSetScoresWithLargePowerOfTwo() {
269268
void testSetScoresValidEdgeCases() {
270269
// Test valid powers of 2 to ensure isPowerOfTwo returns true correctly
271270
int[][] validPowersOf2 = {
272-
new int[1], // 1 = 2^0
273-
new int[2], // 2 = 2^1
274-
new int[4], // 4 = 2^2
275-
new int[8], // 8 = 2^3
276-
new int[16], // 16 = 2^4
277-
new int[64] // 64 = 2^6
271+
new int[1], // 1 = 2^0
272+
new int[2], // 2 = 2^1
273+
new int[4], // 4 = 2^2
274+
new int[8], // 8 = 2^3
275+
new int[16], // 16 = 2^4
276+
new int[64] // 64 = 2^6
278277
};
279278

280-
int[] expectedHeights = { 0, 1, 2, 3, 4, 6 };
279+
int[] expectedHeights = {0, 1, 2, 3, 4, 6};
281280

282281
for (int i = 0; i < validPowersOf2.length; i++) {
283282
miniMax.setScores(validPowersOf2[i]);
284-
Assertions.assertEquals(validPowersOf2[i].length, miniMax.getScores().length,
285-
"Failed for array length: " + validPowersOf2[i].length);
286-
Assertions.assertEquals(expectedHeights[i], miniMax.getHeight(),
287-
"Height calculation failed for array length: " + validPowersOf2[i].length);
283+
Assertions.assertEquals(validPowersOf2[i].length, miniMax.getScores().length, "Failed for array length: " + validPowersOf2[i].length);
284+
Assertions.assertEquals(expectedHeights[i], miniMax.getHeight(), "Height calculation failed for array length: " + validPowersOf2[i].length);
288285
}
289286
}
290287

291288
@Test
292289
void testGetScoresReturnsDefensiveCopy() {
293-
int[] originalScores = { 10, 20, 30, 40 };
290+
int[] originalScores = {10, 20, 30, 40};
294291
miniMax.setScores(originalScores);
295292

296293
// Get the scores and modify them
@@ -303,7 +300,7 @@ void testGetScoresReturnsDefensiveCopy() {
303300

304301
@Test
305302
void testSetScoresCreatesDefensiveCopy() {
306-
int[] originalScores = { 10, 20, 30, 40 };
303+
int[] originalScores = {10, 20, 30, 40};
307304
miniMax.setScores(originalScores);
308305

309306
// Modify the original array after setting
@@ -315,7 +312,7 @@ void testSetScoresCreatesDefensiveCopy() {
315312

316313
@Test
317314
void testMiniMaxWithAllSameScores() {
318-
int[] sameScores = { 5, 5, 5, 5 };
315+
int[] sameScores = {5, 5, 5, 5};
319316
miniMax.setScores(sameScores);
320317

321318
// When all scores are the same, result should be that score
@@ -325,7 +322,7 @@ void testMiniMaxWithAllSameScores() {
325322

326323
@Test
327324
void testMiniMaxAtDifferentDepths() {
328-
int[] testScores = { 3, 12, 8, 2, 14, 5, 2, 9 };
325+
int[] testScores = {3, 12, 8, 2, 14, 5, 2, 9};
329326
miniMax.setScores(testScores);
330327

331328
// Test maximizer first
@@ -337,7 +334,7 @@ void testMiniMaxAtDifferentDepths() {
337334

338335
@Test
339336
void testMiniMaxWithMinIntAndMaxInt() {
340-
int[] extremeScores = { Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 1 };
337+
int[] extremeScores = {Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 1};
341338
miniMax.setScores(extremeScores);
342339

343340
int result = miniMax.miniMax(0, true, 0, false);

0 commit comments

Comments
 (0)