Skip to content

Commit 7e2f8f5

Browse files
enum service unit tests
1 parent c378687 commit 7e2f8f5

File tree

1 file changed

+125
-1
lines changed

1 file changed

+125
-1
lines changed

packages/dev/occt/lib/services/base/enum.service.test.ts

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import initOpenCascade, { OpenCascadeInstance } from "../../../bitbybit-dev-occt/bitbybit-dev-occt";
2+
import { OccHelper } from "../../occ-helper";
3+
import { VectorHelperService } from "../../api/vector-helper.service";
4+
import { ShapesHelperService } from "../../api/shapes-helper.service";
25
import { EnumService } from "./enum.service";
36
import * as Inputs from "../../api/inputs/inputs";
47

5-
describe("OCCT booleans unit tests", () => {
8+
describe("OCCT enum service unit tests", () => {
69
let occt: OpenCascadeInstance;
710
let enumService: EnumService;
11+
let occHelper: OccHelper;
812

913
beforeAll(async () => {
1014
occt = await initOpenCascade();
1115
enumService = new EnumService(occt);
16+
const vec = new VectorHelperService();
17+
const s = new ShapesHelperService();
18+
occHelper = new OccHelper(vec, s, occt);
1219
});
1320

1421
it("should get gcc position unqualified", async () => {
@@ -50,5 +57,122 @@ describe("OCCT booleans unit tests", () => {
5057
const res = enumService.convertFourSidesStrictEnumToTwoCircleInclusionEnum("whatever" as any);
5158
expect(res).toEqual(Inputs.OCCT.twoCircleInclusionEnum.none);
5259
});
60+
61+
describe("getShapeTypeEnum", () => {
62+
it("should return vertex for a vertex shape", () => {
63+
const vertex = occHelper.entitiesService.makeVertex([1, 2, 3]);
64+
const res = enumService.getShapeTypeEnum(vertex);
65+
expect(res).toEqual(Inputs.OCCT.shapeTypeEnum.vertex);
66+
vertex.delete();
67+
});
68+
69+
it("should return edge for an edge shape", () => {
70+
const edge = occHelper.edgesService.lineEdge({ start: [0, 0, 0], end: [1, 0, 0] });
71+
const res = enumService.getShapeTypeEnum(edge);
72+
expect(res).toEqual(Inputs.OCCT.shapeTypeEnum.edge);
73+
edge.delete();
74+
});
75+
76+
it("should return wire for a wire shape", () => {
77+
const wire = occHelper.wiresService.createPolygonWire({ points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]] });
78+
const res = enumService.getShapeTypeEnum(wire);
79+
expect(res).toEqual(Inputs.OCCT.shapeTypeEnum.wire);
80+
wire.delete();
81+
});
82+
83+
it("should return face for a face shape", () => {
84+
const face = occHelper.facesService.createSquareFace({ size: 1, center: [0, 0, 0], direction: [0, 1, 0] });
85+
const res = enumService.getShapeTypeEnum(face);
86+
expect(res).toEqual(Inputs.OCCT.shapeTypeEnum.face);
87+
face.delete();
88+
});
89+
90+
it("should return shell for a shell shape", () => {
91+
// Create a shell by sewing two faces together
92+
const face1 = occHelper.facesService.createSquareFace({ size: 1, center: [0, 0, 0], direction: [0, 0, 1] });
93+
const face2 = occHelper.facesService.createSquareFace({ size: 1, center: [0, 0.5, 0.5], direction: [0, 1, 0] });
94+
const shell = occHelper.shellsService.sewFaces({ shapes: [face1, face2], tolerance: 1e-7 });
95+
const res = enumService.getShapeTypeEnum(shell);
96+
expect(res).toEqual(Inputs.OCCT.shapeTypeEnum.shell);
97+
face1.delete();
98+
face2.delete();
99+
shell.delete();
100+
});
101+
102+
it("should return solid for a solid shape", () => {
103+
const box = occHelper.solidsService.createBox({ width: 1, height: 1, length: 1, center: [0, 0, 0] });
104+
const res = enumService.getShapeTypeEnum(box);
105+
expect(res).toEqual(Inputs.OCCT.shapeTypeEnum.solid);
106+
box.delete();
107+
});
108+
109+
it("should return compound for a compound shape", () => {
110+
const box1 = occHelper.solidsService.createBox({ width: 1, height: 1, length: 1, center: [0, 0, 0] });
111+
const box2 = occHelper.solidsService.createBox({ width: 1, height: 1, length: 1, center: [5, 0, 0] });
112+
const compound = occHelper.converterService.makeCompound({ shapes: [box1, box2] });
113+
const res = enumService.getShapeTypeEnum(compound);
114+
expect(res).toEqual(Inputs.OCCT.shapeTypeEnum.compound);
115+
box1.delete();
116+
box2.delete();
117+
compound.delete();
118+
});
119+
});
120+
121+
describe("getGeomFillTrihedronEnumOCCTValue", () => {
122+
it("should return GeomFill_IsConstantNormal for isConstantNormal", () => {
123+
const res = enumService.getGeomFillTrihedronEnumOCCTValue(Inputs.OCCT.geomFillTrihedronEnum.isConstantNormal);
124+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsConstantNormal);
125+
});
126+
127+
it("should return GeomFill_IsCorrectedFrenet for isCorrectedFrenet", () => {
128+
const res = enumService.getGeomFillTrihedronEnumOCCTValue(Inputs.OCCT.geomFillTrihedronEnum.isCorrectedFrenet);
129+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsCorrectedFrenet);
130+
});
131+
132+
it("should return GeomFill_IsDarboux for isDarboux", () => {
133+
const res = enumService.getGeomFillTrihedronEnumOCCTValue(Inputs.OCCT.geomFillTrihedronEnum.isDarboux);
134+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsDarboux);
135+
});
136+
137+
it("should return GeomFill_IsDiscreteTrihedron for isDiscreteTrihedron", () => {
138+
const res = enumService.getGeomFillTrihedronEnumOCCTValue(Inputs.OCCT.geomFillTrihedronEnum.isDiscreteTrihedron);
139+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsDiscreteTrihedron);
140+
});
141+
142+
it("should return GeomFill_IsFixed for isFixed", () => {
143+
const res = enumService.getGeomFillTrihedronEnumOCCTValue(Inputs.OCCT.geomFillTrihedronEnum.isFixed);
144+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsFixed);
145+
});
146+
147+
it("should return GeomFill_IsFrenet for isFrenet", () => {
148+
const res = enumService.getGeomFillTrihedronEnumOCCTValue(Inputs.OCCT.geomFillTrihedronEnum.isFrenet);
149+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsFrenet);
150+
});
151+
152+
it("should return GeomFill_IsGuideAC for isGuideAC", () => {
153+
const res = enumService.getGeomFillTrihedronEnumOCCTValue(Inputs.OCCT.geomFillTrihedronEnum.isGuideAC);
154+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsGuideAC);
155+
});
156+
157+
it("should return GeomFill_IsGuideACWithContact for isGuideACWithContact", () => {
158+
const res = enumService.getGeomFillTrihedronEnumOCCTValue(Inputs.OCCT.geomFillTrihedronEnum.isGuideACWithContact);
159+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsGuideACWithContact);
160+
});
161+
162+
it("should return GeomFill_IsGuidePlan for isGuidePlan", () => {
163+
const res = enumService.getGeomFillTrihedronEnumOCCTValue(Inputs.OCCT.geomFillTrihedronEnum.isGuidePlan);
164+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsGuidePlan);
165+
});
166+
167+
it("should return GeomFill_IsGuidePlanWithContact for isGuidePlanWithContact", () => {
168+
const res = enumService.getGeomFillTrihedronEnumOCCTValue(Inputs.OCCT.geomFillTrihedronEnum.isGuidePlanWithContact);
169+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsGuidePlanWithContact);
170+
});
171+
172+
it("should return GeomFill_IsConstantNormal as default for unrecognized value", () => {
173+
const res = enumService.getGeomFillTrihedronEnumOCCTValue("whatever" as any);
174+
expect(res).toEqual(occt.GeomFill_Trihedron.GeomFill_IsConstantNormal);
175+
});
176+
});
53177
});
54178

0 commit comments

Comments
 (0)