-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqunit_test_helpers.html
82 lines (57 loc) · 2.74 KB
/
qunit_test_helpers.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test Suite</title>
<link rel="stylesheet" href="../../qunit-2.19.4/qunit-2.19.4.css">
<!-- <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.19.4.css"> -->
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<!-- <script src="https://code.jquery.com/qunit/qunit-2.19.4.js"></script> -->
<script src="../../qunit-2.19.4/qunit-2.19.4.js"></script>
<script src="../../qunit-assert-close-git/qunit-assert-close/qunit-assert-close.js"></script>
<script src="debug.js"></script>
<script src="helpers.js"></script>
<!-- <script src="BCLegs.js"></script> -->
<script src="BCEndRings.js"></script>
<script src="BirdcageBuilder.js"></script>
<!-- see https://www.smashingmagazine.com/2012/06/introduction-to-javascript-unit-testing/ -->
<script>
QUnit.module('Helper Functions', function() {
// TODO - double check all NaN results are correct; try to make some better/more meaningful tests
QUnit.test('Unit Conversion', function(assert) {
/* Test Unit Conversion Functions */
assert.equal(cm2meters(100), 1);
assert.equal(cm2meters(10), 0.1);
assert.equal(cm2meters(1.5), 0.015);
assert.equal(mhz2hz(1), 1000000);
assert.equal(mhz2hz(1.357), 1357000);
assert.equal(mhz2hz(23.5), 23500000);
});
QUnit.test('General Math', function(assert) {
/* Confirming general Javascript Math/IEEE-754 assumptions */
/* Make sure JavaScript Math.log is the same as Java (Natural log) */
assert.close(Math.log(2.71), 0.9969486348916096, 1e-15, 'Natural log of truncated e (2.71)');
assert.equal(Math.log(Math.E), 1.0, 'Natural log of Math.E (exact)');
assert.equal(Math.log(1), 0);
assert.equal(Math.log(0), Number.NEGATIVE_INFINITY);
/* Infinity value handling */
assert.equal(Math.log(0) + 0.5, Number.NEGATIVE_INFINITY);
assert.equal(2*Math.log(0), Number.NEGATIVE_INFINITY);
assert.equal(2*Math.log(0) + 0.5, Number.NEGATIVE_INFINITY);
assert.true(Number.isNaN(0 * Infinity)); // inf * 0 is NaN
});
QUnit.test('Modulo Math', function(assert) {
/* Javascript % is not the same as Java (?) - test workaround function here */
assert.equal(mod( 2, 8), 2);
assert.equal(mod(10, 8), 2);
assert.equal(mod(0, 8), 0)
assert.equal(mod(13, 9), 4)
assert.equal(mod(1+1, 8), 2)
assert.equal(mod(-1, 8), 7); // TODO not sure if this is correct - GT is to test against Java
// TODO - do some tests in Java & compare output
// TODO - make sure to include negative numbers
// TODO - test specific cases where JS% and mod() are different & make sure they are different?
});
}); // end all tests
</script>
</body>