Commit 7642908a authored by iieliteiisquady's avatar iieliteiisquady

First Commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MathsAssesment</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
This diff is collapsed.
import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
class ProgramTestFixed {
@Test
void testConvertBinaryToInt() {
String[] input = {"1010","110","111","11010101"};
int[] result = Program.ConvertBinaryToInt(input);
assertEquals(result[0],8+2);
assertEquals(result[1],6);
assertEquals(result[2],7);
assertEquals(result[3],1+4+16+64+128);
}
@Test
void testConvertBase3ToInt() {
String[] input = {"2","22","10","112"};
int[] result = Program.ConvertBase3ToInt(input);
assertEquals(result[0],2);
assertEquals(result[1],6+2);
assertEquals(result[2],3);
assertEquals(result[3],14);
}
@Test
void testConvertHexToInt() {
String[] input = {"50","110","FA","B1","F"};
int[] result = Program.ConvertHexToInt(input);
assertEquals(result[0],80);
assertEquals(result[1],272);
assertEquals(result[2],250);
assertEquals(result[3],177);
assertEquals(result[4],15);
}
@Test
void testConvertBase20ToInt() {
//1s, 20s, 400s
String[] input = {"50","110","0","GH"};
int[] result = Program.ConvertBase20ToInt(input);
assertEquals(result[0],100);
assertEquals(result[1],420);
assertEquals(result[2],0);
assertEquals(result[3],(16*20)+17);
}
@Test
void testUnion() {
int[] setA = {1,2,3};
int[] setB = {2,3,4,5};
int[] setC = {1,2,3,4,5};
int[] unionSet = Program.Union(setA, setB);
assertEquals(setC.length,unionSet.length);
for(int i: setC) {
Boolean flag = false;
for(int j : unionSet) {
if(i==j) {flag = true;}
}
assertTrue(flag);
}
}
@Test
void testIntersection() {
int[] setA = {2,4,6,8,10,12,14,16,18,20};
int[] setB = {1,2,4,8,16,32,64};
int[] setC = {2,4,8,16};
int[] interSet = Program.Intersection(setA, setB);
System.out.println(Arrays.toString(interSet));
assertEquals(setC.length,interSet.length);
for(int i: setC) {
Boolean flag = false;
for(int j : interSet) {
if(i==j) {flag = true;}
}
assertTrue(flag);
}
}
@Test
void testDifference() {
int[] setA = {0,1,2,3,4,5,6,7,8,9,10};
int[] setB = {2,4,6,8,10};
int[] setC = {0,1,3,5,7,9};
int[] diffSet = Program.Difference(setA, setB);
assertEquals(setC.length,diffSet.length);
for(int i: setC) {
Boolean flag = false;
for(int j : diffSet) {
if(i==j) {flag = true;}
}
assertTrue(flag);
}
}
@Test
void testSum() {
int[] set = {5,10,15,20,25,30,35,40};
assertEquals(Program.Sum(set),5+10+15+20+25+30+35+40);
}
@Test
void testMean() {
int[] set = {1,2,3,4,5,6,666};
assertEquals(Program.Mean(set),((1d+2d+3d+4d+5d+6d+666d)/7d),0.01);
}
@Test
void testMode() {
int[] set = {1,1,1,1,2,3,4,5,6,7,8,9,10,10,10,2};
assertEquals(Program.Mode(set),1);
}
@Test
void testMedian() {
int[] set = {3,6,7,9,8,6,7,6,5,15};
assertEquals(Program.Median(set),6.5d,0.001);
}
@Test
void testStandardDeviation() {
int[] set = {3,6,7,9,8,6,7,6,5,15};
assertEquals(Program.StandardDeviation(set),3.19d,0.1);
}
@Test
void testRange() {
int[] set = {150,3,7,9,8,7,7,6,5,0};
assertEquals(Program.Range(set),150);
}
@Test
void testHarmonicMean() {
int[] set = {3,6,4};
assertEquals(Program.HarmonicMean(set),(3d/((1d/3d)+(1d/6d)+(1d/4d))),0.1);
}
@Test
void testComplexSumFunctionA() {
int[] set = {3,6,77};
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}};
int[][] mScaled = Program.MatrixScalarMultiplication(matrix,11);
assertEquals(mScaled[0][0],11);
assertEquals(mScaled[0][1],22);
assertEquals(mScaled[1][0],33);
assertEquals(mScaled[1][1],44);
}
@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
void testGenerateDistributionForSpecificDie() {
double[] d = Program.GenerateRandomDistributionForSpecificDie(100000);
assertEquals(d[2479],0.0012,0.0001);
}
@Test
void testGenerateRandomDistribution() {
assertEquals(Program.GenerateRandomDistribution(50,5,100000)[89],0.0062,0.0001);
}
@Test
void testGetProbabilityOfResultOrHigher() {
double d = Program.GetProbabilityOfResultOrHigher(50,10,300);
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