-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathmath_test.js
More file actions
77 lines (70 loc) · 1.95 KB
/
math_test.js
File metadata and controls
77 lines (70 loc) · 1.95 KB
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
const gjsunit = imports.gjsunit;
let suite = new gjsunit.Suite("math.js");
suite.addTest("distance", function() {
gjsunit.assertEquals(0, imports.math.distance({x: 0, y: 0}, {x: 0, y: 0}));
gjsunit.assertEquals(1, imports.math.distance({x: 0, y: 0}, {x: 1, y: 0}));
gjsunit.assertEquals(1, imports.math.distance({x: 0, y: 0}, {x: 0, y: 1}));
// TODO find some more measurements
// TODO limit to x decimal places?
});
suite.addTest("gamma", function() {
gjsunit.assertEquals(0, imports.math.gamma({x: 0, y: 0}, {x: 0, y: 0}, {x: 0, y: 0}));
});
suite.addTest("gr", function () {
let tests = [
// tests where a < b
{a: 0, b: 5, e: 2},
{a: 0, b: 8, e: 3},
{a: 0, b: 13, e: 5},
{a: 3, b: 16, e: 8},
{a: -3, b: 10, e: 2},
// tests where a > b
{a: 5, b: 0, e: 3},
{a: 8, b: 0, e: 5},
{a: 13, b: 0, e: 8},
{a: 16, b: 3, e: 11},
{a: 10, b: -3, e: 5},
// tests where a == b
{a: 0, b: 0, e: 0},
{a: 1, b: 1, e: 1},
{a: -1, b: -1, e: -1},
];
// loop through the tests
for (let test of tests) {
// get the ratio
let c = imports.math.gr(test.a, test.b)
// check the expected result against the actual one
let r = Math.round(c);
gjsunit.assertEquals(test.e, r);
}
});
suite.addTest("gr_next", function () {
let tests = [
// tests where a < c
{a: 0, c: 3, e: 5},
{a: 0, c: 5, e: 8},
{a: 0, c: 8, e: 13},
{a: 3, c: 8, e: 11},
{a: -8, c: -3, e: 0},
{a: -3, c: 2, e: 5},
// tests where a > c
{a: 3, c: 0, e: -2},
{a: 5, c: 0, e: -3},
{a: 8, c: 0, e: -5},
{a: 16, c: 8, e: 3},
{a: 5, c: -3, e: -8},
{a: -3, c: -8, e: -11},
// tests where a == c
{a: 0, c: 0, e: 0},
{a: 1, c: 1, e: 1},
{a: -1, c: -1, e: -1},
];
// loop through the tests
for (let test of tests) {
// get the ratio
let c = imports.math.gr_next(test.a, test.c)
// check the expected result against the actual one
let r = Math.round(c);
gjsunit.assertEquals(test.e, r);
}
});