Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@
<Match>
<Bug pattern="UTAO_JUNIT_ASSERTION_ODDITIES_USE_ASSERT_EQUALS" />
</Match>
<Match>
<Bug pattern="UTAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT" />
</Match>
<Match>
<Bug pattern="UTAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE" />
</Match>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class PermutationTest {
@Test
void testNoElement() {
List<Integer[]> result = Permutation.permutation(new Integer[] {});
assertEquals(result.get(0).length, 0);
assertEquals(0, result.get(0).length);
}

@Test
void testSingleElement() {
List<Integer[]> result = Permutation.permutation(new Integer[] {1});
assertEquals(result.get(0)[0], 1);
assertEquals(1, result.get(0)[0]);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/thealgorithms/ciphers/ECCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void testEncrypt() {
System.out.println("Base Point G: " + curve.getBasePoint());

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

// Output the encrypted coordinate points
System.out.println("Encrypted Points:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ void containsTest() {
@Test
void sizeTest() {
Map<Integer, String> map = getMap();
assertEquals(map.size(), 0);
assertEquals(0, map.size());

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

assertEquals(map.size(), 200);
assertEquals(200, map.size());

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

assertEquals(map.size(), 100);
assertEquals(100, map.size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class PriorityQueuesTest {
void testPQInsertion() {
PriorityQueue myQueue = new PriorityQueue(4);
myQueue.insert(2);
Assertions.assertEquals(myQueue.peek(), 2);
Assertions.assertEquals(2, myQueue.peek());

myQueue.insert(5);
myQueue.insert(3);
Assertions.assertEquals(myQueue.peek(), 5);
Assertions.assertEquals(5, myQueue.peek());

myQueue.insert(10);
Assertions.assertEquals(myQueue.peek(), 10);
Assertions.assertEquals(10, myQueue.peek());
}

@Test
Expand All @@ -28,32 +28,32 @@ void testPQDeletion() {
myQueue.insert(10);

myQueue.remove();
Assertions.assertEquals(myQueue.peek(), 5);
Assertions.assertEquals(5, myQueue.peek());
myQueue.remove();
myQueue.remove();
Assertions.assertEquals(myQueue.peek(), 2);
Assertions.assertEquals(2, myQueue.peek());
}

@Test
void testPQExtra() {
PriorityQueue myQueue = new PriorityQueue(4);
Assertions.assertEquals(myQueue.isEmpty(), true);
Assertions.assertEquals(myQueue.isFull(), false);
Assertions.assertTrue(myQueue.isEmpty());
Assertions.assertFalse(myQueue.isFull());
myQueue.insert(2);
myQueue.insert(5);
Assertions.assertEquals(myQueue.isFull(), false);
Assertions.assertFalse(myQueue.isFull());
myQueue.insert(3);
myQueue.insert(10);
Assertions.assertEquals(myQueue.isEmpty(), false);
Assertions.assertEquals(myQueue.isFull(), true);
Assertions.assertFalse(myQueue.isEmpty());
Assertions.assertTrue(myQueue.isFull());

myQueue.remove();
Assertions.assertEquals(myQueue.getSize(), 3);
Assertions.assertEquals(myQueue.peek(), 5);
Assertions.assertEquals(3, myQueue.getSize());
Assertions.assertEquals(5, myQueue.peek());
myQueue.remove();
myQueue.remove();
Assertions.assertEquals(myQueue.peek(), 2);
Assertions.assertEquals(myQueue.getSize(), 1);
Assertions.assertEquals(2, myQueue.peek());
Assertions.assertEquals(1, myQueue.getSize());
}

@Test
Expand Down
40 changes: 20 additions & 20 deletions src/test/java/com/thealgorithms/io/BufferedReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public void testPeeks() throws IOException {
BufferedReader reader = new BufferedReader(input);

// read the first letter
assertEquals(reader.read(), 'H');
assertEquals('H', reader.read());
len--;
assertEquals(reader.available(), len);
assertEquals(len, reader.available());

// position: H[e]llo!\nWorld!
// reader.read() will be == 'e'
assertEquals(reader.peek(1), 'l');
assertEquals(reader.peek(2), 'l'); // second l
assertEquals(reader.peek(3), 'o');
assertEquals('l', reader.peek(1));
assertEquals('l', reader.peek(2)); // second l
assertEquals('o', reader.peek(3));
}

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

// read the first letter
assertEquals(reader.read(), 'H'); // first letter
assertEquals('H', reader.read()); // first letter
len--;

assertEquals(reader.peek(1), 'l'); // third later (second letter after 'H')
assertEquals(reader.read(), 'e'); // second letter
assertEquals('l', reader.peek(1)); // third later (second letter after 'H')
assertEquals('e', reader.read()); // second letter
len--;
assertEquals(reader.available(), len);
assertEquals(len, reader.available());

// position: H[e]llo!\nWorld!
assertEquals(reader.peek(2), 'o'); // second l
assertEquals(reader.peek(3), '!');
assertEquals(reader.peek(4), '\n');
assertEquals('o', reader.peek(2)); // second l
assertEquals('!', reader.peek(3));
assertEquals('\n', reader.peek(4));

assertEquals(reader.read(), 'l'); // third letter
assertEquals(reader.peek(1), 'o'); // fourth letter
assertEquals('l', reader.read()); // third letter
assertEquals('o', reader.peek(1)); // fourth letter

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

assertEquals(reader.peek(), 'H');
assertEquals(reader.read(), '!'); // read the first letter
assertEquals('H', reader.peek());
assertEquals('!', reader.read()); // read the first letter
len--;

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

// maybe kind of a practical demonstration / use case
if (reader.read() == '\n') {
assertEquals(reader.read(), 'W');
assertEquals(reader.read(), 'o');
assertEquals('W', reader.read());
assertEquals('o', reader.read());

// the rest of the blocks
assertEquals(new String(reader.readBlock()), "rld!");
assertEquals("rld!", new String(reader.readBlock()));
} else {
// should not reach
throw new IOException("Something not right");
Expand Down
26 changes: 13 additions & 13 deletions src/test/java/com/thealgorithms/maths/DistanceFormulaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,78 @@ public class DistanceFormulaTest {

@Test
void euclideanTest1() {
Assertions.assertEquals(DistanceFormula.euclideanDistance(1, 1, 2, 2), 1.4142135623730951);
Assertions.assertEquals(1.4142135623730951, DistanceFormula.euclideanDistance(1, 1, 2, 2));
}

@Test
void euclideanTest2() {
Assertions.assertEquals(DistanceFormula.euclideanDistance(1, 3, 8, 0), 7.0710678118654755);
Assertions.assertEquals(7.0710678118654755, DistanceFormula.euclideanDistance(1, 3, 8, 0));
}

@Test
void euclideanTest3() {
Assertions.assertEquals(DistanceFormula.euclideanDistance(2.4, 9.1, 55.1, 100), 110.91911467371168);
Assertions.assertEquals(110.91911467371168, DistanceFormula.euclideanDistance(2.4, 9.1, 55.1, 100));
}

@Test
void euclideanTest4() {
Assertions.assertEquals(DistanceFormula.euclideanDistance(1000, 13, 20000, 84), 19022.067605809836);
Assertions.assertEquals(19022.067605809836, DistanceFormula.euclideanDistance(1000, 13, 20000, 84));
}

@Test
public void manhattantest1() {
assertEquals(DistanceFormula.manhattanDistance(1, 2, 3, 4), 4);
assertEquals(4, DistanceFormula.manhattanDistance(1, 2, 3, 4));
}

@Test
public void manhattantest2() {
assertEquals(DistanceFormula.manhattanDistance(6.5, 8.4, 20.1, 13.6), 18.8);
assertEquals(18.8, DistanceFormula.manhattanDistance(6.5, 8.4, 20.1, 13.6));
}

@Test
public void manhattanTest3() {
assertEquals(DistanceFormula.manhattanDistance(10.112, 50, 8, 25.67), 26.442);
assertEquals(26.442, DistanceFormula.manhattanDistance(10.112, 50, 8, 25.67));
}

@Test
public void hammingTest1() {
int[] array1 = {1, 1, 1, 1};
int[] array2 = {0, 0, 0, 0};
assertEquals(DistanceFormula.hammingDistance(array1, array2), 4);
assertEquals(4, DistanceFormula.hammingDistance(array1, array2));
}

@Test
public void hammingTest2() {
int[] array1 = {1, 1, 1, 1};
int[] array2 = {1, 1, 1, 1};
assertEquals(DistanceFormula.hammingDistance(array1, array2), 0);
assertEquals(0, DistanceFormula.hammingDistance(array1, array2));
}

@Test
public void hammingTest3() {
int[] array1 = {1, 0, 0, 1, 1, 0, 1, 1, 0};
int[] array2 = {0, 1, 0, 0, 1, 1, 1, 0, 0};
assertEquals(DistanceFormula.hammingDistance(array1, array2), 5);
assertEquals(5, DistanceFormula.hammingDistance(array1, array2));
}

@Test
public void minkowskiTest1() {
double[] array1 = {1, 3, 8, 5};
double[] array2 = {4, 2, 6, 9};
assertEquals(DistanceFormula.minkowskiDistance(array1, array2, 1), 10);
assertEquals(10, DistanceFormula.minkowskiDistance(array1, array2, 1));
}

@Test
public void minkowskiTest2() {
double[] array1 = {1, 3, 8, 5};
double[] array2 = {4, 2, 6, 9};
assertEquals(DistanceFormula.minkowskiDistance(array1, array2, 2), 5.477225575051661);
assertEquals(5.477225575051661, DistanceFormula.minkowskiDistance(array1, array2, 2));
}

@Test
public void minkowskiTest3() {
double[] array1 = {1, 3, 8, 5};
double[] array2 = {4, 2, 6, 9};
assertEquals(DistanceFormula.minkowskiDistance(array1, array2, 3), 4.641588833612778);
assertEquals(4.641588833612778, DistanceFormula.minkowskiDistance(array1, array2, 3));
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/thealgorithms/maths/FactorialTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FactorialTest {
@Test
public void testWhenInvalidInoutProvidedShouldThrowException() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> Factorial.factorial(-1));
assertEquals(exception.getMessage(), EXCEPTION_MESSAGE);
assertEquals(EXCEPTION_MESSAGE, exception.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ public void testGetWithSameObject() {

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

assertEquals(uglyNumbers.get(999), 385875);
assertEquals(385875, uglyNumbers.get(999));
}

@Test
public void testGetWithBase1() {
var uglyNumbers = new NthUglyNumber(new int[] {1});
assertEquals(uglyNumbers.get(10), 1);
assertEquals(1, uglyNumbers.get(10));
}

@Test
public void testGetWithBase2() {
var uglyNumbers = new NthUglyNumber(new int[] {2});
assertEquals(uglyNumbers.get(5), 32);
assertEquals(32, uglyNumbers.get(5));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public void testNumbersAreNotPalindromes() {
@Test
public void testIfNegativeInputThenExceptionExpected() {
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> PalindromeNumber.isPalindrome(-1));
Assertions.assertEquals(exception.getMessage(), "Input parameter must not be negative!");
Assertions.assertEquals("Input parameter must not be negative!", exception.getMessage());
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/thealgorithms/maths/ParseIntegerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public class ParseIntegerTest {
@Test
public void testNullInput() {
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> ParseInteger.parseInt(null));
Assertions.assertEquals(exception.getMessage(), NULL_PARAMETER_MESSAGE);
Assertions.assertEquals(NULL_PARAMETER_MESSAGE, exception.getMessage());
}

@Test
public void testEmptyInput() {
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> ParseInteger.parseInt(""));
Assertions.assertEquals(exception.getMessage(), EMPTY_PARAMETER_MESSAGE);
Assertions.assertEquals(EMPTY_PARAMETER_MESSAGE, exception.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public void testSolveEquationRealRoots() {
double c = 1.9;

ComplexNumber[] roots = quadraticEquationSolver.solveEquation(a, b, c);
Assertions.assertEquals(roots.length, 2);
Assertions.assertEquals(roots[0].real, -0.27810465435684306);
Assertions.assertEquals(2, roots.length, 2);
Assertions.assertEquals(-0.27810465435684306, roots[0].real);
Assertions.assertNull(roots[0].imaginary);
Assertions.assertEquals(roots[1].real, -1.6266572504050616);
Assertions.assertEquals(-1.6266572504050616, roots[1].real);
Assertions.assertNull(roots[1].imaginary);
}

Expand All @@ -29,8 +29,8 @@ public void testSolveEquationEqualRoots() {
double c = 1;

ComplexNumber[] roots = quadraticEquationSolver.solveEquation(a, b, c);
Assertions.assertEquals(roots.length, 1);
Assertions.assertEquals(roots[0].real, -1);
Assertions.assertEquals(1, roots.length);
Assertions.assertEquals(-1, roots[0].real);
}

@Test
Expand All @@ -41,10 +41,10 @@ public void testSolveEquationComplexRoots() {
double c = 5.6;

ComplexNumber[] roots = quadraticEquationSolver.solveEquation(a, b, c);
Assertions.assertEquals(roots.length, 2);
Assertions.assertEquals(roots[0].real, -0.8695652173913044);
Assertions.assertEquals(roots[0].imaginary, 1.2956229935435948);
Assertions.assertEquals(roots[1].real, -0.8695652173913044);
Assertions.assertEquals(roots[1].imaginary, -1.2956229935435948);
Assertions.assertEquals(2, roots.length);
Assertions.assertEquals(-0.8695652173913044, roots[0].real);
Assertions.assertEquals(1.2956229935435948, roots[0].imaginary);
Assertions.assertEquals(-0.8695652173913044, roots[1].real);
Assertions.assertEquals(-1.2956229935435948, roots[1].imaginary);
}
}
Loading
Loading