Skip to content

Commit b18d386

Browse files
authored
Merge pull request #51 from rii-mango/hanayik/update-tests-and-fix-build
update tests and fix build
2 parents cb6fc56 + 4f43cc7 commit b18d386

File tree

86 files changed

+8943
-9355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+8943
-9355
lines changed

.github/workflows/test-linux-node18.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
- run: npm install
2828
- run: npm run build --if-present
2929
- run: npm run test
30-
- run: npm run test-js
30+

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
tabWidth: 2,
3+
printWidth: 120,
4+
singleQuote: true,
5+
trailingComma: 'none',
6+
semi: false
7+
}

__tests__/nifti-not-nifti.spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import { isCompressed, readHeader, isNIFTI } from "../src/nifti";
2-
import { assert } from "chai";
3-
import * as fs from "fs";
4-
import { Utils } from "../src/utilities";
1+
import { isCompressed, readHeader, isNIFTI } from '../src/nifti.js'
2+
import { describe, it, assert } from 'vitest'
3+
import * as fs from 'fs'
4+
import { Utils } from '../src/utilities.js'
55

6-
const buf = fs.readFileSync("./data/not-nifti.nii");
7-
let data = Utils.toArrayBuffer(buf);
6+
const buf = fs.readFileSync('./data/not-nifti.nii')
7+
let data = Utils.toArrayBuffer(buf)
88

99
describe('NIFTI-Reader-JS', function () {
1010
describe('not-nifti test', function () {
11-
it('isCompressed() should return false', function () {
12-
assert.equal(false, isCompressed(data));
13-
});
11+
it('isCompressed() should return false', function () {
12+
assert.equal(false, isCompressed(data))
13+
})
1414

15-
it('isNIFTI() should return false', function () {
16-
assert.equal(false, isNIFTI(data));
17-
});
15+
it('isNIFTI() should return false', function () {
16+
assert.equal(false, isNIFTI(data))
17+
})
1818

19-
it('readHeader() should return null', function () {
20-
assert.throws(() => readHeader(data), 'That file does not appear to be NIFTI!');
21-
});
22-
});
23-
});
19+
it('readHeader() should return null', function () {
20+
assert.throws(() => readHeader(data), 'That file does not appear to be NIFTI!')
21+
})
22+
})
23+
})

__tests__/nifti1-5D-big.spec.ts

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,60 @@
1-
import { isCompressed, readHeader, readImage, decompress, isNIFTI1 } from "../src/nifti";
2-
import { NIFTI1 } from "../src/nifti1";
3-
import { assert } from "chai";
4-
import * as fs from "fs";
5-
import { Utils } from "../src/utilities";
6-
import { NIFTI2 } from "../src/nifti2";
1+
import { isCompressed, readHeader, readImage, decompress, isNIFTI1 } from '../src/nifti.js'
2+
import { NIFTI1 } from '../src/nifti1.js'
3+
import { describe, it, assert } from 'vitest'
4+
import * as fs from 'fs'
5+
import { Utils } from '../src/utilities.js'
6+
import { NIFTI2 } from '../src/nifti2.js'
77

8-
const buf = fs.readFileSync("./data/big.nii.gz");
9-
let data = Utils.toArrayBuffer(buf);
10-
let nifti1: NIFTI1 | NIFTI2 | null;
8+
const buf = fs.readFileSync('./data/big.nii.gz')
9+
let data = Utils.toArrayBuffer(buf)
10+
let nifti1: NIFTI1 | NIFTI2 | null
1111

1212
describe('NIFTI-Reader-JS', function () {
1313
describe('nifti-1 big endian test', function () {
14-
it('isCompressed() should return true', function () {
15-
assert.equal(true, isCompressed(data));
16-
});
17-
18-
it('should not throw error when decompressing', function (done) {
19-
assert.doesNotThrow(function() {
20-
data = decompress(data);
21-
done();
22-
});
23-
});
24-
25-
it('isNIFTI1() should return true', function () {
26-
assert.equal(true, isNIFTI1(data));
27-
});
28-
29-
it('should not throw error when reading header', function (done) {
30-
assert.doesNotThrow(function() {
31-
nifti1 = readHeader(data);
32-
done();
33-
});
34-
});
35-
36-
it('numBitsPerVoxel should be 32', function () {
37-
assert.equal(32, nifti1!.numBitsPerVoxel);
38-
});
39-
40-
it('littleEndian should be false', function () {
41-
assert.equal(false, nifti1!.littleEndian);
42-
});
43-
44-
it('dims[1] should be 64', function () {
45-
assert.equal(64, nifti1!.dims[1]);
46-
});
47-
48-
it('dims[2] should be 64', function () {
49-
assert.equal(64, nifti1!.dims[2]);
50-
});
51-
52-
it('dims[3] should be 21', function () {
53-
assert.equal(21, nifti1!.dims[3]);
54-
});
55-
56-
it('image data checksum should equal 3243691439', function () {
57-
var imageData = readImage(nifti1!, data);
58-
var checksum = Utils.crc32(new DataView(imageData));
59-
assert.equal(checksum, 3243691439);
60-
});
61-
});
62-
});
14+
it('isCompressed() should return true', function () {
15+
assert.equal(true, isCompressed(data))
16+
})
17+
18+
it('should not throw error when decompressing', function (done) {
19+
assert.doesNotThrow(function () {
20+
data = decompress(data)
21+
})
22+
})
23+
24+
it('isNIFTI1() should return true', function () {
25+
assert.equal(true, isNIFTI1(data))
26+
})
27+
28+
it('should not throw error when reading header', function (done) {
29+
assert.doesNotThrow(function () {
30+
nifti1 = readHeader(data)
31+
})
32+
})
33+
34+
it('numBitsPerVoxel should be 32', function () {
35+
assert.equal(32, nifti1!.numBitsPerVoxel)
36+
})
37+
38+
it('littleEndian should be false', function () {
39+
assert.equal(false, nifti1!.littleEndian)
40+
})
41+
42+
it('dims[1] should be 64', function () {
43+
assert.equal(64, nifti1!.dims[1])
44+
})
45+
46+
it('dims[2] should be 64', function () {
47+
assert.equal(64, nifti1!.dims[2])
48+
})
49+
50+
it('dims[3] should be 21', function () {
51+
assert.equal(21, nifti1!.dims[3])
52+
})
53+
54+
it('image data checksum should equal 3243691439', function () {
55+
var imageData = readImage(nifti1!, data)
56+
var checksum = Utils.crc32(new DataView(imageData))
57+
assert.equal(checksum, 3243691439)
58+
})
59+
})
60+
})

