From e05c5b7a3df99ac79fd5d69dc7f367402bf47d7e Mon Sep 17 00:00:00 2001 From: Brian Benjamin Maranville Date: Wed, 8 Jan 2025 16:37:06 -0500 Subject: [PATCH] add tests --- test/tests.mjs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/tests.mjs diff --git a/test/tests.mjs b/test/tests.mjs new file mode 100644 index 0000000..63906dc --- /dev/null +++ b/test/tests.mjs @@ -0,0 +1,34 @@ +import assert from 'node:assert'; +import { test } from 'node:test'; +import { read, readFileSync } from "node:fs"; + +import * as hdf5 from "jsfive"; + +function loadFile(filename) { + const ab = readFileSync(filename); + return new hdf5.File(ab.buffer, filename); +} + +test('check dtypes', () => { + const dtypes = ['f2', 'f4', 'f8', 'i1', 'i2', 'i4']; + const values = [3.0, 4.0, 5.0]; + const f = loadFile("test/test.h5"); + + for (const dtype of dtypes) { + const dset = f.get(dtype); + assert.strictEqual(dset.dtype, `<${dtype}`); + assert.deepEqual(dset.value, values); + } +}); + +test('strings', () => { + const f = loadFile("test/test.h5"); + const dset = f.get('string'); + + assert.strictEqual(dset.dtype, 'S5'); + assert.deepEqual(dset.value, ['hello']); + + const vlen_dset = f.get('vlen_string'); + assert.deepEqual(vlen_dset.dtype, ['VLEN_STRING', 0, 1]); + assert.deepEqual(vlen_dset.value, ['hello']); +}); \ No newline at end of file