Skip to content

Commit f893158

Browse files
committed
fix: test
1 parent 042eb43 commit f893158

12 files changed

Lines changed: 71 additions & 45 deletions

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default [
2424
'build',
2525
'docs',
2626
'.svelte-kit',
27+
'vitest.config.*',
2728
'package',
2829
'**/.env',
2930
'**/.env.*',

tests/setup.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from 'vitest';
2-
import type { Solid } from '$lib/3d/Solid';
2+
3+
import { Solid } from '$lib/3d/Solid';
34

45
/**
56
* Default tolerance for floating point comparisons
@@ -59,7 +60,6 @@ export function expectValidVertexCount(solid: Solid, minVertices = 9) {
5960
*/
6061
export function expectImmutability(original: Solid, afterOperation: Solid) {
6162
const originalVertices = original.getVertices();
62-
const afterVertices = afterOperation.getVertices();
6363

6464
// They should be different instances
6565
expect(original).not.toBe(afterOperation);
@@ -93,8 +93,8 @@ export function parseStlBinary(buffer: Uint8Array) {
9393
}> = [];
9494

9595
// Parse each triangle (50 bytes each)
96-
for (let i = 0; i < triangleCount; i++) {
97-
const offset = 84 + i * 50;
96+
for (let index = 0; index < triangleCount; index++) {
97+
const offset = 84 + index * 50;
9898

9999
const normal = {
100100
x: dataView.getFloat32(offset, true),
@@ -134,22 +134,19 @@ export function parseStlBinary(buffer: Uint8Array) {
134134
* Helper to create a simple test fixture - a unit cube
135135
*/
136136
export function createUnitCube() {
137-
const { Solid } = require('$lib/3d/Solid');
138137
return Solid.cube(1, 1, 1);
139138
}
140139

141140
/**
142141
* Helper to create a simple test fixture - a unit cylinder
143142
*/
144143
export function createUnitCylinder() {
145-
const { Solid } = require('$lib/3d/Solid');
146144
return Solid.cylinder(1, 1);
147145
}
148146

149147
/**
150148
* Helper to create a simple test fixture - a unit sphere
151149
*/
152150
export function createUnitSphere() {
153-
const { Solid } = require('$lib/3d/Solid');
154151
return Solid.sphere(1);
155152
}

tests/unit/lib/3d/Solid.alignment.test.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { describe, it, expect } from 'vitest';
1+
import { describe, it } from 'vitest';
2+
23
import { Solid } from '$lib/3d/Solid';
3-
import { expectBoundsEqual, expectValidVertexCount, expectCloseTo } from '../../../setup';
4+
5+
import { expectBoundsEqual, expectCloseTo, expectValidVertexCount } from '../../../setup';
46

57
describe('Solid - Alignment and Bounds', () => {
68
describe('getBounds()', () => {
@@ -118,31 +120,39 @@ describe('Solid - Alignment and Bounds', () => {
118120
});
119121

120122
it('should center cube on x and y axes', () => {
121-
const cube = Solid.cube(10, 10, 10).move({ x: 20, y: 30, z: 40 }).center({ x: true, y: true });
123+
const cube = Solid.cube(10, 10, 10)
124+
.move({ x: 20, y: 30, z: 40 })
125+
.center({ x: true, y: true });
122126
const bounds = cube.getBounds();
123127

124128
expectCloseTo(bounds.center.x, 0, 1);
125129
expectCloseTo(bounds.center.y, 0, 1);
126130
});
127131

128132
it('should center cube on x and z axes', () => {
129-
const cube = Solid.cube(10, 10, 10).move({ x: 20, y: 30, z: 40 }).center({ x: true, z: true });
133+
const cube = Solid.cube(10, 10, 10)
134+
.move({ x: 20, y: 30, z: 40 })
135+
.center({ x: true, z: true });
130136
const bounds = cube.getBounds();
131137

132138
expectCloseTo(bounds.center.x, 0, 1);
133139
expectCloseTo(bounds.center.z, 0, 1);
134140
});
135141

136142
it('should center cube on y and z axes', () => {
137-
const cube = Solid.cube(10, 10, 10).move({ x: 20, y: 30, z: 40 }).center({ y: true, z: true });
143+
const cube = Solid.cube(10, 10, 10)
144+
.move({ x: 20, y: 30, z: 40 })
145+
.center({ y: true, z: true });
138146
const bounds = cube.getBounds();
139147

140148
expectCloseTo(bounds.center.y, 0, 1);
141149
expectCloseTo(bounds.center.z, 0, 1);
142150
});
143151

144152
it('should center cube on all axes with explicit flags', () => {
145-
const cube = Solid.cube(10, 10, 10).move({ x: 20, y: 30, z: 40 }).center({ x: true, y: true, z: true });
153+
const cube = Solid.cube(10, 10, 10)
154+
.move({ x: 20, y: 30, z: 40 })
155+
.center({ x: true, y: true, z: true });
146156
const bounds = cube.getBounds();
147157

148158
expectCloseTo(bounds.center.x, 0, 1);
@@ -302,7 +312,10 @@ describe('Solid - Alignment and Bounds', () => {
302312

303313
describe('Combined Alignment Operations', () => {
304314
it('should combine center and align', () => {
305-
const cube = Solid.cube(10, 20, 30).move({ x: 50, y: 60, z: 70 }).center({ x: true, z: true }).align('bottom');
315+
const cube = Solid.cube(10, 20, 30)
316+
.move({ x: 50, y: 60, z: 70 })
317+
.center({ x: true, z: true })
318+
.align('bottom');
306319

307320
const bounds = cube.getBounds();
308321

@@ -332,7 +345,11 @@ describe('Solid - Alignment and Bounds', () => {
332345
});
333346

334347
it('should align multiple sides sequentially', () => {
335-
const cube = Solid.cube(10, 20, 30).move({ x: 50, y: 60, z: 70 }).align('bottom').align('left').align('front');
348+
const cube = Solid.cube(10, 20, 30)
349+
.move({ x: 50, y: 60, z: 70 })
350+
.align('bottom')
351+
.align('left')
352+
.align('front');
336353

337354
const bounds = cube.getBounds();
338355

tests/unit/lib/3d/Solid.csg.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { describe, it, expect } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
2+
23
import { Solid } from '$lib/3d/Solid';
3-
import { expectImmutability, expectValidVertexCount, expectCloseTo } from '../../../setup';
4+
5+
import { expectCloseTo, expectImmutability, expectValidVertexCount } from '../../../setup';
46

57
describe('Solid - CSG Operations', () => {
68
describe('SUBTRACT()', () => {
@@ -299,9 +301,9 @@ describe('Solid - CSG Operations', () => {
299301
const unionResult = Solid.UNION(cube1, cube2);
300302

301303
// Should have similar vertex counts
302-
expect(Math.abs(mergeResult.getVertices().length - unionResult.getVertices().length)).toBeLessThan(
303-
100
304-
);
304+
expect(
305+
Math.abs(mergeResult.getVertices().length - unionResult.getVertices().length)
306+
).toBeLessThan(100);
305307
});
306308

307309
it('should be chainable with other operations', () => {

tests/unit/lib/3d/Solid.grids.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { describe, it, expect } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
2+
23
import { Solid } from '$lib/3d/Solid';
3-
import { expectValidVertexCount, expectCloseTo } from '../../../setup';
4+
5+
import { expectCloseTo, expectValidVertexCount } from '../../../setup';
46

57
describe('Solid - Grid Operations', () => {
68
describe('GRID_X() - 1D Grid', () => {

tests/unit/lib/3d/Solid.primitives.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { describe, it, expect } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
2+
23
import { Solid } from '$lib/3d/Solid';
3-
import { expectBoundsEqual, expectValidVertexCount, expectCloseTo } from '../../../setup';
4+
5+
import { expectBoundsEqual, expectCloseTo, expectValidVertexCount } from '../../../setup';
46

57
describe('Solid - Primitive Creation', () => {
68
describe('cube()', () => {

tests/unit/lib/3d/Solid.profiles.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { describe, it, expect } from 'vitest';
2-
import { Solid, straight, curve } from '$lib/3d/Solid';
3-
import { expectValidVertexCount, expectCloseTo } from '../../../setup';
1+
import { describe, expect, it } from 'vitest';
2+
3+
import { curve, Solid, straight } from '$lib/3d/Solid';
4+
5+
import { expectCloseTo, expectValidVertexCount } from '../../../setup';
46

57
describe('Solid - Custom Profiles', () => {
68
describe('profilePrism()', () => {

tests/unit/lib/3d/Solid.revolution.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { describe, it, expect } from 'vitest';
2-
import { Solid, straight, curve } from '$lib/3d/Solid';
3-
import { expectValidVertexCount, expectCloseTo } from '../../../setup';
1+
import { describe, expect, it } from 'vitest';
2+
3+
import { curve, Solid, straight } from '$lib/3d/Solid';
4+
5+
import { expectCloseTo, expectValidVertexCount } from '../../../setup';
46

57
describe('Solid - Revolution Solids', () => {
68
describe('revolutionSolid()', () => {

tests/unit/lib/3d/Solid.transforms.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { describe, it, expect } from 'vitest';
1+
import { describe, it } from 'vitest';
2+
23
import { Solid } from '$lib/3d/Solid';
3-
import { expectBoundsEqual, expectValidVertexCount, expectCloseTo } from '../../../setup';
4+
5+
import { expectCloseTo, expectValidVertexCount } from '../../../setup';
46

57
describe('Solid - Transformations', () => {
68
describe('at() - Absolute Positioning', () => {
@@ -407,7 +409,7 @@ describe('Solid - Transformations', () => {
407409

408410
// After 90 degree z rotation, width and depth may swap
409411
// But total volume-related dimensions should be preserved
410-
const dimensions = [bounds.width, bounds.height, bounds.depth].sort();
412+
const dimensions = [bounds.width, bounds.height, bounds.depth].toSorted();
411413
expectCloseTo(dimensions[0], 10, 1);
412414
expectCloseTo(dimensions[1], 20, 1);
413415
expectCloseTo(dimensions[2], 30, 1);
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { describe, it, expect } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
2+
23
import { Solid } from '$lib/3d/Solid';
4+
35
import { expectValidVertexCount } from '../../../setup';
46

57
describe('Solid - Utility Methods', () => {
@@ -129,10 +131,7 @@ describe('Solid - Utility Methods', () => {
129131
});
130132

131133
it('should allow color changes multiple times', () => {
132-
const cube = Solid.cube(10, 10, 10)
133-
.setColor('red')
134-
.setColor('blue')
135-
.setColor('green');
134+
const cube = Solid.cube(10, 10, 10).setColor('red').setColor('blue').setColor('green');
136135

137136
expectValidVertexCount(cube);
138137
});
@@ -364,10 +363,7 @@ describe('Solid - Utility Methods', () => {
364363
});
365364

366365
it('should preserve color through transformations', () => {
367-
const cube = Solid.cube(10, 10, 10)
368-
.setColor('purple')
369-
.rotate({ z: 45 })
370-
.scale({ all: 2 });
366+
const cube = Solid.cube(10, 10, 10).setColor('purple').rotate({ z: 45 }).scale({ all: 2 });
371367

372368
expectValidVertexCount(cube);
373369
});

0 commit comments

Comments
 (0)