Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Maths Sem1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jack.templeman
Maths Sem1
Commits
ed7fdbce
Commit
ed7fdbce
authored
Nov 28, 2018
by
jackt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first
parents
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
602 additions
and
0 deletions
+602
-0
.classpath
Maths assessment/.classpath
+9
-0
.gitignore
Maths assessment/.gitignore
+1
-0
.project
Maths assessment/.project
+17
-0
org.eclipse.jdt.core.prefs
Maths assessment/.settings/org.eclipse.jdt.core.prefs
+11
-0
Program.java
Maths assessment/src/Program.java
+283
-0
ProgramTest.java
Maths assessment/src/ProgramTest.java
+281
-0
No files found.
Maths assessment/.classpath
0 → 100644
View file @
ed7fdbce
<?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=
"con"
path=
"org.eclipse.jdt.junit.JUNIT_CONTAINER/5"
/>
<classpathentry
kind=
"src"
path=
"src"
/>
<classpathentry
kind=
"src"
path=
"maths"
/>
<classpathentry
excluding=
"src/|maths/"
kind=
"src"
path=
""
/>
<classpathentry
kind=
"output"
path=
"bin"
/>
</classpath>
Maths assessment/.gitignore
0 → 100644
View file @
ed7fdbce
/bin/
Maths assessment/.project
0 → 100644
View file @
ed7fdbce
<?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>
Maths assessment/.settings/org.eclipse.jdt.core.prefs
0 → 100644
View file @
ed7fdbce
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
Maths assessment/src/Program.java
0 → 100644
View file @
ed7fdbce
import
java.awt.List
;
import
java.util.Arrays
;
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
];
for
(
int
l
=
0
;
l
<
resultsArray
.
length
;
l
++)
{
String
binary
=
binaryArray
[
l
];
String
character
=
""
;
int
total
=
0
;
int
b
=
binary
.
length
()
-
1
;
int
c
=
l
-
1
;
resultsArray
[
c
]
=
total
;
for
(
int
a
=
0
;
a
<=
b
;
a
++)
{
if
(
a
==
0
)
{
total
=
0
;
}
char
theChar
=
binary
.
charAt
(
a
);
character
=
Character
.
toString
(
theChar
);
if
(
a
==
0
&&
character
.
equals
(
"1"
))
{
total
=
total
++;
continue
;
}
else
if
(
character
.
equals
(
"0"
)
&&
a
==
0
)
{
continue
;
}
switch
(
a
)
{
case
1
:
if
(
character
.
equals
(
"1"
))
{
total
=
total
+
2
;
continue
;
}
case
2
:
if
(
character
.
equals
(
"1"
))
{
total
=
total
+
4
;
continue
;
}
else
continue
;
case
3
:
if
(
character
.
equals
(
"1"
))
{
total
=
total
+
8
;
continue
;
}
else
continue
;
case
4
:
if
(
character
.
equals
(
"1"
))
{
total
=
total
+
16
;
continue
;
}
else
continue
;
case
5
:
if
(
character
.
equals
(
"1"
))
{
total
=
total
+
32
;
continue
;
}
else
continue
;
case
6
:
if
(
character
.
equals
(
"1"
))
{
total
=
total
+
64
;
continue
;
}
else
continue
;
case
7
:
if
(
character
.
equals
(
"1"
))
{
total
=
total
+
128
;
continue
;
}
else
break
;
case
8
:
if
(
character
.
equals
(
"1"
))
{
total
=
total
+
256
;
continue
;
}
}
resultsArray
[
l
-
1
]
=
total
;
}
}
return
resultsArray
;
}
public
static
int
[]
ConvertHexToInt
(
String
[]
hexArray
)
{
int
[]
resultsArray
=
new
int
[
hexArray
.
length
];
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
;
return
result
;
}
public
static
double
Mean
(
int
[]
input
)
{
double
output
=
0
;
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
;
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
;
return
output
;
}
public
static
double
HarmonicMean
(
int
[]
input
)
{
double
output
=
0
;
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
;
}
}
Maths assessment/src/ProgramTest.java
0 → 100644
View file @
ed7fdbce
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
org.junit.jupiter.api.Test
;
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
),
((
3
d
+
6
d
+
7
d
+
9
d
+
8
d
+
7
d
+
6
d
+
5
d
+
15
d
)
/
9
d
),
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
),
(
3
d
/
((
1
d
/
3
d
)
+
(
1
d
/
6
d
)
+
(
1
d
/
77
d
))),
0.1
);
}
@Test
void
testComplexSumFunctionA
()
{
int
[]
set
=
{
3
,
6
,
77
};
assertEquals
(
Program
.
ComplexSumFunctionA
(
set
),
(
1
d
+
Math
.
pow
(
6
d
/
2
d
,
0.5d
)
+
(
77
d
/
2
d
))
/
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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment