Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-linux-node18.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
- run: npm install
- run: npm run build --if-present
- run: npm run test
- run: npm run test-js

7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
tabWidth: 2,
printWidth: 120,
singleQuote: true,
trailingComma: 'none',
semi: false
}
34 changes: 17 additions & 17 deletions __tests__/nifti-not-nifti.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { isCompressed, readHeader, isNIFTI } from "../src/nifti";
import { assert } from "chai";
import * as fs from "fs";
import { Utils } from "../src/utilities";
import { isCompressed, readHeader, isNIFTI } from '../src/nifti.js'
import { describe, it, assert } from 'vitest'
import * as fs from 'fs'
import { Utils } from '../src/utilities.js'

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

describe('NIFTI-Reader-JS', function () {
describe('not-nifti test', function () {
it('isCompressed() should return false', function () {
assert.equal(false, isCompressed(data));
});
it('isCompressed() should return false', function () {
assert.equal(false, isCompressed(data))
})

it('isNIFTI() should return false', function () {
assert.equal(false, isNIFTI(data));
});
it('isNIFTI() should return false', function () {
assert.equal(false, isNIFTI(data))
})

it('readHeader() should return null', function () {
assert.throws(() => readHeader(data), 'That file does not appear to be NIFTI!');
});
});
});
it('readHeader() should return null', function () {
assert.throws(() => readHeader(data), 'That file does not appear to be NIFTI!')
})
})
})
114 changes: 56 additions & 58 deletions __tests__/nifti1-5D-big.spec.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,60 @@
import { isCompressed, readHeader, readImage, decompress, isNIFTI1 } from "../src/nifti";
import { NIFTI1 } from "../src/nifti1";
import { assert } from "chai";
import * as fs from "fs";
import { Utils } from "../src/utilities";
import { NIFTI2 } from "../src/nifti2";
import { isCompressed, readHeader, readImage, decompress, isNIFTI1 } from '../src/nifti.js'
import { NIFTI1 } from '../src/nifti1.js'
import { describe, it, assert } from 'vitest'
import * as fs from 'fs'
import { Utils } from '../src/utilities.js'
import { NIFTI2 } from '../src/nifti2.js'

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

describe('NIFTI-Reader-JS', function () {
describe('nifti-1 big endian test', function () {
it('isCompressed() should return true', function () {
assert.equal(true, isCompressed(data));
});

it('should not throw error when decompressing', function (done) {
assert.doesNotThrow(function() {
data = decompress(data);
done();
});
});

it('isNIFTI1() should return true', function () {
assert.equal(true, isNIFTI1(data));
});

it('should not throw error when reading header', function (done) {
assert.doesNotThrow(function() {
nifti1 = readHeader(data);
done();
});
});

it('numBitsPerVoxel should be 32', function () {
assert.equal(32, nifti1!.numBitsPerVoxel);
});

it('littleEndian should be false', function () {
assert.equal(false, nifti1!.littleEndian);
});

it('dims[1] should be 64', function () {
assert.equal(64, nifti1!.dims[1]);
});

it('dims[2] should be 64', function () {
assert.equal(64, nifti1!.dims[2]);
});

it('dims[3] should be 21', function () {
assert.equal(21, nifti1!.dims[3]);
});

it('image data checksum should equal 3243691439', function () {
var imageData = readImage(nifti1!, data);
var checksum = Utils.crc32(new DataView(imageData));
assert.equal(checksum, 3243691439);
});
});
});
it('isCompressed() should return true', function () {
assert.equal(true, isCompressed(data))
})

it('should not throw error when decompressing', function (done) {
assert.doesNotThrow(function () {
data = decompress(data)
})
})

it('isNIFTI1() should return true', function () {
assert.equal(true, isNIFTI1(data))
})

it('should not throw error when reading header', function (done) {
assert.doesNotThrow(function () {
nifti1 = readHeader(data)
})
})

it('numBitsPerVoxel should be 32', function () {
assert.equal(32, nifti1!.numBitsPerVoxel)
})

