Commit f3ffae2f authored by samuelboulton's avatar samuelboulton

making repository

parents
Pipeline #410 canceled 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-10">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<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>Program</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=10
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=10
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.release=enabled
org.eclipse.jdt.core.compiler.source=10
import java.awt.List;
import java.util.ArrayList;
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
}
public static int[] ConvertBinaryToInt(String[] binaryArray) {
int[] resultsArray = new int[binaryArray.length];
/*Needs a lot of work.
char[] binCA = binaryInput[0].toCharArray();
int binTotal = 0;
int binCM = 0;
for (int i = 0; i < binCA.length; i++) {
int binIndex = binCA.length - i - 1;
if (binCA[binIndex] == '1') {
binTotal = binTotal + binCM;
}
binCM = binCM * 2;
}
System.out.println(binTotal);
*/
// loop to go round each string, and do something in the string to characterise it.
return resultsArray;
}
public static int[] ConvertHexToInt(String[] hexArray) {
int[] resultsArray = new int[hexArray.length];
// same on this question
return resultsArray;
}
public static int[] Union(int[] intArrayA, int[] intArrayB) {
ArrayList<Integer> unionList = new ArrayList<Integer>();
/*this is the same as the intersection
for(int i = 0; i < intArrayA.length; i++)
{
for(int k = 0; k < intArrayB.length; k++)
{
if(intArrayA[i] == intArrayB[i])
{
}
}
}
*/
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>();
// **************** Ask how do i return it and where does the output go???*****************
/*
//looking through intArrayA
for(int j = 0; j < intArrayA.length; j++)
{
// looking through intArrayB
for(int k = 0; k < intArrayB.length; k++)
{
// Working out what is used in both arrays
if(intArrayA[j] == intArrayB[k])
{
}
}
}*/
//This was here
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>();
/*
for(int j = 0; j < intArrayA.length; j++)
{
for(int k = 0; k < intArrayB.length; k++)
{
if(intArrayA[j] != intArrayB[k])
{
}
}
}
*/
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;
// DONE AND PASSED TEST
// the for loop goes through each number and does the calculation each time.
for(int i = 0; i < input.length; i++)
{
result = result + input[i];
}
return result;
}
public static double Mean (int[] input) {
double output = 0;
// DONE AND PASSED TEST
// for loop that goes through each number and calculates the output each time.
for(int i = 0; i < input.length; i++)
{
output = output + input[i];
}
// the output result is divided by the length of the set of numbers.
return output / input.length;
}
public static int[] ConvertBase20ToInt(String[] b20array) {
int[] resultsArray = new int[b20array.length];
return resultsArray;
}
public static int Range (int[] input) {
int output = 0;
// DONE AND PASSED TEST
// Declaring the highest and lowest integers
int highest = input[0];
int lowest = input[0];
// finding the highest out of the array
for(int i = 0; i < input.length; i++)
{
if(input[i] > highest)
{
highest = input[i];
}
}
// finding the lowest of the array
for(int j = 0; j < input.length; j++)
{
if(input[j] < lowest)
{
lowest = input[j];
}
}
// calculating the range
output = highest - lowest;
return output;
}
public static int[] ConvertBase3ToInt(String[] b3array) {
int[] resultsArray = new int[b3array.length];
return resultsArray;
}
public static int Mode (int[] input) {
// DONE AND PASSED TEST
int output = 0;
// declaring topCount integer for calculations.
int topCount = 0;
// first for loop to calculate the counts of each number
for (int j = 0; j < input.length; ++j)
{
int count = 0;
// second for loop.
for (int k = 0; k < input.length; ++k)
{
if (input[j] == input[k])
++count;
}
// if statement to calculate which number has the highest count.
if (count > topCount)
{
// declaring the mode into output
topCount = count;
output = input[j];
}
}
return output;
}
public static double Median (int[] input) {
int output = 0;
return output;
}
public static double StandardDeviation (int[] input) {
double output = 0;
// should be working!
float mean = 0;
float totalMean = 0 ;
for( int i = 0; i<input.length; i++)
{
mean = mean + i;
}
totalMean = mean / input.length;
for(int j = 0; j<input.length; j++)
{
output = output + j + (j - totalMean)*(j - totalMean);
}
output = output / (input.length - 1);
output = Math.sqrt(output);
return output;
}
public static double HarmonicMean (int[] input) {
double output = 0;
double sum = 0;
// ASK WHY THIS IS WRONG
for(int i = 0; i<input.length; i++)
{
sum = sum + 1 / input[i];
}
output = input.length / sum;
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;
/*
Test your work with these unit tests.
Can work from home on this one unless you want specific help.
*/
class ProgramTest {
@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