Commit a063e2e9 authored by jackt's avatar jackt

Finito

parent 4176483b
Pipeline #360 failed with stages
This diff is collapsed.
...@@ -7,275 +7,296 @@ class ProgramTest { ...@@ -7,275 +7,296 @@ class ProgramTest {
@Test @Test
void testConvertBinaryToInt() { void testConvertBinaryToInt() {
String[] input = { "010", "110", "111", "1010101" }; String[] input = {"010","110","111","1010101"};
int[] result = Program.ConvertBinaryToInt(input); int[] result = Program.ConvertBinaryToInt(input);
assertEquals(result[0], 2); assertEquals(result[0],2);
assertEquals(result[1], 6); assertEquals(result[1],6);
assertEquals(result[2], 7); assertEquals(result[2],7);
assertEquals(result[3], 85); assertEquals(result[3],85);
} }
@Test @Test
void testConvertBase3ToInt() { void testConvertBase3ToInt() {
String[] input = { "2", "12", "10", "111" }; String[] input = {"2","12","10","111"};
int[] result = Program.ConvertBase3ToInt(input); int[] result = Program.ConvertBase3ToInt(input);
assertEquals(result[0], 2); assertEquals(result[0],2);
assertEquals(result[1], 5); assertEquals(result[1],5);
assertEquals(result[2], 3); assertEquals(result[2],3);
assertEquals(result[3], 13); assertEquals(result[3],13);
} }
@Test @Test
void testConvertHexToInt() { void testConvertHexToInt() {
String[] input = { "50", "110", "FA", "B0", "F" }; String[] input = {"50","110","FA","B0","F"};
int[] result = Program.ConvertHexToInt(input); int[] result = Program.ConvertHexToInt(input);
assertEquals(result[0], 80); assertEquals(result[0],80);
assertEquals(result[1], 272); assertEquals(result[1],272);
assertEquals(result[2], 250); assertEquals(result[2],250);
assertEquals(result[3], 176); assertEquals(result[3],176);
assertEquals(result[4], 15); assertEquals(result[4],15);
} }
@Test @Test
void testConvertBase20ToInt() { void testConvertBase20ToInt() {
// 1s, 20s, 400s //1s, 20s, 400s
String[] input = {"50","110","FA","GH"};
int[] result = Program.ConvertBase20ToInt(input);
String[] input = { "50", "110", "FA", "GH" }; assertEquals(result[0],100);
assertEquals(result[1],420);
assertEquals(result[2],310);
assertEquals(result[3],(16*20)+17);
int[] result = Program.ConvertBase20ToInt(input);
assertEquals(result[0], 100);
assertEquals(result[1], 420);
assertEquals(result[2], 310);
assertEquals(result[3], (16 * 20) + 17);
} }
@Test @Test
void testUnion() { void testUnion() {
int[] setA = { 3, 6, 8, 4, 2, 1 }; int[] setA = {3,6,8,4,2,1};
int[] setB = { 3, 6, 7, 9, 8, 7, 6, 5, 15 }; int[] setB = {3,6,7,9,8,7,6,5,15};
int[] setC = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 15 }; int[] setC = {1,2,3,4,5,6,7,8,9,15};
int[] unionSet = Program.Union(setA, setB); int[] unionSet = Program.Union(setA, setB);
assertEquals(setC.length, unionSet.length); assertEquals(setC.length,unionSet.length);
for (int i : setC) { for(int i: setC) {
Boolean flag = false; Boolean flag = false;
for (int j : unionSet) { for(int j : unionSet) {
if (i == j) { if(i==j) {flag = true;}
flag = true;
}
}
assertTrue(flag);
} }
assertTrue(flag);
}
} }
@Test @Test
void testIntersection() { void testIntersection() {
int[] setA = { 3, 6, 8, 4, 2, 1 }; int[] setA = {3,6,8,4,2,1};
int[] setB = { 3, 6, 7, 9, 8, 7, 6, 5, 15 }; int[] setB = {3,6,7,9,8,7,6,5,15};
int[] setC = { 3, 6, 8 }; int[] setC = {3,6,8};
int[] interSet = Program.Intersection(setA, setB); int[] interSet = Program.Intersection(setA, setB);
assertEquals(setC.length, interSet.length); assertEquals(setC.length,interSet.length);
for (int i : setC) { for(int i: setC) {
Boolean flag = false; Boolean flag = false;
for (int j : interSet) { for(int j : interSet) {
if (i == j) { if(i==j) {flag = true;}
flag = true;
}
}
assertTrue(flag);
} }
assertTrue(flag);
}
} }
@Test @Test
void testDifference() { void testDifference() {
int[] setA = { 3, 6, 8, 4, 2, 1 }; int[] setA = {3,6,8,4,2,1};
int[] setB = { 3, 6, 7, 9, 8, 7, 6, 5, 15 }; int[] setB = {3,6,7,9,8,7,6,5,15};
int[] setC = { 4, 2, 1 }; int[] setC = {4,2,1};
int[] diffSet = Program.Difference(setA, setB); int[] diffSet = Program.Difference(setA, setB);
assertEquals(setC.length, diffSet.length); assertEquals(setC.length,diffSet.length);
for (int i : setC) { for(int i: setC) {
Boolean flag = false; Boolean flag = false;
for (int j : diffSet) { for(int j : diffSet) {
if (i == j) { if(i==j) {flag = true;}
flag = true;
}
}
assertTrue(flag);
} }
assertTrue(flag);
} }
}
@Test @Test
void testSum() { void testSum() {
int[] set = { 3, 6, 7, 9, 8, 7, 6, 5, 15 }; int[] set = {3,6,7,9,8,7,6,5,15};
assertEquals(Program.Sum(set), 3 + 6 + 7 + 9 + 8 + 7 + 6 + 5 + 15); assertEquals(Program.Sum(set),3+6+7+9+8+7+6+5+15);
} }
@Test @Test
void testMean() { void testMean() {
int[] set = { 3, 6, 7, 9, 8, 7, 6, 5, 15 }; int[] set = {3,6,7,9,8,7,6,5,15};
assertEquals(Program.Mean(set),((3d+6d+7d+9d+8d+7d+6d+5d+15d)/9d),0.01);
assertEquals(Program.Mean(set), ((3d + 6d + 7d + 9d + 8d + 7d + 6d + 5d + 15d) / 9d), 0.01);
} }
@Test @Test
void testMode() { void testMode() {
int[] set = { 3, 6, 7, 9, 8, 7, 7, 6, 5, 15 }; int[] set = {3,6,7,9,8,7,7,6,5,15};
assertEquals(Program.Mode(set), 7); assertEquals(Program.Mode(set),7);
} }
@Test @Test
void testMedian() { void testMedian() {
int[] set = { 3, 6, 7, 9, 8, 6, 7, 6, 5, 15 }; int[] set = {3,6,7,9,8,6,7,6,5,15};
assertEquals(Program.Median(set), 6.5d, 0.001); assertEquals(Program.Median(set),6.5d,0.001);
} }
@Test @Test
void testStandardDeviation() { void testStandardDeviation() {
int[] set = { 3, 6, 7, 9, 8, 6, 7, 6, 5, 15 }; int[] set = {3,6,7,9,8,6,7,6,5,15};
assertEquals(Program.StandardDeviation(set), 3.19d, 0.1); assertEquals(Program.StandardDeviation(set),3.19d,0.1);
} }
@Test @Test
void testRange() { void testRange() {
int[] set = { 15, 3, 7, 9, 8, 7, 7, 6, 5, 2 }; int[] set = {15,3,7,9,8,7,7,6,5,2};
assertEquals(Program.Range(set), 13); assertEquals(Program.Range(set),13);
} }
@Test @Test
void testHarmonicMean() { void testHarmonicMean() {
int[] set = { 3, 6, 77 }; int[] set = {3,6,77};
assertEquals(Program.HarmonicMean(set), (3d / ((1d / 3d) + (1d / 6d) + (1d / 77d))), 0.1);
assertEquals(Program.HarmonicMean(set),(3d/((1d/3d)+(1d/6d)+(1d/77d))),0.1);
} }
@Test @Test
void testComplexSumFunctionA() { void testComplexSumFunctionA() {
int[] set = { 3, 6, 77 }; int[] set = {3,6,77};
assertEquals(Program.ComplexSumFunctionA(set), assertEquals(Program.ComplexSumFunctionA(set),
(1d+
Math.pow(6d/2d, 0.5d)+
(77d/2d))
/6
,0.1);
}
@Test
void testMatrixScalar() {
int[][] matrix = {{1,2},
{3,4}};
(1d + Math.pow(6d / 2d, 0.5d) + (77d / 2d)) / 6 int[][] mScaled = Program.MatrixScalarMultiplication(matrix,11);
, 0.1); assertEquals(mScaled[0][0],11);
assertEquals(mScaled[0][1],22);
assertEquals(mScaled[1][0],33);
assertEquals(mScaled[1][1],44);
} }
@Test @Test
void testMatrixScalar() { void testComplexMatrixOperation() {
int[][] matrix = { { 1, 2 }, { 3, 4 } };
int[][] mScaled = Program.MatrixScalarMultiplication(matrix, 11); int[][] matrix = {{1,2},
{3,4}};
assertEquals(mScaled[0][0], 11); int[][] matrix2 = Program.ComplexMatrixOperation(matrix,matrix,11);
assertEquals(mScaled[0][1], 22);
assertEquals(mScaled[1][0], 33); assertEquals(matrix2[0][0],22);
assertEquals(mScaled[1][1], 44); assertEquals(matrix2[0][1],44);
assertEquals(matrix2[1][0],66);
assertEquals(matrix2[1][1],88);
}
/*
* @Test void testComplexMatrixOperation() {
*
* int[][] matrix = {{1,2}, {3,4}};
*
* int[][] matrix2 = Program.ComplexMatrixOperation(matrix,matrix,11);
*
* assertEquals(matrix2[0][0],22); assertEquals(matrix2[0][1],44);
* assertEquals(matrix2[1][0],66); assertEquals(matrix2[1][1],88);
*
*
*
*
* }
*/
}
@Test @Test
void testGenerateDistributionForSpecificDie() { void testGenerateDistributionForSpecificDie() {
double[] d = Program.GenerateRandomDistributionForSpecificDie(100000); double[] d = Program.GenerateRandomDistributionForSpecificDie(100000);
assertEquals(d[2479], 0.0012, 0.0001);
} assertEquals(d[2479],0.0012,0.0001);
}
@Test @Test
void testGenerateRandomDistribution() { void testGenerateRandomDistribution() {
assertEquals(Program.GenerateRandomDistribution(50, 5, 100000)[89], 0.0062, 0.0001); assertEquals(Program.GenerateRandomDistribution(50,5,100000)[89],0.0062,0.0001);
} }
@Test @Test
void testGetProbabilityOfResultOrHigher() { void testGetProbabilityOfResultOrHigher() {
double d = Program.GetProbabilityOfResultOrHigher(50, 10, 300); double d = Program.GetProbabilityOfResultOrHigher(50,10,300);
assertEquals(d, 0.16947000000000007, 0.0001); assertEquals(d,0.16947000000000007,0.0001);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment