59 lines
2.4 KiB
TypeScript
59 lines
2.4 KiB
TypeScript
import { StringReader, readAll } from "../src/deps.ts";
|
|
import { Vector3D } from "../src/services/interfaces.ts";
|
|
import { WaveFrontServiceImpl } from "../src/services/wavefrontService.ts";
|
|
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts';
|
|
|
|
Deno.test('WaveFrontServiceImpl happy path ', async (t) => {
|
|
const waveFrontService = new WaveFrontServiceImpl();
|
|
|
|
|
|
await t.step("test trivial transform", async () => {
|
|
const content = "line 1\nline2\nline3\n"
|
|
const reader = new StringReader(content);
|
|
|
|
const ret = waveFrontService.transformLine(reader, (s) => `hello ${s}`);
|
|
const expt = "hello line 1\nhello line2\nhello line3\n"
|
|
assertEquals(new TextDecoder().decode(await readAll(ret)), expt);
|
|
});
|
|
|
|
await t.step("test trivial transform (no final new line in original file) `", async () => {
|
|
const content = "line 1\nline2\nline3"
|
|
const reader = new StringReader(content);
|
|
|
|
const ret = waveFrontService.transformLine(reader, (s) => `hello ${s}`);
|
|
const expt = "hello line 1\nhello line2\nhello line3\n"
|
|
assertEquals(new TextDecoder().decode(await readAll(ret)), expt);
|
|
});
|
|
});
|
|
|
|
Deno.test('WaveFrontServiceImpl getLineTransformer', async (t) => {
|
|
const waveFrontService = new WaveFrontServiceImpl();
|
|
|
|
await t.step("trivial cases", () => {
|
|
const fn = waveFrontService.getLineTransformer([1, 2, 3], [10, 11, 12])
|
|
|
|
assertEquals(fn(''), '');
|
|
assertEquals(fn('hello'), 'hello');
|
|
assertEquals(fn('hello 1 2 3'), 'hello 1 2 3');
|
|
});
|
|
|
|
await t.step("transform cases", () => {
|
|
const scale: Vector3D = [5, 6, 7];
|
|
const translate: Vector3D = [10, 11, 12];
|
|
const fn = waveFrontService.getLineTransformer(scale, translate);
|
|
const expt = (x: number, y: number, z: number) => `v ${x * scale[0] + translate[0]} ${y * scale[1] + translate[1]} ${z * scale[2] + translate[2]}`;
|
|
const values = [-1, 2, 3, 10, 5.23, 34.56, -12.75 ]
|
|
for(const x of values){
|
|
for(const y of values){
|
|
for(const z of values){
|
|
assertEquals(fn(`v ${x} ${y} ${z}`), expt(x, y, z));
|
|
assertEquals(fn(`v ${x} ${y} ${z} `), expt(x, y, z));
|
|
assertEquals(fn(`v ${x} ${y} ${z} # foo bar`), expt(x, y, z));
|
|
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
}) |