__tests__/nifti1-5D-small.spec.ts

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
1-
import { isCompressed, readHeader, readImage } from "../src/nifti";
2-
import { NIFTI1 } from "../src/nifti1";
3-
import { assert } from "chai";
4-
import * as fs from "fs";
5-
import { Utils } from "../src/utilities";
6-
import { NIFTI2 } from "../src/nifti2";
7-
8-
const buf = fs.readFileSync("./data/5D_small.nii");
9-
const data = Utils.toArrayBuffer(buf);
10-
let nifti1: NIFTI1 | NIFTI2 | null;
11-
let imageData = null;
12-
13-
describe("NIFTI-Reader-JS", () => {
14-
describe("uncompressed 5D nifti-1 test", function () {
15-
it("isCompressed() should return false", function () {
16-
assert.equal(false, isCompressed(data));
17-
});
18-
it("should not throw error when reading header", function (done) {
1+
import { isCompressed, readHeader, readImage } from '../src/nifti.js'
2+
import { NIFTI1 } from '../src/nifti1.js'
3+
import { describe, it, assert } from 'vitest'
4+
import * as fs from 'fs'
5+
import { Utils } from '../src/utilities.js'
6+
import { NIFTI2 } from '../src/nifti2.js'
7+
8+
const buf = fs.readFileSync('./data/5D_small.nii')
9+
const data = Utils.toArrayBuffer(buf)
10+
let nifti1: NIFTI1 | NIFTI2 | null
11+
let imageData: ArrayBuffer | null = null
12+
13+
describe('NIFTI-Reader-JS', () => {
14+
describe('uncompressed 5D nifti-1 test', function () {
15+
it('isCompressed() should return false', function () {
16+
assert.equal(false, isCompressed(data))
17+
})
18+
it('should not throw error when reading header', function (done) {
1919
assert.doesNotThrow(function () {
20-
nifti1 = readHeader(data);
21-
done();
22-
});
23-
});
24-
25-
it("dims[1] should be 1", function () {
26-
assert.equal(1, nifti1!.dims[1]);
27-
});
28-
29-
it("dims[2] should be 2", function () {
30-
assert.equal(2, nifti1!.dims[2]);
31-
});
32-
33-
it("dims[3] should be 3", function () {
34-
assert.equal(3, nifti1!.dims[3]);
35-
});
36-
37-
it("dims[4] should be 1", function () {
38-
assert.equal(1, nifti1!.dims[4]);
39-
});
40-
41-
it("dims[5] should be 3", function () {
42-
assert.equal(3, nifti1!.dims[5]);
43-
});
44-
45-
it("image size should equal 1 * 2 * 3 * 1 * 3", function () {
46-
imageData = readImage(nifti1!, data);
47-
assert.equal(18, imageData.byteLength);
48-
});
49-
50-
it("image data checksum should equal 1033497386", function () {
51-
var imageData = readImage(nifti1!, data);
52-
var checksum = Utils.crc32(new DataView(imageData));
53-
assert.equal(checksum, 1168954819);
54-
});
55-
});
56-
});
20+
nifti1 = readHeader(data)
21+
})
22+
})
23+
24+
it('dims[1] should be 1', function () {
25+
assert.equal(1, nifti1!.dims[1])
26+
})
27+
28+
it('dims[2] should be 2', function () {
29+
assert.equal(2, nifti1!.dims[2])
30+
})
31+
32+
it('dims[3] should be 3', function () {
33+
assert.equal(3, nifti1!.dims[3])
34+
})
35+
36+
it('dims[4] should be 1', function () {
37+
assert.equal(1, nifti1!.dims[4])
38+
})
39+
40+
it('dims[5] should be 3', function () {
41+
assert.equal(3, nifti1!.dims[5])
42+
})
43+
44+
it('image size should equal 1 * 2 * 3 * 1 * 3', function () {
45+
imageData = readImage(nifti1!, data)
46+
assert.equal(18, imageData.byteLength)
47+
})
48+
49+
it('image data checksum should equal 1033497386', function () {
50+
var imageData = readImage(nifti1!, data)
51+
var checksum = Utils.crc32(new DataView(imageData))
52+
assert.equal(checksum, 1168954819)
53+
})
54+
})
55+
})

0 commit comments

Comments
 (0)