Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bmaranville committed Jan 8, 2025
1 parent c892aa3 commit e05c5b7
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/tests.mjs
Original file line number Diff line number Diff line change
@@ -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']);
});

0 comments on commit e05c5b7

Please sign in to comment.