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
a063e2e9
Commit
a063e2e9
authored
Nov 30, 2018
by
jackt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finito
parent
4176483b
Pipeline
#360
failed with stages
Changes
2
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
861 additions
and
266 deletions
+861
-266
Program.java
Maths assessment/src/Program.java
+675
-101
ProgramTest.java
Maths assessment/src/ProgramTest.java
+186
-165
No files found.
Maths assessment/src/Program.java
View file @
a063e2e9
This diff is collapsed.
Click to expand it.
Maths assessment/src/ProgramTest.java
View file @
a063e2e9
...
@@ -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
),((
3
d
+
6
d
+
7
d
+
9
d
+
8
d
+
7
d
+
6
d
+
5
d
+
15
d
)/
9
d
),
0.01
);
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
@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
),
(
3
d
/
((
1
d
/
3
d
)
+
(
1
d
/
6
d
)
+
(
1
d
/
77
d
))),
0.1
);
assertEquals
(
Program
.
HarmonicMean
(
set
),(
3
d
/((
1
d
/
3
d
)+(
1
d
/
6
d
)+(
1
d
/
77
d
))),
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
),
(
1
d
+
Math
.
pow
(
6
d
/
2
d
,
0.5d
)
+
(
77
d
/
2
d
))
/
6
,
0.1
);
(
1
d
+
Math
.
pow
(
6
d
/
2
d
,
0.5d
)+
(
77
d
/
2
d
))
/
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
);
}
}
}
}
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