mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
style: include UTAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT (#7239)
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ECCTest {
|
||||
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:");
|
||||
|
||||
@@ -81,19 +81,19 @@ abstract class MapTest {
|
||||
@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
|
||||
|
||||
@@ -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
|
||||
@@ -28,32 +28,32 @@ class PriorityQueuesTest {
|
||||
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
|
||||
|
||||
@@ -17,15 +17,15 @@ class BufferedReaderTest {
|
||||
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
|
||||
@@ -38,21 +38,21 @@ class BufferedReaderTest {
|
||||
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();
|
||||
@@ -74,23 +74,23 @@ class BufferedReaderTest {
|
||||
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");
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -48,22 +48,22 @@ public class NthUglyNumberTest {
|
||||
|
||||
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
|
||||
|
||||
@@ -25,6 +25,6 @@ public class PalindromeNumberTest {
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,10 +14,10 @@ public class QuadraticEquationSolverTest {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ public class QuadraticEquationSolverTest {
|
||||
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
|
||||
@@ -41,10 +41,10 @@ public class QuadraticEquationSolverTest {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,19 +29,19 @@ public class SecondMinMaxTest {
|
||||
@Test
|
||||
public void testForEmptyInputArray() {
|
||||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> SecondMinMax.findSecondMin(new int[] {}));
|
||||
assertEquals(exception.getMessage(), EXP_MSG_ARR_LEN_LESS_2);
|
||||
assertEquals(EXP_MSG_ARR_LEN_LESS_2, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForArrayWithSingleElement() {
|
||||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> SecondMinMax.findSecondMax(new int[] {1}));
|
||||
assertEquals(exception.getMessage(), EXP_MSG_ARR_LEN_LESS_2);
|
||||
assertEquals(EXP_MSG_ARR_LEN_LESS_2, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForArrayWithSameElements() {
|
||||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> SecondMinMax.findSecondMin(new int[] {1, 1, 1, 1}));
|
||||
assertEquals(exception.getMessage(), EXP_MSG_ARR_SAME_ELE);
|
||||
assertEquals(EXP_MSG_ARR_SAME_ELE, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
||||
@@ -8,19 +8,19 @@ public class StandardDeviationTest {
|
||||
@Test
|
||||
void test1() {
|
||||
double[] t1 = new double[] {1, 1, 1, 1, 1};
|
||||
Assertions.assertEquals(StandardDeviation.stdDev(t1), 0.0);
|
||||
Assertions.assertEquals(0.0, StandardDeviation.stdDev(t1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test2() {
|
||||
double[] t2 = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
Assertions.assertEquals(StandardDeviation.stdDev(t2), 2.8722813232690143);
|
||||
Assertions.assertEquals(2.8722813232690143, StandardDeviation.stdDev(t2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test3() {
|
||||
double[] t3 = new double[] {1.1, 8.5, 20.3, 2.4, 6.2};
|
||||
Assertions.assertEquals(StandardDeviation.stdDev(t3), 6.8308125431752265);
|
||||
Assertions.assertEquals(6.8308125431752265, StandardDeviation.stdDev(t3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -32,6 +32,6 @@ public class StandardDeviationTest {
|
||||
100.00045,
|
||||
56.7,
|
||||
};
|
||||
Assertions.assertEquals(StandardDeviation.stdDev(t4), 38.506117353865775);
|
||||
Assertions.assertEquals(38.506117353865775, StandardDeviation.stdDev(t4));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,21 +7,21 @@ public class StandardScoreTest {
|
||||
|
||||
@Test
|
||||
void test1() {
|
||||
Assertions.assertEquals(StandardScore.zScore(2, 0, 5), 0.4);
|
||||
Assertions.assertEquals(0.4, StandardScore.zScore(2, 0, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test2() {
|
||||
Assertions.assertEquals(StandardScore.zScore(1, 1, 1), 0.0);
|
||||
Assertions.assertEquals(0.0, StandardScore.zScore(1, 1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test3() {
|
||||
Assertions.assertEquals(StandardScore.zScore(2.5, 1.8, 0.7), 1.0);
|
||||
Assertions.assertEquals(1.0, StandardScore.zScore(2.5, 1.8, 0.7));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test4() {
|
||||
Assertions.assertEquals(StandardScore.zScore(8.9, 3, 4.2), 1.4047619047619049);
|
||||
Assertions.assertEquals(1.4047619047619049, StandardScore.zScore(8.9, 3, 4.2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,30 +10,30 @@ public class VolumeTest {
|
||||
public void volume() {
|
||||
|
||||
/* test cube */
|
||||
assertEquals(Volume.volumeCube(7), 343.0);
|
||||
assertEquals(343.0, Volume.volumeCube(7));
|
||||
|
||||
/* test cuboid */
|
||||
assertEquals(Volume.volumeCuboid(2, 5, 7), 70.0);
|
||||
assertEquals(70.0, Volume.volumeCuboid(2, 5, 7));
|
||||
|
||||
/* test sphere */
|
||||
assertEquals(Volume.volumeSphere(7), 1436.7550402417319);
|
||||
assertEquals(1436.7550402417319, Volume.volumeSphere(7));
|
||||
|
||||
/* test cylinder */
|
||||
assertEquals(Volume.volumeCylinder(3, 7), 197.92033717615698);
|
||||
assertEquals(197.92033717615698, Volume.volumeCylinder(3, 7));
|
||||
|
||||
/* test hemisphere */
|
||||
assertEquals(Volume.volumeHemisphere(7), 718.3775201208659);
|
||||
assertEquals(718.3775201208659, Volume.volumeHemisphere(7));
|
||||
|
||||
/* test cone */
|
||||
assertEquals(Volume.volumeCone(3, 7), 65.97344572538566);
|
||||
assertEquals(65.97344572538566, Volume.volumeCone(3, 7));
|
||||
|
||||
/* test prism */
|
||||
assertEquals(Volume.volumePrism(10, 2), 20.0);
|
||||
assertEquals(20.0, Volume.volumePrism(10, 2));
|
||||
|
||||
/* test pyramid */
|
||||
assertEquals(Volume.volumePyramid(10, 3), 10.0);
|
||||
assertEquals(10.0, Volume.volumePyramid(10, 3));
|
||||
|
||||
/* test frustum */
|
||||
assertEquals(Volume.volumeFrustumOfCone(3, 5, 7), 359.188760060433);
|
||||
assertEquals(359.188760060433, Volume.volumeFrustumOfCone(3, 5, 7));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class MedianOfRunningArrayTest {
|
||||
public void testWhenInvalidInoutProvidedShouldThrowException() {
|
||||
var stream = new MedianOfRunningArrayInteger();
|
||||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, stream::getMedian);
|
||||
assertEquals(exception.getMessage(), EXCEPTION_MESSAGE);
|
||||
assertEquals(EXCEPTION_MESSAGE, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -117,7 +117,7 @@ public class BinarySearch2dArrayTest {
|
||||
int target = 8;
|
||||
// Assert that the requirement, that the target is in the middle row and middle column, is
|
||||
// fulfilled.
|
||||
assertEquals(arr[arr.length / 2][arr[0].length / 2], target);
|
||||
assertEquals(target, arr[arr.length / 2][arr[0].length / 2]);
|
||||
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
|
||||
System.out.println(Arrays.toString(ans));
|
||||
assertEquals(1, ans[0]);
|
||||
@@ -135,8 +135,8 @@ public class BinarySearch2dArrayTest {
|
||||
|
||||
// Assert that the requirement, that he target is in the middle column,
|
||||
// in an array with an even number of columns, and on the row "above" the middle row.
|
||||
assertEquals(arr[0].length % 2, 0);
|
||||
assertEquals(arr[arr.length / 2 - 1][arr[0].length / 2], target);
|
||||
assertEquals(0, arr[0].length % 2);
|
||||
assertEquals(target, arr[arr.length / 2 - 1][arr[0].length / 2]);
|
||||
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
|
||||
System.out.println(Arrays.toString(ans));
|
||||
assertEquals(0, ans[0]);
|
||||
|
||||
@@ -14,7 +14,7 @@ class KMPSearchTest {
|
||||
KMPSearch kmpSearch = new KMPSearch();
|
||||
int value = kmpSearch.kmpSearch(pat, txt);
|
||||
System.out.println(value);
|
||||
assertEquals(value, 10);
|
||||
assertEquals(10, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -25,7 +25,7 @@ class KMPSearchTest {
|
||||
KMPSearch kmpSearch = new KMPSearch();
|
||||
int value = kmpSearch.kmpSearch(pat, txt);
|
||||
System.out.println(value);
|
||||
assertEquals(value, 0);
|
||||
assertEquals(0, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -36,7 +36,7 @@ class KMPSearchTest {
|
||||
KMPSearch kmpSearch = new KMPSearch();
|
||||
int value = kmpSearch.kmpSearch(pat, txt);
|
||||
System.out.println(value);
|
||||
assertEquals(value, 4);
|
||||
assertEquals(4, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -47,7 +47,7 @@ class KMPSearchTest {
|
||||
KMPSearch kmpSearch = new KMPSearch();
|
||||
int value = kmpSearch.kmpSearch(pat, txt);
|
||||
System.out.println(value);
|
||||
assertEquals(value, 4);
|
||||
assertEquals(4, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,6 +58,6 @@ class KMPSearchTest {
|
||||
KMPSearch kmpSearch = new KMPSearch();
|
||||
int value = kmpSearch.kmpSearch(pat, txt);
|
||||
System.out.println(value);
|
||||
assertEquals(value, -1);
|
||||
assertEquals(-1, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ class QuickSelectTest {
|
||||
void quickSelectMedianOfThreeCharacters() {
|
||||
List<Character> elements = Arrays.asList('X', 'Z', 'Y');
|
||||
char actual = QuickSelect.select(elements, 1);
|
||||
assertEquals(actual, 'Y');
|
||||
assertEquals('Y', actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -58,7 +58,7 @@ class TopologicalSortTest {
|
||||
Exception exception = assertThrows(RuntimeException.class, () -> TopologicalSort.sort(graph));
|
||||
String expected = "This graph contains a cycle. No linear ordering is possible. "
|
||||
+ "Back edge: 6 -> 2";
|
||||
assertEquals(exception.getMessage(), expected);
|
||||
assertEquals(expected, exception.getMessage());
|
||||
}
|
||||
@Test
|
||||
void testEmptyGraph() {
|
||||
|
||||
@@ -24,7 +24,7 @@ public class WordLadderTest {
|
||||
public void testWordLadder() {
|
||||
|
||||
List<String> wordList1 = Arrays.asList("hot", "dot", "dog", "lot", "log", "cog");
|
||||
assertEquals(WordLadder.ladderLength("hit", "cog", wordList1), 5);
|
||||
assertEquals(5, WordLadder.ladderLength("hit", "cog", wordList1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +39,7 @@ public class WordLadderTest {
|
||||
public void testWordLadder2() {
|
||||
|
||||
List<String> wordList2 = Arrays.asList("hot", "dot", "dog", "lot", "log");
|
||||
assertEquals(WordLadder.ladderLength("hit", "cog", wordList2), 0);
|
||||
assertEquals(0, WordLadder.ladderLength("hit", "cog", wordList2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +54,7 @@ public class WordLadderTest {
|
||||
public void testWordLadder3() {
|
||||
|
||||
List<String> wordList3 = emptyList();
|
||||
assertEquals(WordLadder.ladderLength("hit", "cog", wordList3), 0);
|
||||
assertEquals(0, WordLadder.ladderLength("hit", "cog", wordList3));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
||||
@@ -9,8 +9,8 @@ public class ZigZagPatternTest {
|
||||
public void testZigZagPattern() {
|
||||
String input1 = "HelloWorldFromJava";
|
||||
String input2 = "javaIsAProgrammingLanguage";
|
||||
Assertions.assertEquals(ZigZagPattern.encode(input1, 4), "HooeWrrmalolFJvlda");
|
||||
Assertions.assertEquals(ZigZagPattern.encode(input2, 4), "jAaLgasPrmgaaevIrgmnnuaoig");
|
||||
Assertions.assertEquals("HooeWrrmalolFJvlda", ZigZagPattern.encode(input1, 4));
|
||||
Assertions.assertEquals("jAaLgasPrmgaaevIrgmnnuaoig", ZigZagPattern.encode(input2, 4));
|
||||
// Edge cases
|
||||
Assertions.assertEquals("ABC", ZigZagPattern.encode("ABC", 1)); // Single row
|
||||
Assertions.assertEquals("A", ZigZagPattern.encode("A", 2)); // numRows > length of string
|
||||
|
||||
Reference in New Issue
Block a user