Skip to content

Commit 871f16c

Browse files
committed
Improve tests to not assume the value of the default
1 parent b40b04d commit 871f16c

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/__tests__/job.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect, describe } from 'vitest';
2-
import { Job, State } from '../job';
2+
import { Job, State, LayersIndexer } from '../job';
33
import { PathType, Path } from '../path';
44

55
test('it has an initial state', () => {
@@ -96,7 +96,7 @@ describe('.layers', () => {
9696
expect(layers?.[0].length).toEqual(2);
9797
});
9898

99-
test('travel paths moving z above the tolerance create a new layer', () => {
99+
test('travel paths moving z above the default tolerance create a new layer', () => {
100100
const job = new Job();
101101

102102
append_path(job, PathType.Extrusion, [
@@ -105,7 +105,7 @@ describe('.layers', () => {
105105
]);
106106
append_path(job, PathType.Travel, [
107107
[5, 6, 0],
108-
[5, 6, 1]
108+
[5, 6, LayersIndexer.DEFAULT_TOLERANCE + 0.01]
109109
]);
110110

111111
const layers = job.layers;
@@ -117,7 +117,7 @@ describe('.layers', () => {
117117
expect(layers?.[1].length).toEqual(1);
118118
});
119119

120-
test('travel paths moving z under the tolerance are on the same layer', () => {
120+
test('travel paths moving z under the default tolerance are on the same layer', () => {
121121
const job = new Job();
122122

123123
append_path(job, PathType.Extrusion, [
@@ -126,7 +126,7 @@ describe('.layers', () => {
126126
]);
127127
append_path(job, PathType.Travel, [
128128
[5, 6, 0],
129-
[5, 6, 0.04]
129+
[5, 6, LayersIndexer.DEFAULT_TOLERANCE - 0.01]
130130
]);
131131

132132
const layers = job.layers;

src/job.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class State {
1717

1818
type JobOptions = {
1919
state?: State;
20-
minLayerThreshold: number;
20+
minLayerThreshold?: number;
2121
};
2222

2323
export class Job {
@@ -29,7 +29,7 @@ export class Job {
2929
private indexers: Indexer[];
3030
inprogressPath: Path | undefined;
3131

32-
constructor(opts: JobOptions = { minLayerThreshold: 0.05 }) {
32+
constructor(opts: JobOptions = {}) {
3333
this.paths = [];
3434
this.state = opts.state || State.initial;
3535
this.layersPaths = [[]];
@@ -89,7 +89,7 @@ export class Job {
8989
}
9090

9191
class NonApplicableIndexer extends Error {}
92-
class Indexer {
92+
export class Indexer {
9393
protected indexes: Record<string, Path[]> | Path[][];
9494
constructor(indexes: Record<string, Path[]> | Path[][]) {
9595
this.indexes = indexes;
@@ -100,7 +100,7 @@ class Indexer {
100100
}
101101
}
102102

103-
class TravelTypeIndexer extends Indexer {
103+
export class TravelTypeIndexer extends Indexer {
104104
protected declare indexes: Record<string, Path[]>;
105105
constructor(indexes: Record<string, Path[]>) {
106106
super(indexes);
@@ -120,10 +120,11 @@ class NonPlanarPathError extends NonApplicableIndexer {
120120
super("Non-planar paths can't be indexed by layer");
121121
}
122122
}
123-
class LayersIndexer extends Indexer {
123+
export class LayersIndexer extends Indexer {
124+
static readonly DEFAULT_TOLERANCE = 0.05;
124125
protected declare indexes: Path[][];
125126
private tolerance: number;
126-
constructor(indexes: Path[][], tolerance: number = 0.05) {
127+
constructor(indexes: Path[][], tolerance: number = LayersIndexer.DEFAULT_TOLERANCE) {
127128
super(indexes);
128129
this.tolerance = tolerance;
129130
}

0 commit comments

Comments
 (0)