Commit a063e2e9 authored by jackt's avatar jackt

Finito

parent 4176483b
Pipeline #360 failed with stages
...@@ -2,6 +2,7 @@ import java.awt.List; ...@@ -2,6 +2,7 @@ import java.awt.List;
import java.util.Arrays; import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
import java.lang.Math;
public class Program { public class Program {
...@@ -23,122 +24,253 @@ public class Program { ...@@ -23,122 +24,253 @@ public class Program {
public static int[] ConvertBinaryToInt(String[] binaryArray) { public static int[] ConvertBinaryToInt(String[] binaryArray) {
int[] resultsArray = new int[binaryArray.length]; int[] resultsArray = new int[binaryArray.length];
{
int iA = 0;
int iB = 0;
int iD = binaryArray.length - 1;
int iE = 0;
Double dA = 0.0;
for (iA = 0; iA <= iD; iA++) {
String sA = binaryArray[iA];
iE = binaryArray[iA].length() - 1;
int total = 0;
int iC = 100;
for (int l = 0; l < resultsArray.length; l++) { for (iB = 0; iB <= iE; iB++) {
String binary = binaryArray[l]; if (iC == 100) {
String character = ""; iC = iE;
int total = 0; }
int b = binary.length() -1; char cA = sA.charAt(iB);
int c = l; String sB = Character.toString(cA);
int d = resultsArray[0];
int e = resultsArray[1];
int f = resultsArray[2];
int g = resultsArray[3];
for (int a = 0; a <= b; a++) { switch (sB) {
case "0": {
dA = Math.pow(2, iC) * 0;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "1": {
dA = Math.pow(2, iC) * 1;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
}
}
}
return resultsArray;
}
if (a == 0)
{
total = 0;
} }
char theChar = binary.charAt(a); public static int[] ConvertHexToInt(String[] hexArray) {
character = Character.toString(theChar);
if (a == 0 && character.equals("1")) int[] resultsArray = new int[hexArray.length];
{ {
total = total++; int iA = 0;
int iB = 0;
int iD = hexArray.length - 1;
int iE = 0;
Double dA = 0.0;
for (iA = 0; iA <= iD; iA++) {
String sA = hexArray[iA];
iE = hexArray[iA].length() - 1;
int total = 0;
int iC = 100;
for (iB = 0; iB <= iE; iB++) {
if (iC == 100) {
iC = iE;
} }
char cA = sA.charAt(iB);
String sB = Character.toString(cA);
if (character.equals("0") && a==0) switch (sB) {
{
case "0": {
dA = Math.pow(16, iC) * 0;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
} }
case "1": {
switch (a) { dA = Math.pow(16, iC) * 1;
case 1: total = total + dA.intValue();
if (character.equals("1")) { resultsArray[iA] = total;
total = total + 2; iC--;
resultsArray[l] = total;
continue; continue;
} }
case 2: case "2": {
if (character.equals("1")) { dA = Math.pow(16, iC) * 2;
total = total + 4; total = total + dA.intValue();
resultsArray[l] = total; resultsArray[iA] = total;
iC--;
continue; continue;
} else }
case "3": {
dA = Math.pow(16, iC) * 3;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
case 3: }
if (character.equals("1")) { case "4": {
total = total + 8; dA = Math.pow(16, iC) * 4;
resultsArray[l] = total; total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
} else }
case "5": {
dA = Math.pow(16, iC) * 5;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
case 4: }
if (character.equals("1")) { case "6": {
total = total + 16; dA = Math.pow(16, iC) * 6;
resultsArray[l] = total; total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
} else }
case "7": {
dA = Math.pow(16, iC) * 7;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
case 5: }
if (character.equals("1")) { case "8": {
total = total + 32; dA = Math.pow(16, iC) * 8;
resultsArray[l] = total; total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "9": {
dA = Math.pow(16, iC) * 9;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
} else }
case "A": {
dA = Math.pow(16, iC) * 10;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
case 6: }
if (character.equals("1")) { case "B": {
total = total + 64; dA = Math.pow(16, iC) * 11;
resultsArray[l] = total; total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "C": {
dA = Math.pow(16, iC) * 12;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
} else }
case "D": {
dA = Math.pow(16, iC) * 13;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
case 7: }
if (character.equals("1")) { case "E": {
total = total + 128; dA = Math.pow(16, iC) * 14;
resultsArray[l] = total; total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue; continue;
} else }
break; case "F": {
case 8: dA = Math.pow(16, iC) * 15;
if (character.equals("1")) { total = total + dA.intValue();
total = total + 256; resultsArray[iA] = total;
resultsArray[l] = total; iC--;
continue; continue;
} }
} }
resultsArray[l-1] = total;
} }
} }
return resultsArray; return resultsArray;
} }
}
public static int[] ConvertHexToInt(String[] hexArray) { public static int[] Union(int[] intArrayA, int[] intArrayB) {
int[] resultsArray = new int[hexArray.length]; ArrayList<Integer> unionList = new ArrayList<Integer>();
return resultsArray; int[] resultsArray = new int[unionList.size()];
int currentCount = 0;
int iVal = 0;
int jVal = 0;
int z = 0;
int y = 0;
int a = intArrayB.length;
for (int i = 0; i < intArrayA.length; i++) {
z = intArrayA[i];
iVal = 0;
if (i == 0 && unionList.size() == 0) {
unionList.add(intArrayA[i]);
continue;
} }
public static int[] Union(int[] intArrayA, int[] intArrayB) { if (i != 0) {
for (int k = 0; k < unionList.size(); k++) {
if (intArrayA[i] == unionList.get(k)) {
iVal++;
}
}
if (iVal == 0) {
unionList.add(intArrayA[i]);
}
}
}
ArrayList<Integer> unionList = new ArrayList<Integer>(); for (int i = 0; i < intArrayB.length ; i++)
{
;
iVal = 0;
for (int k = 0; k < unionList.size(); k++) {
int proof = unionList.get(k);
int compare = intArrayB[i];
if (intArrayB[i] == unionList.get(k)) {
iVal++;
}
}
if (iVal == 0) {
unionList.add(intArrayB[i]);
int[] resultsArray = new int[unionList.size()];
for (int i = 0; i < unionList.size(); i++) {
resultsArray[i] = unionList.get(i);
} }
return resultsArray; }
resultsArray = unionList.stream().mapToInt(g -> g).toArray();
Arrays.sort(resultsArray);
return resultsArray;
} }
public static int[] Intersection(int[] intArrayA, int[] intArrayB) { public static int[] Intersection(int[] intArrayA, int[] intArrayB) {
...@@ -146,23 +278,69 @@ public class Program { ...@@ -146,23 +278,69 @@ public class Program {
ArrayList<Integer> intersectList = new ArrayList<Integer>(); ArrayList<Integer> intersectList = new ArrayList<Integer>();
int[] resultsArray = new int[intersectList.size()]; int[] resultsArray = new int[intersectList.size()];
for (int i = 0; i < intersectList.size(); i++) { int currentCount = 0;
resultsArray[i] = intersectList.get(i); int iVal = 0;
} int jVal = 0;
int z = 0;
int y = 0;
int a = intArrayB.length;
for (int i = 0; i < intArrayA.length; i++) {
for (int j = 0; j < intArrayB.length; j++) {
z = intArrayA[i];
y = intArrayB[j];
iVal = 0;
if (intArrayA[i] == intArrayB[j] && i == 0) {
intersectList.add(intArrayA[i]);
}
if (intArrayA[i] == intArrayB[j] && i != 0) {
for (int k = 0; k < intersectList.size(); k++) {
if (intArrayA[i] == intersectList.get(k)) {
iVal++;
}
}
if (iVal == 0) {
intersectList.add(intArrayA[i]);
}
}
}
}
resultsArray = intersectList.stream().mapToInt(i -> i).toArray();
return resultsArray; return resultsArray;
} }
public static int[] Difference(int[] intArrayA, int[] intArrayB) { public static int[] Difference(int[] intArrayA, int[] intArrayB) {
ArrayList<Integer> differenceList = new ArrayList<Integer>(); ArrayList<Integer> differenceList = new ArrayList<Integer>();
int totalA = 0;
int totalB = 0;
int[] resultsArray = new int[differenceList.size()]; int[] resultsArray = new int[differenceList.size()];
for (int i = 0; i < differenceList.size(); i++) { int currentCount = 0;
resultsArray[i] = differenceList.get(i); int iVal = 0;
int jVal = 0;
for (int i = 0; i < intArrayA.length; i++) {
currentCount = 0;
for (int j = 0; j < intArrayB.length; j++) {
iVal = intArrayA[i];
jVal = intArrayB[j];
if (iVal == jVal) {
currentCount++;
continue;
} }
}
if (currentCount == 0) {
differenceList.add(iVal);
}
}
resultsArray = differenceList.stream().mapToInt(i -> i).toArray();
Arrays.sort(resultsArray);
return resultsArray; return resultsArray;
} }
...@@ -170,6 +348,12 @@ public class Program { ...@@ -170,6 +348,12 @@ public class Program {
public static int Sum(int[] input) { public static int Sum(int[] input) {
int result = 0; int result = 0;
int length = 0;
length = input.length;
for (int i = 0; i < length; i++) {
result += input[i];
}
return result; return result;
...@@ -178,7 +362,13 @@ public class Program { ...@@ -178,7 +362,13 @@ public class Program {
public static double Mean(int[] input) { public static double Mean(int[] input) {
double output = 0; double output = 0;
int length = input.length;
double total = 0;
for (int i = 0; i < length; i++) {
total += input[i];
}
output = total / length;
return output; return output;
} }
...@@ -186,13 +376,184 @@ public class Program { ...@@ -186,13 +376,184 @@ public class Program {
int[] resultsArray = new int[b20array.length]; int[] resultsArray = new int[b20array.length];
int iA = 0;
int iB = 0;
int iD = b20array.length - 1;
int iE = 0;
Double dA = 0.0;
for (iA = 0; iA <= iD; iA++) {
String sA = b20array[iA];
iE = b20array[iA].length() - 1;
int total = 0;
int iC = 100;
for (iB = 0; iB <= iE; iB++) {
if (iC == 100) {
iC = iE;
}
char cA = sA.charAt(iB);
String sB = Character.toString(cA);
switch (sB) {
case "0": {
dA = Math.pow(20, iC) * 0;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "1": {
dA = Math.pow(20, iC) * 1;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "2": {
dA = Math.pow(20, iC) * 2;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "3": {
dA = Math.pow(20, iC) * 3;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "4": {
dA = Math.pow(20, iC) * 4;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "5": {
dA = Math.pow(20, iC) * 5;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "6": {
dA = Math.pow(20, iC) * 6;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "7": {
dA = Math.pow(20, iC) * 7;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "8": {
dA = Math.pow(20, iC) * 8;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "9": {
dA = Math.pow(20, iC) * 9;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "A": {
dA = Math.pow(20, iC) * 10;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "B": {
dA = Math.pow(20, iC) * 11;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "C": {
dA = Math.pow(20, iC) * 12;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "D": {
dA = Math.pow(20, iC) * 13;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "E": {
dA = Math.pow(20, iC) * 14;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "F": {
dA = Math.pow(20, iC) * 15;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "G": {
dA = Math.pow(20, iC) * 16;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "H": {
dA = Math.pow(20, iC) * 17;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "I": {
dA = Math.pow(20, iC) * 18;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "J": {
dA = Math.pow(20, iC) * 19;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
}
}
}
return resultsArray; return resultsArray;
} }
public static int Range(int[] input) { public static int Range(int[] input) {
int output = 0; int length = input.length - 1;
int output;
Arrays.sort(input);
output = input[length] - input[0];
return output; return output;
} }
...@@ -201,6 +562,52 @@ public class Program { ...@@ -201,6 +562,52 @@ public class Program {
int[] resultsArray = new int[b3array.length]; int[] resultsArray = new int[b3array.length];
int iA = 0;
int iB = 0;
int iD = b3array.length - 1;
int iE = 0;
Double dA = 0.0;
for (iA = 0; iA <= iD; iA++) {
String sA = b3array[iA];
iE = b3array[iA].length() - 1;
int total = 0;
int iC = 100;
for (iB = 0; iB <= iE; iB++) {
if (iC == 100) {
iC = iE;
}
char cA = sA.charAt(iB);
String sB = Character.toString(cA);
switch (sB) {
case "0": {
dA = Math.pow(3, iC) * 0;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "1": {
dA = Math.pow(3, iC) * 1;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
case "2": {
dA = Math.pow(3, iC) * 2;
total = total + dA.intValue();
resultsArray[iA] = total;
iC--;
continue;
}
}
}
}
return resultsArray; return resultsArray;
} }
...@@ -208,13 +615,54 @@ public class Program { ...@@ -208,13 +615,54 @@ public class Program {
public static int Mode(int[] input) { public static int Mode(int[] input) {
int output = 0; int output = 0;
int highestCount = 0;
int currentCount = 0;
int highestVal = 0;
int iVal = 0;
int jVal = 0;
for (int i = 0; i < input.length; i++) {
currentCount = 0;
for (int j = 0; j < input.length; j++) {
iVal = input[i];
jVal = input[j];
if (i != j && iVal == jVal) {
currentCount++;
}
if (currentCount > highestCount) {
highestCount = currentCount;
output = input[i];
}
}
}
return output; return output;
} }
public static double Median(int[] input) { public static double Median(int[] input) {
int output = 0; Arrays.sort(input);
;
int length;
double output = 0;
double modeA;
double modeB;
length = input.length;
Arrays.sort(input);
if (input.length % 2 == 0) {
modeA = length / 2;
modeB = modeA + 1;
double divisible = input[(int) modeB - 1] - input[(int) modeA - 1];
divisible /= 2;
output = input[(int) modeA - 1] + divisible;
}
if (input.length % 2 != 0) {
modeA = input.length / 2;
output = input[(int) modeA];
}
return output; return output;
} }
...@@ -222,20 +670,63 @@ public class Program { ...@@ -222,20 +670,63 @@ public class Program {
public static double StandardDeviation(int[] input) { public static double StandardDeviation(int[] input) {
double output = 0; double output = 0;
double xBar = 0;
double total = 0;
double i = 0;
int a = 0;
double top = 0;
double divisor = 0;
double out = 0;
for (i = 0; i < input.length; i++) {
a = (int) i;
total += input[a];
}
xBar = total / input.length;
for (int j = 0; j < input.length; j++) {
a = (int) j;
top = input[a] - xBar;
divisor = input.length - 1;
out = Math.pow(top, 2);
output += out;
}
output /= divisor;
output = Math.sqrt(output);
return output; return output;
} }
public static double HarmonicMean(int[] input) { public static double HarmonicMean(int[] input) {
double output = 0; double output = 0;
double c = 0;
double a = 0;
for (int i = 0; i < input.length; i++) {
a = input[i];
c = c + (1 / a);
output = (input.length) / c;
}
return output; return output;
} }
public static double ComplexSumFunctionA(int[] input) { public static double ComplexSumFunctionA(int[] input) {
double output = 0; double output = 0;
double a = 0;
double b = 0;
double c = 0;
double d = 0;
for (int i = 0; i < input.length; i++)
{
a = input[i] / 2;
b = input.length + 3;
d = i;
c = d / 2;
output = output + (Math.pow(a, c)) / b;
;
}
return output; return output;
} }
...@@ -244,26 +735,72 @@ public class Program { ...@@ -244,26 +735,72 @@ public class Program {
int[][] resultMatrix = new int[matrix.length][matrix[0].length]; int[][] resultMatrix = new int[matrix.length][matrix[0].length];
int mat = 0;
int matTwo = 0;
for (int i = 0; i < matrix[0].length; i++) {
for (int j = 0; j < matrix[1].length; j++) {
resultMatrix[i][j] = matrix[i][j] * 11;
}
}
return resultMatrix; return resultMatrix;
} }
public static int[][] ComplexMatrixOperation(int[][] matrix, int scalar) { public static int[][] ComplexMatrixOperation (int[][] matrixA, int[][] matrixB, int scalar){
int[][] resultMatrix = new int[matrix.length][matrix[0].length]; int[][] resultMatrix = new int[matrixA[0].length][matrixA[0].length];
int mat = 0;
int matTwo = 0;
for (int i = 0; i < matrixA[0].length; i++) {
for (int j = 0; j < matrixA[1].length; j++) {
resultMatrix[i][j] = matrixA[i][j] + matrixB[i][j];
}
}
for (int i = 0; i < resultMatrix[0].length; i++) {
for (int j = 0; j < resultMatrix[1].length; j++) {
resultMatrix[i][j] = resultMatrix[i][j] * 11;
}
}
return resultMatrix; return resultMatrix;
} }
public static double[] GenerateRandomDistributionForSpecificDie(int iterations) { public static double[] GenerateRandomDistributionForSpecificDie(int iterations) {
double[] resultsArray = new double[5121]; double[] resultsArray = new double[5121];
int n = 0;
int z = 0;
Random rng = new Random(1234); Random rng = new Random(1234);
for (int i = 0; i < iterations; i++) { for (int i = 0; i < iterations; i++) {
int total = 0;
for (int j = 0; j <20; j++)
{
n = rng.nextInt(256) + 1;
total += n;
}
resultsArray[total]++;
} }
for ( int i = 0; i < 5121; i++)
{
if (resultsArray[i] ==0)
{
continue;
}
resultsArray[i] = resultsArray[i]/iterations;
double a = (resultsArray[i]/iterations);
}
return resultsArray; return resultsArray;
} }
...@@ -271,10 +808,32 @@ public class Program { ...@@ -271,10 +808,32 @@ public class Program {
double[] resultsArray = new double[(dieSides * rolls) + 1]; double[] resultsArray = new double[(dieSides * rolls) + 1];
int n = 0;
int z = 0;
Random rng = new Random(1234); Random rng = new Random(1234);
for (int i = 0; i < iterations; i++) { for (int i = 0; i < iterations; i++) {
int total = 0;
for (int j = 0; j <rolls; j++)
{
n = rng.nextInt(dieSides) + 1;
total += n;
}
resultsArray[total]++;
}
for ( int i = 0; i < dieSides*rolls; i++)
{
if (resultsArray[i] ==0)
{
continue;
}
resultsArray[i] = resultsArray[i]/iterations;
double a = (resultsArray[i]/iterations);
} }
return resultsArray; return resultsArray;
...@@ -284,8 +843,23 @@ public class Program { ...@@ -284,8 +843,23 @@ public class Program {
double[] distribution = GenerateRandomDistribution(dieSides, rolls, 100000); double[] distribution = GenerateRandomDistribution(dieSides, rolls, 100000);
double result = 0;
double[] resultsArray = new double[(dieSides * rolls) + 1];
double iterations = 100000;
double n = 0;
double y = 0;
System.out.println(Arrays.toString(distribution));
for ( y = sum; y < dieSides*rolls; y++)
{
double e = distribution[(int)y];
n += distribution[(int)y];
}
double result = 0;
result = n;
return result; return result;
} }
......
...@@ -7,83 +7,87 @@ class ProgramTest { ...@@ -7,83 +7,87 @@ 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" }; String[] input = {"50","110","FA","GH"};
int[] result = Program.ConvertBase20ToInt(input); int[] result = Program.ConvertBase20ToInt(input);
assertEquals(result[0], 100); assertEquals(result[0],100);
assertEquals(result[1], 420); assertEquals(result[1],420);
assertEquals(result[2], 310); assertEquals(result[2],310);
assertEquals(result[3], (16 * 20) + 17); 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;
}
} }
...@@ -96,24 +100,22 @@ class ProgramTest { ...@@ -96,24 +100,22 @@ class ProgramTest {
@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;
}
} }
...@@ -123,27 +125,26 @@ class ProgramTest { ...@@ -123,27 +125,26 @@ class ProgramTest {
} }
@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;
}
} }
...@@ -156,126 +157,146 @@ class ProgramTest { ...@@ -156,126 +157,146 @@ class ProgramTest {
@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); (1d+
Math.pow(6d/2d, 0.5d)+
(77d/2d))
/6
,0.1);
} }
@Test @Test
void testMatrixScalar() { void testMatrixScalar() {
int[][] matrix = { { 1, 2 }, { 3, 4 } }; 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);
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 @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