Skip to content

Commit

Permalink
test: separate test task
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed May 29, 2024
1 parent 760482d commit f349681
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
18 changes: 12 additions & 6 deletions lib/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`work fine 1`] = `
exports[`Module 1`] = `
Float32Array [
1,
4,
Expand All @@ -11,29 +11,35 @@ Float32Array [
]
`;

exports[`work fine 2`] = `
exports[`Tensor 1`] = `
Float32Array [
2,
4,
6,
]
`;

exports[`work fine 3`] = `
exports[`Tensor 2`] = `
Float32Array [
0,
4,
6,
]
`;

exports[`work fine 4`] = `
exports[`Tensor 3`] = `
Float32Array [
0,
0,
1,
2,
1,
2,
3,
4,
3,
4,
5,
6,
5,
6,
]
`;
9 changes: 6 additions & 3 deletions lib/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Module, Tensor } from "./index";

const model = path.resolve(__dirname, "__fixtures__/mul.pte");

it("work fine", async () => {
it("Module", async () => {
const mod = await Module.load(model);
expect(mod.method_names).toEqual(["forward"]);
const input = new Tensor("float32", [3, 2], new Float32Array([1, 2, 3, 4, 5, 6]));
Expand All @@ -14,7 +14,10 @@ it("work fine", async () => {
expect(outputs[0].shape).toEqual([3, 2]);
expect(outputs[0].data).toMatchSnapshot();
}
});

it("Tensor", async () => {
const input = new Tensor("float32", [3, 2], new Float32Array([1, 2, 3, 4, 5, 6]));
const slice = input.slice([null, [1, null]]);
expect(slice.dtype).toBe("float32");
expect(slice.shape).toEqual([3, 1]);
Expand All @@ -23,8 +26,8 @@ it("work fine", async () => {
slice.setIndex([0, 0], 0);
expect(slice.data).toMatchSnapshot();

const concat = Tensor.concat([slice, slice], 1);
const concat = Tensor.concat([input, input], 1);
expect(concat.dtype).toBe("float32");
expect(concat.shape).toEqual([3, 2]);
expect(concat.shape).toEqual([3, 4]);
expect(concat.data).toMatchSnapshot();
});

0 comments on commit f349681

Please sign in to comment.