This repository has been archived by the owner on Jul 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest.js
32 lines (27 loc) · 2.17 KB
/
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
const test = require('ava')
const {CSG} = require('@jscad/csg')
const serializer = require('./index.js')
test('serialize csg to stl (binary)', function (t) {
const input = new CSG.cube()
const observed = serializer.serialize(input, {binary: true})
// TODO: VERY shallow testing ... improve
t.deepEqual(observed[0].byteLength, 80)
t.deepEqual(observed[1].byteLength, 4)
t.deepEqual(observed[2].byteLength, 600)
})
test('serialize csg to stl (ascii)', function (t) {
const input = new CSG.cube()
const expected = [ 'solid csg.js\nfacet normal -1 0 0\nouter loop\nvertex -1 -1 -1\nvertex -1 -1 1\nvertex -1 1 1\nendloop\nendfacet\nfacet normal -1 0 0\nouter loop\nvertex -1 -1 -1\nvertex -1 1 1\nvertex -1 1 -1\nendloop\nendfacet\nfacet normal 1 0 0\nouter loop\nvertex 1 -1 -1\nvertex 1 1 -1\nvertex 1 1 1\nendloop\nendfacet\nfacet normal 1 0 0\nouter loop\nvertex 1 -1 -1\nvertex 1 1 1\nvertex 1 -1 1\nendloop\nendfacet\nfacet normal 0 -1 0\nouter loop\nvertex -1 -1 -1\nvertex 1 -1 -1\nvertex 1 -1 1\nendloop\nendfacet\nfacet normal 0 -1 0\nouter loop\nvertex -1 -1 -1\nvertex 1 -1 1\nvertex -1 -1 1\nendloop\nendfacet\nfacet normal 0 1 0\nouter loop\nvertex -1 1 -1\nvertex -1 1 1\nvertex 1 1 1\nendloop\nendfacet\nfacet normal 0 1 0\nouter loop\nvertex -1 1 -1\nvertex 1 1 1\nvertex 1 1 -1\nendloop\nendfacet\nfacet normal 0 0 -1\nouter loop\nvertex -1 -1 -1\nvertex -1 1 -1\nvertex 1 1 -1\nendloop\nendfacet\nfacet normal 0 0 -1\nouter loop\nvertex -1 -1 -1\nvertex 1 1 -1\nvertex 1 -1 -1\nendloop\nendfacet\nfacet normal 0 0 1\nouter loop\nvertex -1 -1 1\nvertex 1 -1 1\nvertex 1 1 1\nendloop\nendfacet\nfacet normal 0 0 1\nouter loop\nvertex -1 -1 1\nvertex 1 1 1\nvertex -1 1 1\nendloop\nendfacet\nendsolid csg.js\n' ]
const observed = serializer.serialize(input, {binary: false})
t.deepEqual(observed, expected)
})
test('progress status callback', function (t) {
const input = new CSG.cube()
const progresses = [];
const statusCallback = function (statusObj) {
progresses.push(statusObj.progress);
};
const observed = serializer.serialize(input, {statusCallback: statusCallback})
t.deepEqual(0, progresses[0]);
t.deepEqual(100, progresses[progresses.length - 1]);
})