UNPKG

gs-json

Version:

gs-JSON is a domain agnostic unifying 3D file format for geometric and semantic modelling (hence the 'gs').

160 lines 5.34 kB
import * as gs from "./gs-json"; import * as gen from "./generate/generate"; describe("Tests for Attrib class", () => { it("test_Attrib_constructor", () => { expect(test_Attrib_constructor()).toBe(true); }); it("test_Attrib_getName", () => { expect(test_Attrib_getName()).toBe(true); }); it("test_Attrib_setName", () => { expect(test_Attrib_setName()).toBe(true); }); it("test_Attrib_getGeomType", () => { expect(test_Attrib_getGeomType()).toBe(true); }); it("test_Attrib_getObjDataType", () => { expect(test_Attrib_getObjDataType()).toBe(true); }); it("test_Attrib_getValues", () => { expect(test_Attrib_getValues()).toBe(true); }); it("test_Attrib_getLabels", () => { expect(test_Attrib_getLabels()).toBe(true); }); it("test_Attrib_count", () => { expect(test_Attrib_count()).toBe(true); }); }); export function test_Attrib_constructor() { const m = new gs.Model(); const b = m.addEntAttrib("test1", gs.EGeomType.objs, gs.EDataType.type_num); return true; } export function test_Attrib_getName() { const m = new gs.Model(); const b = m.addEntAttrib("test1", gs.EGeomType.objs, gs.EDataType.type_num); if (b.getName() !== "test1") { return false; } return true; } export function test_Attrib_setName() { const m = new gs.Model(); const a = m.addEntAttrib("test1", gs.EGeomType.objs, gs.EDataType.type_num); a.setName("test2"); if (a.getName() === "test1") { return false; } if (a.getName() !== "test2") { return false; } return true; } export function test_Attrib_getGeomType() { const m = new gs.Model(); const b = m.addEntAttrib("test1", gs.EGeomType.objs, gs.EDataType.type_num); if (b.getGeomType() !== gs.EGeomType.objs) { return false; } return true; } export function test_Attrib_getObjDataType() { const m = new gs.Model(); const b = m.addEntAttrib("test1", gs.EGeomType.objs, gs.EDataType.type_num); if (b.getDataType() !== gs.EDataType.type_num) { return false; } return true; } export function test_Attrib_getValues() { const m = gen.genModelBoxWithAttribs(); const g = m.getGeom(); // get ent attrib values const ent_attribs = m.getAllEntAttribs(); const ent_attrib = ent_attribs[0]; const values1 = ent_attrib.getValues(); if (values1.length !== 8) { return false; } // add points, then get ent attrib values g.addPoints([[1, 2, 3], [2, 3, 4], [3, 4, 5]]); const values2 = ent_attribs[0].getValues(); if (values2.length !== 11) { return false; } if (values2[9] !== null) { return false; } // del points, then get ent attrib values const points = g.getAllPoints(); g.delPoint(points[5]); const values3 = ent_attribs[0].getValues(); if (values3.length !== 10) { return false; } if (values3[8] !== null) { return false; } // test topo attribs const topo_attribs = m.getAllTopoAttribs(); const topo_values1 = topo_attribs[0].getValues(); const topo_values2 = topo_attribs[1].getValues(); const topo_values3 = topo_attribs[2].getValues(); if (topo_values1.length !== 24) { return false; } if (topo_values2.length !== 24) { return false; } if (topo_values3.length !== 6) { return false; } return true; } export function test_Attrib_getLabels() { const m = gen.genModelBoxWithAttribs(); const g = m.getGeom(); // test ent attrib const ent_attribs = m.getAllEntAttribs(); const ent_labels = ent_attribs[0].getLabels(); if (ent_labels.length !== 8) { return false; } // test topo attribs const topo_attribs = m.getAllTopoAttribs(); const topo_labels1 = topo_attribs[0].getLabels(); const topo_labels2 = topo_attribs[1].getLabels(); const topo_labels3 = topo_attribs[2].getLabels(); if (topo_labels1.length !== 24) { return false; } if (topo_labels2.length !== 24) { return false; } if (topo_labels3.length !== 6) { return false; } return true; } export function test_Attrib_count() { const m = new gs.Model(); const a1 = [Math.floor(Math.random() * 10), Math.floor(Math.random() * 10), Math.floor(Math.random() * 10)]; const a2 = [Math.floor(Math.random() * 10), Math.floor(Math.random() * 10), Math.floor(Math.random() * 10)]; const a3 = [Math.floor(Math.random() * 10), Math.floor(Math.random() * 10), Math.floor(Math.random() * 10)]; const a4 = [Math.floor(Math.random() * 10), Math.floor(Math.random() * 10), Math.floor(Math.random() * 10)]; // add 4 points m.getGeom().addPoint(a1); m.getGeom().addPoint(a2); m.getGeom().addPoint(a3); m.getGeom().addPoint(a4); // create a point attribute, all values should be null const b = m.addEntAttrib("Color of points", gs.EGeomType.points, gs.EDataType.type_str); // if (b.count() !== 4) {return false; } return true; } //# sourceMappingURL=_attrib_tests.js.map