1
+ import assert from 'node:assert' ;
2
+ import { test } from 'node:test' ;
3
+ import { read , readFileSync } from "node:fs" ;
4
+
5
+ import * as hdf5 from "jsfive" ;
6
+
7
+ function loadFile ( filename ) {
8
+ const ab = readFileSync ( filename ) ;
9
+ return new hdf5 . File ( ab . buffer , filename ) ;
10
+ }
11
+
12
+ test ( 'check dtypes' , ( ) => {
13
+ const dtypes = [ 'f2' , 'f4' , 'f8' , 'i1' , 'i2' , 'i4' ] ;
14
+ const values = [ 3.0 , 4.0 , 5.0 ] ;
15
+ const f = loadFile ( "test/test.h5" ) ;
16
+
17
+ for ( const dtype of dtypes ) {
18
+ const dset = f . get ( dtype ) ;
19
+ assert . strictEqual ( dset . dtype , `<${ dtype } ` ) ;
20
+ assert . deepEqual ( dset . value , values ) ;
21
+ }
22
+ } ) ;
23
+
24
+ test ( 'strings' , ( ) => {
25
+ const f = loadFile ( "test/test.h5" ) ;
26
+ const dset = f . get ( 'string' ) ;
27
+
28
+ assert . strictEqual ( dset . dtype , 'S5' ) ;
29
+ assert . deepEqual ( dset . value , [ 'hello' ] ) ;
30
+
31
+ const vlen_dset = f . get ( 'vlen_string' ) ;
32
+ assert . deepEqual ( vlen_dset . dtype , [ 'VLEN_STRING' , 0 , 1 ] ) ;
33
+ assert . deepEqual ( vlen_dset . value , [ 'hello' ] ) ;
34
+ } ) ;
0 commit comments