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
Hide 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,275 +7,296 @@ class ProgramTest {
@Test
void
testConvertBinaryToInt
()
{
String
[]
input
=
{
"010"
,
"110"
,
"111"
,
"1010101"
};
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
);
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"
};
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
);
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"
};
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
);
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
//1s, 20s, 400s
String
[]
input
=
{
"50"
,
"110"
,
"FA"
,
"GH"
};
int
[]
result
=
Program
.
ConvertBase20ToInt
(
input
);
String
[]
input
=
{
"50"
,
"110"
,
"FA"
,
"GH"
};
assertEquals
(
result
[
0
],
100
);
assertEquals
(
result
[
1
],
420
);
assertEquals
(
result
[
2
],
310
);
assertEquals
(
result
[
3
],(
16
*
20
)+
17
);
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
);
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
);
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
);
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
);
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
};
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
void
testMode
()
{
int
[]
set
=
{
3
,
6
,
7
,
9
,
8
,
7
,
7
,
6
,
5
,
15
};
assertEquals
(
Program
.
Mode
(
set
),
7
);
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
);
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
);
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
);
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
);
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
};
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
}};
(
1
d
+
Math
.
pow
(
6
d
/
2
d
,
0.5d
)
+
(
77
d
/
2
d
))
/
6
,
0.1
);
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
testMatrixScalar
()
{
int
[][]
matrix
=
{
{
1
,
2
},
{
3
,
4
}
};
void
testComplexMatrixOperation
()
{
int
[][]
mScaled
=
Program
.
MatrixScalarMultiplication
(
matrix
,
11
);
int
[][]
matrix
=
{{
1
,
2
},
{
3
,
4
}};
assertEquals
(
mScaled
[
0
][
0
],
11
);
assertEquals
(
mScaled
[
0
][
1
],
22
);
assertEquals
(
mScaled
[
1
][
0
],
33
);
assertEquals
(
mScaled
[
1
][
1
],
44
);
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 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
);
}
assertEquals
(
d
[
2479
],
0.0012
,
0.0001
);
}
@Test
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
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