Skip to content

Commit d1d50b6

Browse files
committed
added test file
1 parent 54d39af commit d1d50b6

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

maker.js/makerjs-tests.ts

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/// <reference path="./makerjs.d.ts" />
2+
3+
function test() {
4+
5+
var makerjs: typeof MakerJs;
6+
7+
var p1: MakerJs.IPoint = [0, 0];
8+
var p2: MakerJs.IPoint = [1, 1];
9+
var paths = testPaths();
10+
var path: MakerJs.IPath = testPaths[0];
11+
var arc: MakerJs.IPathArc = testPaths[0];
12+
var models = testModels();
13+
var model: MakerJs.IModel = models[0];
14+
15+
function testRoot() {
16+
makerjs.extendObject({abc:123}, {xyz:789});
17+
makerjs.findById<MakerJs.IPath>(model.paths, 'a');
18+
makerjs.isModel({});
19+
makerjs.isPath({});
20+
makerjs.isPoint([]);
21+
makerjs.pathType.Circle;
22+
makerjs.removeById<MakerJs.IModel>(models, 'x');
23+
makerjs.round(44.44444, .01);
24+
makerjs.unitType.Millimeter;
25+
}
26+
27+
function testAngle() {
28+
makerjs.angle.mirror(45, true, false);
29+
makerjs.angle.noRevolutions(90);
30+
makerjs.angle.ofArcEnd(arc);
31+
makerjs.angle.ofPointInRadians([0,0], [1,1]);
32+
makerjs.angle.toDegrees(Math.PI);
33+
makerjs.angle.toRadians(90);
34+
}
35+
36+
function testExporter() {
37+
new makerjs.exporter.Exporter({});
38+
makerjs.exporter.toDXF(model);
39+
makerjs.exporter.toSVG(model);
40+
makerjs.exporter.tryGetModelUnits(model);
41+
}
42+
43+
function testKit() {
44+
makerjs.kit.construct(null, null);
45+
makerjs.kit.getParameterValues(null);
46+
(<MakerJs.kit.IMetaParameter>{}).max;
47+
(<MakerJs.kit.IKit>{}).metaParameters;
48+
}
49+
50+
function testMeasure() {
51+
makerjs.measure.arcAngle(arc);
52+
makerjs.measure.modelExtents(model).high[0];
53+
makerjs.measure.pathExtents(path).low[0];
54+
makerjs.measure.pathLength(path);
55+
makerjs.measure.pointDistance([0,0], [9,9]);
56+
}
57+
58+
function testModel(){
59+
makerjs.model.mirror(model, false, true);
60+
makerjs.model.move(makerjs.model.originate(model, [9,9]), [0,0]);
61+
makerjs.model.rotate(makerjs.model.scale(model, 6), 45, [0,0]);
62+
}
63+
64+
function testModels(): MakerJs.IModel[] {
65+
return [
66+
new makerjs.models.BoltCircle('b', 7, 7, 7, 7),
67+
new makerjs.models.BoltRectangle('c', 2, 2, 2),
68+
new makerjs.models.ConnectTheDots('c', true, [ [0,0], [1,1] ]),
69+
new makerjs.models.GoldenRectangle('g', 7),
70+
new makerjs.models.Oval('g', 7, 7),
71+
new makerjs.models.OvalArc('o', 6, 4, 2, 12),
72+
new makerjs.models.Polygon('p', 7, 5),
73+
new makerjs.models.Rectangle('r', 8, 9),
74+
new makerjs.models.Ring('r', 7, 7),
75+
new makerjs.models.RoundRectangle('r', 2, 2, 0),
76+
new makerjs.models.SCurve('s', 5, .9),
77+
new makerjs.models.Square('s', 8)
78+
];
79+
}
80+
81+
function testPath() {
82+
makerjs.path.mirror(path, true, true);
83+
makerjs.path.moveRelative(path, [0,0]);
84+
makerjs.path.rotate(path, 5, [0,0]);
85+
makerjs.path.scale(path, 8);
86+
}
87+
88+
function testPaths(): MakerJs.IPath[] {
89+
return [
90+
new makerjs.paths.Arc('a', [0,0], 7, 0, 180),
91+
new MakerJs.paths.Circle('c', [0,0], 5),
92+
new makerjs.paths.Line('l', [0,0], [1,1])
93+
];
94+
}
95+
96+
function testPoint() {
97+
makerjs.point.add(p1, p2);
98+
makerjs.point.areEqual(p1, p2);
99+
makerjs.point.clone(p1);
100+
makerjs.point.fromArc(arc);
101+
makerjs.point.fromPolar(Math.PI, 7);
102+
makerjs.point.mirror(p1, true, false);
103+
makerjs.point.rotate(p1, 5, p2);
104+
makerjs.point.scale(p2, 8);
105+
makerjs.point.subtract(p2, p1);
106+
makerjs.point.zero();
107+
}
108+
109+
function testTools() {
110+
makerjs.tools.breakPath(path, .7)[0].newPath.cssStyle;
111+
makerjs.tools.bridgeGaps([p1, p2], [p1, p2]);
112+
makerjs.tools.gapPath(model, 'a', 7, .7);
113+
makerjs.tools.pathIntersection(path, arc).intersectionPoints;
114+
makerjs.tools.solveTriangleASA(4, 4, 4);
115+
makerjs.tools.solveTriangleSSS(9, 9, 9);
116+
}
117+
118+
function testUnits() {
119+
makerjs.units.conversionScale(makerjs.unitType.Centimeter, makerjs.unitType.Foot);
120+
}
121+
122+
}

0 commit comments

Comments
 (0)