-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.html
More file actions
130 lines (104 loc) · 3.47 KB
/
test.html
File metadata and controls
130 lines (104 loc) · 3.47 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit Example</title>
<link rel="stylesheet" href="resources/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="resources/qunit.js"></script>
<script src="resources/ecc.js"></script>
<script>
test("div test", function() {
ok(div(5, 2) == 2);
});
test("mod tests", function() {
ok(mod(5, 2) == 1, "Positive modulo test passed");
ok(mod(-5, 2) == 1, "Negative modulo test passed");
});
test("inv test", function() {
ok(inv(4, 23) == 6);
ok(inv(3, 11) == 4);
});
test("euclid-next test", function() {
var result = euclid_next([240, 1, 0], [46, 0, 1]);
deepEqual(result, [10, 1, -5]);
var result = euclid_next([46, 0, 1], [10, 1, -5]);
deepEqual(result, [6, -4, 21]);
});
test("extended euclid test", function() {
var result = ext_euclid(240, 46);
deepEqual(result, [2, -9, 47]);
});
test("gcd tests", function() {
deepEqual(gcd(9, 12), 3);
deepEqual(gcd(13, 7), 1);
deepEqual(gcd(3, -1), 1);
});
test("add(P, Q) test", function() {
var curve = new Curve(17, 1, 1, 7);
var P = new Point(2, 0),
Q = new Point(1, 3);
deepEqual(add(P, Q, curve), new Point(6, 12));
});
test("add(P, P) test", function() {
var curve = new Curve(17, 1, 1, 7);
var P = new Point(1, 3);
deepEqual(add(P, P, curve), new Point(6, 5));
});
test("isElem test", function() {
var curve = new Curve(17, 1, 1, 7);
var point = new Point(2, 0);
ok(isElem(point, curve) == true, "On-curve test passed");
var point = new Point(2, 1);
ok(isElem(point, curve) == false, "Not-on-curve test passed");
});
test("castRay test", function() {
var curve = new Curve(7, 1, 3, 5);
var p1 = new Point(1, 3),
p2 = new Point(4, 2);
deepEqual(castRay(p1, p2, curve), new Point(13, -1));
});
test("shift apply tests", function() {
var arrow = shift(new Arrow(new Point(-1, 5), new Point(-2, 3)), 7);
deepEqual(new Arrow(new Point(6, 5), new Point(5, 3)), arrow);
});
test("shift no-apply test", function() {
var arrow = shift(new Arrow(new Point(1, 3), new Point(7, 1)), 7);
deepEqual(new Arrow(new Point(1, 3), new Point(7, 1)), arrow);
});
test("unitSplit sloped test", function() {
var arrow = new Arrow(new Point(1, 1), new Point(2, 3));
deepEqual(unitSplit(arrow), [new Point(1, 1), new Point(1.5, 2), new Point(2, 3)]);
});
test("unitSplit horizontal test", function() {
var arrow = new Arrow(new Point(1, 1), new Point(5, 1));
deepEqual(unitSplit(arrow), [new Point(1, 1), new Point(2, 1), new Point(3, 1), new Point(4, 1), new Point(5, 1)]);
});
test("unitSplit vertical test", function() {
var arrow = new Arrow(new Point(1, 5), new Point(1, 1));
deepEqual(unitSplit(arrow), [new Point(1, 5), new Point(1, 4), new Point(1, 3), new Point(1, 2), new Point(1, 1)]);
});
test("splitLine test", function() {
var curve = new Curve(7, 1, 3, 5);
var p1 = new Point(1, 3),
p2 = new Point(13, -1);
deepEqual(splitArrow(new Arrow(p1, p2), curve), [
new Arrow(new Point(1, 3), new Point(7, 1)),
new Arrow(new Point(0, 1), new Point(3, 0)),
new Arrow(new Point(3, 7), new Point(6, 6))
]);
});
test("getYTwin test", function() {
var twin = getYTwin(new Point(12, 8), new Curve(17, 1, 1, 7));
deepEqual(twin, new Point(12, 9));
});
test("getYTwin idem test", function() {
var twin = getYTwin(new Point(2, 0), new Curve(17, 1, 1, 7));
deepEqual(twin, null);
});
</script>
</body>
</html>