Commit e2693a15 authored by Danie's avatar Danie

initial.

parents
Pipeline #441 failed with stages
<?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>Maths Assessment</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
import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
public class Program {
public static String[] binaryInput =
{
"0010010",
"0100100",
"0010010",
"0100010",
"0001001",
"0100000",
"0010001",
"1000010",
"1000100",
"0010100"
};
public static String[] hexInput =
{
"87",
"32",
"11",
"43",
"F1",
"97",
"42",
"56",
"FF",
"6B",
};
public static String[] base20Input =
{
"87",
"32",
"11",
"43",
"F1",
"97",
"42",
"56",
"FF",
"6B",
};
public static String[] base3input =
{
"0020010",
"0100200",
"0010010",
"0220010",
"0002201",
"0200020",
"0210021",
"1200010",
"1000100",
"0010100"
};
public static void main(String[] args) {
// TODO Auto-generated method stub
ConvertBinaryToInt(binaryInput);
}
public static int[] ConvertBinaryToInt(String[] binaryArray) {
int[] resultsArray = new int[binaryArray.length];
int wordTotal = 0;
for(int eachWord=0; eachWord<binaryArray.length;eachWord++) {
char[] characters = binaryArray[eachWord].toCharArray();
for(int i = 0; i < characters.length; i++) {
int index = (characters.length - i - 1);
double columnMultiplier = Math.pow(2, index);
if(characters[index]=='1') {
wordTotal=(int) (wordTotal + columnMultiplier);
}
}
resultsArray[eachWord] = wordTotal;
}
System.out.println(Arrays.toString(resultsArray));
return resultsArray;
}
public static int[] ConvertHexToInt(String[] hexArray) {
int[] resultsArray = new int[hexArray.length];
String hexidecimal = "0123456789ABCDEF";
int total = 0;
for(int eachHex = 0; eachHex < hexArray.length; eachHex++)
{
char[] hexChar = hexArray[eachHex].toCharArray();
for(int eachChar = 0; eachChar < hexChar.length; eachChar++ )
{
}
resultsArray[eachHex] = resultsArray[eachHex] + total;
}
return resultsArray;
}
public static int[] Union(int[] intArrayA, int[] intArrayB) {
ArrayList<Integer> unionList = new ArrayList<Integer>();
int[] resultsArray = new int[unionList.size()];
for(int i = 0; i<unionList.size(); i++) {
resultsArray[i] = unionList.get(i);
}
return resultsArray;
}
public static int[] Intersection(int[] intArrayA, int[] intArrayB) {
ArrayList<Integer> intersectList = new ArrayList<Integer>();
int[] resultsArray = new int[intersectList.size()];
for(int i = 0; i<intersectList.size(); i++) {
resultsArray[i] = intersectList.get(i);
}
return resultsArray;
}
public static int[] Difference(int[] intArrayA, int[] intArrayB) {
ArrayList<Integer> differenceList = new ArrayList<Integer>();
int[] resultsArray = new int[differenceList.size()];
for(int i = 0; i<differenceList.size(); i++) {
resultsArray[i] = differenceList.get(i);
}
return resultsArray;
}
public static int Sum (int[] input) {
int result = 0;
for(int i = 0; i < input.length; i++) {
result = result + input[i];
}
return result;
}
public static double Mean (int[] input) {
double output = 0;
for(int i = 0; i < input.length; i++) {
output = (output + input[i])/input.length;
}
return output;
}
public static int[] ConvertBase20ToInt(String[] b20array) {
int[] resultsArray = new int[b20array.length];
return resultsArray;
}
public static int Range (int[] input) {
int output = 0;
int minimumValue = input[0];
int highestValue = input[0];
for(int i = 1; i < input.length; i++) {
if(input[i] > highestValue) {
highestValue = input[i];
}
if(input[i] < minimumValue) {
minimumValue = input[i];
}
}
output = highestValue - minimumValue;
return output;
}
public static int[] ConvertBase3ToInt(String[] b3array) {
int[] resultsArray = new int[b3array.length];
return resultsArray;
}
public static int Mode (int[] input) {
int output = 0;
return output;
}
public static double Median (int[] input) {
int output = 0;
return output;
}
public static double StandardDeviation (int[] input) {
double output = 0;
//mean
for(int i = 0; i < input.length; i++) {
output = (output + input[i])/input.length;
}
int result = 0;
for(int i = 0; i < input.length; i++) {
result = result + input[i];
}
output = Math.sqrt(((result-output)*(result-output)/(input.length-1)));
return output;
}
public static double HarmonicMean (int[] input) {
double output = 0;
for(int i = 0; i < input.length; i++) {
output = input.length/(1/(output + input[i]));
}
return output;
}
public static double ComplexSumFunctionA (int[] input) {
double output = 0;
return output;
}
public static int[][] MatrixScalarMultiplication (int[][] matrix, int scalar){
int[][] resultMatrix = new int[matrix.length][matrix[0].length];
return resultMatrix;
}
public static int[][] ComplexMatrixOperation (int[][] matrix, int scalar){
int[][] resultMatrix = new int[matrix.length][matrix[0].length];
return resultMatrix;
}
public static double[] GenerateRandomDistributionForSpecificDie(int iterations) {
double[] resultsArray = new double[5121];
Random rng = new Random(1234);
for(int i = 0; i<iterations; i++) {
}
return resultsArray;
}
public static double[] GenerateRandomDistribution(int dieSides, int rolls, int iterations) {
double[] resultsArray = new double[(dieSides*rolls)+1];
Random rng = new Random(1234);
for(int i = 0; i<iterations; i++) {
}
return resultsArray;
}
public static double GetProbabilityOfResultOrHigher(int dieSides, int rolls, int sum) {
double[] distribution = GenerateRandomDistribution(dieSides,rolls,100000);
double result = 0;
return result;
}
}
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class ProgramTestFixed {
@Test
void testConvertBinaryToInt() {
String[] input = {"010","110","111","1010101"};
int[] result = Program.ConvertBinaryToInt(input);
assertEquals(result[0],2);
assertEquals(result[1],6);
assertEquals(result[2],7);
assertEquals(result[3],85);
}
@Test
void testConvertBase3ToInt() {
String[] input = {"2","12","10","111"};
int[] result = Program.ConvertBase3ToInt(input);
assertEquals(result[0],2);
assertEquals(result[1],5);
assertEquals(result[2],3);
assertEquals(result[3],13);
}
@Test
void testConvertHexToInt() {
String[] input = {"50","110","FA","B0","F"};
int[] result = Program.ConvertHexToInt(input);
assertEquals(result[0],80);
assertEquals(result[1],272);
assertEquals(result[2],250);
assertEquals(result[3],176);
assertEquals(result[4],15);
}
@Test
void testConvertBase20ToInt() {
//1s, 20s, 400s
String[] input = {"50","110","FA","GH"};
int[] result = Program.ConvertBase20ToInt(input);
assertEquals(result[0],100);
assertEquals(result[1],420);
assertEquals(result[2],310);
assertEquals(result[3],(16*20)+17);
}
@Test
void testUnion() {
int[] setA = {3,6,8,4,2,1};
int[] setB = {3,6,7,9,8,7,6,5,15};
int[] setC = {1,2,3,4,5,6,7,8,9,15};
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 = {3,6,8,4,2,1};
int[] setB = {3,6,7,9,8,7,6,5,15};
int[] setC = {3,6,8};
int[] interSet = Program.Intersection(setA, setB);
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 = {3,6,8,4,2,1};
int[] setB = {3,6,7,9,8,7,6,5,15};
int[] setC = {4,2,1};
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 = {3,6,7,9,8,7,6,5,15};
assertEquals(Program.Sum(set),3+6+7+9+8+7+6+5+15);
}
@Test
void testMean() {
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);
}
@Test
void testMode() {
int[] set = {3,6,7,9,8,7,7,6,5,15};
assertEquals(Program.Mode(set),7);
}
@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 = {15,3,7,9,8,7,7,6,5,2};
assertEquals(Program.Range(set),13);
}
@Test
void testHarmonicMean() {
int[] set = {3,6,77};
assertEquals(Program.HarmonicMean(set),(3d/((1d/3d)+(1d/6d)+(1d/77d))),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