forked from pencil-js/pencil.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregular-polygon.test.js
51 lines (41 loc) · 1.09 KB
/
regular-polygon.test.js
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
import test from "ava";
import RegularPolygon from "./regular-polygon";
test.beforeEach((t) => {
t.context = new RegularPolygon([10, 20], 5, 20);
});
test("constructor", (t) => {
t.is(t.context.points.length, 5);
t.is(t.context.radius, 20);
t.is(t.context.position.x, 10);
t.is(t.context.position.y, 20);
t.throws(() => new RegularPolygon(), RangeError);
});
test("trace", (t) => {
const path = {
lineTo: () => {
t.pass();
},
};
t.plan(t.context.points.length + 2);
t.context.trace(path);
});
test("toJSON", (t) => {
const json = t.context.toJSON();
t.is(json.nbSides, 5);
t.is(json.radius, 20);
t.is(json.points, undefined);
t.is(json.constructor, "RegularPolygon");
});
test("from", (t) => {
const definition = {
nbSides: 7,
radius: 20,
};
const polygon = RegularPolygon.from(definition);
t.is(polygon.points.length, 7);
t.is(polygon.radius, 20);
});
test("getRotatingPoints", (t) => {
const points = RegularPolygon.getRotatingPoints(4, 50);
t.is(points.length, 4);
});