Skip to content

Commit 0b0cefe

Browse files
authored
style: include UTAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT (#7239)
1 parent 1a7f8fe commit 0b0cefe

23 files changed

+107
-110
lines changed

spotbugs-exclude.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,6 @@
210210
<Match>
211211
<Bug pattern="UTAO_JUNIT_ASSERTION_ODDITIES_USE_ASSERT_EQUALS" />
212212
</Match>
213-
<Match>
214-
<Bug pattern="UTAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT" />
215-
</Match>
216213
<Match>
217214
<Bug pattern="UTAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE" />
218215
</Match>

src/test/java/com/thealgorithms/backtracking/PermutationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public class PermutationTest {
1212
@Test
1313
void testNoElement() {
1414
List<Integer[]> result = Permutation.permutation(new Integer[] {});
15-
assertEquals(result.get(0).length, 0);
15+
assertEquals(0, result.get(0).length);
1616
}
1717

1818
@Test
1919
void testSingleElement() {
2020
List<Integer[]> result = Permutation.permutation(new Integer[] {1});
21-
assertEquals(result.get(0)[0], 1);
21+
assertEquals(1, result.get(0)[0]);
2222
}
2323

2424
@Test

src/test/java/com/thealgorithms/ciphers/ECCTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void testEncrypt() {
3737
System.out.println("Base Point G: " + curve.getBasePoint());
3838

3939
// Verify that the ciphertext is not empty
40-
assertEquals(cipherText.length, 2); // Check if the ciphertext contains two points (R and S)
40+
assertEquals(2, cipherText.length); // Check if the ciphertext contains two points (R and S)
4141

4242
// Output the encrypted coordinate points
4343
System.out.println("Encrypted Points:");

src/test/java/com/thealgorithms/datastructures/hashmap/hashing/MapTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ void containsTest() {
8181
@Test
8282
void sizeTest() {
8383
Map<Integer, String> map = getMap();
84-
assertEquals(map.size(), 0);
84+
assertEquals(0, map.size());
8585

8686
for (int i = -100; i < 100; i++) {
8787
map.put(i, String.valueOf(i));
8888
}
8989

90-
assertEquals(map.size(), 200);
90+
assertEquals(200, map.size());
9191

9292
for (int i = -50; i < 50; i++) {
9393
map.delete(i);
9494
}
9595

96-
assertEquals(map.size(), 100);
96+
assertEquals(100, map.size());
9797
}
9898

9999
@Test

src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ class PriorityQueuesTest {
99
void testPQInsertion() {
1010
PriorityQueue myQueue = new PriorityQueue(4);
1111
myQueue.insert(2);
12-
Assertions.assertEquals(myQueue.peek(), 2);
12+
Assertions.assertEquals(2, myQueue.peek());
1313

1414
myQueue.insert(5);
1515
myQueue.insert(3);
16-
Assertions.assertEquals(myQueue.peek(), 5);
16+
Assertions.assertEquals(5, myQueue.peek());
1717

1818
myQueue.insert(10);
19-
Assertions.assertEquals(myQueue.peek(), 10);
19+
Assertions.assertEquals(10, myQueue.peek());
2020
}
2121

2222
@Test
@@ -28,32 +28,32 @@ void testPQDeletion() {
2828
myQueue.insert(10);
2929

3030
myQueue.remove();
31-
Assertions.assertEquals(myQueue.peek(), 5);
31+
Assertions.assertEquals(5, myQueue.peek());
3232
myQueue.remove();
3333
myQueue.remove();
34-
Assertions.assertEquals(myQueue.peek(), 2);
34+
Assertions.assertEquals(2, myQueue.peek());
3535
}
3636

3737
@Test
3838
void testPQExtra() {
3939
PriorityQueue myQueue = new PriorityQueue(4);
40-
Assertions.assertEquals(myQueue.isEmpty(), true);
41-
Assertions.assertEquals(myQueue.isFull(), false);
40+
Assertions.assertTrue(myQueue.isEmpty());
41+
Assertions.assertFalse(myQueue.isFull());
4242
myQueue.insert(2);
4343
myQueue.insert(5);
44-
Assertions.assertEquals(myQueue.isFull(), false);
44+
Assertions.assertFalse(myQueue.isFull());
4545
myQueue.insert(3);
4646
myQueue.insert(10);
47-
Assertions.assertEquals(myQueue.isEmpty(), false);
48-
Assertions.assertEquals(myQueue.isFull(), true);
47+
Assertions.assertFalse(myQueue.isEmpty());
48+
Assertions.assertTrue(myQueue.isFull());
4949

5050
myQueue.remove();
51-
Assertions.assertEquals(myQueue.getSize(), 3);
52-
Assertions.assertEquals(myQueue.peek(), 5);
51+
Assertions.assertEquals(3, myQueue.getSize());
52+
Assertions.assertEquals(5, myQueue.peek());
5353
myQueue.remove();
5454
myQueue.remove();
55-
Assertions.assertEquals(myQueue.peek(), 2);
56-
Assertions.assertEquals(myQueue.getSize(), 1);
55+
Assertions.assertEquals(2, myQueue.peek());
56+
Assertions.assertEquals(1, myQueue.getSize());
5757
}
5858

5959
@Test

src/test/java/com/thealgorithms/io/BufferedReaderTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public void testPeeks() throws IOException {
1717
BufferedReader reader = new BufferedReader(input);
1818

1919
// read the first letter
20-
assertEquals(reader.read(), 'H');
20+
assertEquals('H', reader.read());
2121
len--;
22-
assertEquals(reader.available(), len);
22+
assertEquals(len, reader.available());
2323

2424
// position: H[e]llo!\nWorld!
2525
// reader.read() will be == 'e'
26-
assertEquals(reader.peek(1), 'l');
27-
assertEquals(reader.peek(2), 'l'); // second l
28-
assertEquals(reader.peek(3), 'o');
26+
assertEquals('l', reader.peek(1));
27+
assertEquals('l', reader.peek(2)); // second l
28+
assertEquals('o', reader.peek(3));
2929
}
3030

3131
@Test
@@ -38,21 +38,21 @@ public void testMixes() throws IOException {
3838
BufferedReader reader = new BufferedReader(input);
3939

4040
// read the first letter
41-
assertEquals(reader.read(), 'H'); // first letter
41+
assertEquals('H', reader.read()); // first letter
4242
len--;
4343

44-
assertEquals(reader.peek(1), 'l'); // third later (second letter after 'H')
45-
assertEquals(reader.read(), 'e'); // second letter
44+
assertEquals('l', reader.peek(1)); // third later (second letter after 'H')
45+
assertEquals('e', reader.read()); // second letter
4646
len--;
47-
assertEquals(reader.available(), len);
47+
assertEquals(len, reader.available());
4848

4949
// position: H[e]llo!\nWorld!
50-
assertEquals(reader.peek(2), 'o'); // second l
51-
assertEquals(reader.peek(3), '!');
52-
assertEquals(reader.peek(4), '\n');
50+
assertEquals('o', reader.peek(2)); // second l
51+
assertEquals('!', reader.peek(3));
52+
assertEquals('\n', reader.peek(4));
5353

54-
assertEquals(reader.read(), 'l'); // third letter
55-
assertEquals(reader.peek(1), 'o'); // fourth letter
54+
assertEquals('l', reader.read()); // third letter
55+
assertEquals('o', reader.peek(1)); // fourth letter
5656

5757
for (int i = 0; i < 6; i++) {
5858
reader.read();
@@ -74,23 +74,23 @@ public void testBlockPractical() throws IOException {
7474
ByteArrayInputStream input = new ByteArrayInputStream(bytes);
7575
BufferedReader reader = new BufferedReader(input);
7676

77-
assertEquals(reader.peek(), 'H');
78-
assertEquals(reader.read(), '!'); // read the first letter
77+
assertEquals('H', reader.peek());
78+
assertEquals('!', reader.read()); // read the first letter
7979
len--;
8080

8181
// this only reads the next 5 bytes (Hello) because
8282
// the default buffer size = 5
83-
assertEquals(new String(reader.readBlock()), "Hello");
83+
assertEquals("Hello", new String(reader.readBlock()));
8484
len -= 5;
8585
assertEquals(reader.available(), len);
8686

8787
// maybe kind of a practical demonstration / use case
8888
if (reader.read() == '\n') {
89-
assertEquals(reader.read(), 'W');
90-
assertEquals(reader.read(), 'o');
89+
assertEquals('W', reader.read());
90+
assertEquals('o', reader.read());
9191

9292
// the rest of the blocks
93-
assertEquals(new String(reader.readBlock()), "rld!");
93+
assertEquals("rld!", new String(reader.readBlock()));
9494
} else {
9595
// should not reach
9696
throw new IOException("Something not right");

src/test/java/com/thealgorithms/maths/DistanceFormulaTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,78 @@ public class DistanceFormulaTest {
99

1010
@Test
1111
void euclideanTest1() {
12-
Assertions.assertEquals(DistanceFormula.euclideanDistance(1, 1, 2, 2), 1.4142135623730951);
12+
Assertions.assertEquals(1.4142135623730951, DistanceFormula.euclideanDistance(1, 1, 2, 2));
1313
}
1414

1515
@Test
1616
void euclideanTest2() {
17-
Assertions.assertEquals(DistanceFormula.euclideanDistance(1, 3, 8, 0), 7.0710678118654755);
17+
Assertions.assertEquals(7.0710678118654755, DistanceFormula.euclideanDistance(1, 3, 8, 0));
1818
}
1919

2020
@Test
2121
void euclideanTest3() {
22-
Assertions.assertEquals(DistanceFormula.euclideanDistance(2.4, 9.1, 55.1, 100), 110.91911467371168);
22+
Assertions.assertEquals(110.91911467371168, DistanceFormula.euclideanDistance(2.4, 9.1, 55.1, 100));
2323
}
2424

2525
@Test
2626
void euclideanTest4() {
27-
Assertions.assertEquals(DistanceFormula.euclideanDistance(1000, 13, 20000, 84), 19022.067605809836);
27+
Assertions.assertEquals(19022.067605809836, DistanceFormula.euclideanDistance(1000, 13, 20000, 84));
2828
}
2929

3030
@Test
3131
public void manhattantest1() {
32-
assertEquals(DistanceFormula.manhattanDistance(1, 2, 3, 4), 4);
32+
assertEquals(4, DistanceFormula.manhattanDistance(1, 2, 3, 4));
3333
}
3434

3535
@Test
3636
public void manhattantest2() {
37-
assertEquals(DistanceFormula.manhattanDistance(6.5, 8.4, 20.1, 13.6), 18.8);
37+
assertEquals(18.8, DistanceFormula.manhattanDistance(6.5, 8.4, 20.1, 13.6));
3838
}
3939

4040
@Test
4141
public void manhattanTest3() {
42-
assertEquals(DistanceFormula.manhattanDistance(10.112, 50, 8, 25.67), 26.442);
42+
assertEquals(26.442, DistanceFormula.manhattanDistance(10.112, 50, 8, 25.67));
4343
}
4444

4545
@Test
4646
public void hammingTest1() {
4747
int[] array1 = {1, 1, 1, 1};
4848
int[] array2 = {0, 0, 0, 0};
49-
assertEquals(DistanceFormula.hammingDistance(array1, array2), 4);
49+
assertEquals(4, DistanceFormula.hammingDistance(array1, array2));
5050
}
5151

5252
@Test
5353
public void hammingTest2() {
5454
int[] array1 = {1, 1, 1, 1};
5555
int[] array2 = {1, 1, 1, 1};
56-
assertEquals(DistanceFormula.hammingDistance(array1, array2), 0);
56+
assertEquals(0, DistanceFormula.hammingDistance(array1, array2));
5757
}
5858

5959
@Test
6060
public void hammingTest3() {
6161
int[] array1 = {1, 0, 0, 1, 1, 0, 1, 1, 0};
6262
int[] array2 = {0, 1, 0, 0, 1, 1, 1, 0, 0};
63-
assertEquals(DistanceFormula.hammingDistance(array1, array2), 5);
63+
assertEquals(5, DistanceFormula.hammingDistance(array1, array2));
6464
}
6565

6666
@Test
6767
public void minkowskiTest1() {
6868
double[] array1 = {1, 3, 8, 5};
6969
double[] array2 = {4, 2, 6, 9};
70-
assertEquals(DistanceFormula.minkowskiDistance(array1, array2, 1), 10);
70+
assertEquals(10, DistanceFormula.minkowskiDistance(array1, array2, 1));
7171
}
7272

7373
@Test
7474
public void minkowskiTest2() {
7575
double[] array1 = {1, 3, 8, 5};
7676
double[] array2 = {4, 2, 6, 9};
77-
assertEquals(DistanceFormula.minkowskiDistance(array1, array2, 2), 5.477225575051661);
77+
assertEquals(5.477225575051661, DistanceFormula.minkowskiDistance(array1, array2, 2));
7878
}
7979

8080
@Test
8181
public void minkowskiTest3() {
8282
double[] array1 = {1, 3, 8, 5};
8383
double[] array2 = {4, 2, 6, 9};
84-
assertEquals(DistanceFormula.minkowskiDistance(array1, array2, 3), 4.641588833612778);
84+
assertEquals(4.641588833612778, DistanceFormula.minkowskiDistance(array1, array2, 3));
8585
}
8686
}

src/test/java/com/thealgorithms/maths/FactorialTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class FactorialTest {
1111
@Test
1212
public void testWhenInvalidInoutProvidedShouldThrowException() {
1313
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> Factorial.factorial(-1));
14-
assertEquals(exception.getMessage(), EXCEPTION_MESSAGE);
14+
assertEquals(EXCEPTION_MESSAGE, exception.getMessage());
1515
}
1616

1717
@Test

src/test/java/com/thealgorithms/maths/NthUglyNumberTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ public void testGetWithSameObject() {
4848

4949
var uglyNumbers = new NthUglyNumber(new int[] {7, 2, 5, 3});
5050
for (final var tc : testCases.entrySet()) {
51-
assertEquals(uglyNumbers.get(tc.getKey()), tc.getValue());
51+
assertEquals(tc.getValue(), uglyNumbers.get(tc.getKey()));
5252
}
5353

54-
assertEquals(uglyNumbers.get(999), 385875);
54+
assertEquals(385875, uglyNumbers.get(999));
5555
}
5656

5757
@Test
5858
public void testGetWithBase1() {
5959
var uglyNumbers = new NthUglyNumber(new int[] {1});
60-
assertEquals(uglyNumbers.get(10), 1);
60+
assertEquals(1, uglyNumbers.get(10));
6161
}
6262

6363
@Test
6464
public void testGetWithBase2() {
6565
var uglyNumbers = new NthUglyNumber(new int[] {2});
66-
assertEquals(uglyNumbers.get(5), 32);
66+
assertEquals(32, uglyNumbers.get(5));
6767
}
6868

6969
@Test

src/test/java/com/thealgorithms/maths/PalindromeNumberTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public void testNumbersAreNotPalindromes() {
2525
@Test
2626
public void testIfNegativeInputThenExceptionExpected() {
2727
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> PalindromeNumber.isPalindrome(-1));
28-
Assertions.assertEquals(exception.getMessage(), "Input parameter must not be negative!");
28+
Assertions.assertEquals("Input parameter must not be negative!", exception.getMessage());
2929
}
3030
}

0 commit comments

Comments
 (0)