Skip to content

Commit

Permalink
test(node): add format write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Nov 11, 2024
1 parent 9dc2cde commit c5438d5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 7 deletions.
33 changes: 31 additions & 2 deletions packages/transform-io/typescript/test/node/hdf5-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import test from "ava";
import path from "path";

import { hdf5ReadTransformNode } from "../../dist/index-node.js";
import {
hdf5ReadTransformNode,
hdf5WriteTransformNode,
} from "../../dist/index-node.js";

import { testInputPath, verifyTestLinearTransform } from "./common.js";
import {
testInputPath,
testOutputPath,
verifyTestLinearTransform,
} from "./common.js";

const testInputFilePath = path.join(testInputPath, "LinearTransform.h5");
const testOutputFilePath = path.join(
testOutputPath,
"hdf5-test-write-LinearTransform.h5"
);

test("Test reading a HDF5 file", async (t) => {
const { couldRead, transform } = await hdf5ReadTransformNode(
Expand All @@ -14,3 +25,21 @@ test("Test reading a HDF5 file", async (t) => {
t.true(couldRead);
verifyTestLinearTransform(t, transform);
});

test("Test writing a HDF5 transform file", async (t) => {
const { couldRead, transform } = await hdf5ReadTransformNode(
testInputFilePath
);
t.true(couldRead);

const { couldWrite } = await hdf5WriteTransformNode(
transform,
testOutputFilePath
);
t.true(couldWrite);

const { couldRead: couldReadBack, transform: transformBack } =
await hdf5ReadTransformNode(testInputFilePath);
t.true(couldReadBack);
verifyTestLinearTransform(t, transformBack);
});
33 changes: 31 additions & 2 deletions packages/transform-io/typescript/test/node/mat-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import test from "ava";
import path from "path";

import { matReadTransformNode } from "../../dist/index-node.js";
import {
matReadTransformNode,
matWriteTransformNode,
} from "../../dist/index-node.js";

import { testInputPath, verifyTestLinearTransform } from "./common.js";
import {
testInputPath,
testOutputPath,
verifyTestLinearTransform,
} from "./common.js";

const testInputFilePath = path.join(testInputPath, "LinearTransform.mat");
const testOutputFilePath = path.join(
testOutputPath,
"mat-test-write-LinearTransform.mat"
);

test("Test reading a .mat file", async (t) => {
const { couldRead, transform } = await matReadTransformNode(
Expand All @@ -14,3 +25,21 @@ test("Test reading a .mat file", async (t) => {
t.true(couldRead);
verifyTestLinearTransform(t, transform);
});

test("Test writing .mat transform file", async (t) => {
const { couldRead, transform } = await matReadTransformNode(
testInputFilePath
);
t.true(couldRead);

const { couldWrite } = await matWriteTransformNode(
transform,
testOutputFilePath
);
t.true(couldWrite);

const { couldRead: couldReadBack, transform: transformBack } =
await matReadTransformNode(testInputFilePath);
t.true(couldReadBack);
verifyTestLinearTransform(t, transformBack);
});
35 changes: 32 additions & 3 deletions packages/transform-io/typescript/test/node/txt-test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
import test from "ava";
import path from "path";

import { txtReadTransformNode } from "../../dist/index-node.js";
import {
txtReadTransformNode,
txtWriteTransformNode,
} from "../../dist/index-node.js";

import { testInputPath, verifyTestLinearTransform } from "./common.js";
import {
testInputPath,
testOutputPath,
verifyTestLinearTransform,
} from "./common.js";

const testInputFilePath = path.join(testInputPath, "LinearTransform.txt");
const testOutputFilePath = path.join(
testOutputPath,
"txt-test-write-LinearTransform.txt"
);

test("Test reading a Insight Legacy TXT transform file", async (t) => {
test("Test reading an Insight Legacy TXT transform file", async (t) => {
const { couldRead, transform } = await txtReadTransformNode(
testInputFilePath
);
t.true(couldRead);
verifyTestLinearTransform(t, transform);
});

test("Test writing an Insight Legacy TXT transform file", async (t) => {
const { couldRead, transform } = await txtReadTransformNode(
testInputFilePath
);
t.true(couldRead);

const { couldWrite } = await txtWriteTransformNode(
transform,
testOutputFilePath
);
t.true(couldWrite);

const { couldRead: couldReadBack, transform: transformBack } =
await txtReadTransformNode(testInputFilePath);
t.true(couldReadBack);
verifyTestLinearTransform(t, transformBack);
});

0 comments on commit c5438d5

Please sign in to comment.