it('littleEndian should be false', function () {
assert.equal(false, nifti1!.littleEndian)
})

it('dims[1] should be 64', function () {
assert.equal(64, nifti1!.dims[1])
})

it('dims[2] should be 64', function () {
assert.equal(64, nifti1!.dims[2])
})

it('dims[3] should be 21', function () {
assert.equal(21, nifti1!.dims[3])
})

it('image data checksum should equal 3243691439', function () {
var imageData = readImage(nifti1!, data)
var checksum = Utils.crc32(new DataView(imageData))
assert.equal(checksum, 3243691439)
})
})
})
109 changes: 54 additions & 55 deletions __tests__/nifti1-5D-small.spec.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
import { isCompressed, readHeader, readImage } from "../src/nifti";
import { NIFTI1 } from "../src/nifti1";
import { assert } from "chai";
import * as fs from "fs";
import { Utils } from "../src/utilities";
import { NIFTI2 } from "../src/nifti2";

const buf = fs.readFileSync("./data/5D_small.nii");
const data = Utils.toArrayBuffer(buf);
let nifti1: NIFTI1 | NIFTI2 | null;
let imageData = null;

describe("NIFTI-Reader-JS", () => {
describe("uncompressed 5D nifti-1 test", function () {
it("isCompressed() should return false", function () {
assert.equal(false, isCompressed(data));
});
it("should not throw error when reading header", function (done) {
import { isCompressed, readHeader, readImage } from '../src/nifti.js'
import { NIFTI1 } from '../src/nifti1.js'
import { describe, it, assert } from 'vitest'
import * as fs from 'fs'
import { Utils } from '../src/utilities.js'
import { NIFTI2 } from '../src/nifti2.js'

const buf = fs.readFileSync('./data/5D_small.nii')
const data = Utils.toArrayBuffer(buf)
let nifti1: NIFTI1 | NIFTI2 | null
let imageData: ArrayBuffer | null = null

describe('NIFTI-Reader-JS', () => {
describe('uncompressed 5D nifti-1 test', function () {
it('isCompressed() should return false', function () {
assert.equal(false, isCompressed(data))
})
it('should not throw error when reading header', function (done) {
assert.doesNotThrow(function () {
nifti1 = readHeader(data);
done();
});
});

it("dims[1] should be 1", function () {
assert.equal(1, nifti1!.dims[1]);
});

it("dims[2] should be 2", function () {
assert.equal(2, nifti1!.dims[2]);
});

it("dims[3] should be 3", function () {
assert.equal(3, nifti1!.dims[3]);
});

it("dims[4] should be 1", function () {
assert.equal(1, nifti1!.dims[4]);
});

it("dims[5] should be 3", function () {
assert.equal(3, nifti1!.dims[5]);
});

it("image size should equal 1 * 2 * 3 * 1 * 3", function () {
imageData = readImage(nifti1!, data);
assert.equal(18, imageData.byteLength);
});

it("image data checksum should equal 1033497386", function () {
var imageData = readImage(nifti1!, data);
var checksum = Utils.crc32(new DataView(imageData));
assert.equal(checksum, 1168954819);
});
});
});
nifti1 = readHeader(data)
})
})

it('dims[1] should be 1', function () {
assert.equal(1, nifti1!.dims[1])
})

it('dims[2] should be 2', function () {
assert.equal(2, nifti1!.dims[2])
})

it('dims[3] should be 3', function () {
assert.equal(3, nifti1!.dims[3])
})

it('dims[4] should be 1', function () {
assert.equal(1, nifti1!.dims[4])
})

it('dims[5] should be 3', function () {
assert.equal(3, nifti1!.dims[5])
})

it('image size should equal 1 * 2 * 3 * 1 * 3', function () {
imageData = readImage(nifti1!, data)
assert.equal(18, imageData.byteLength)
})

it('image data checksum should equal 1033497386', function () {
var imageData = readImage(nifti1!, data)
var checksum = Utils.crc32(new DataView(imageData))
assert.equal(checksum, 1168954819)
})
})
})
Loading