-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from rii-mango/MNT/manually-combine-ts-fixes
Mnt/manually combine ts fixes
- Loading branch information
Showing
121 changed files
with
12,239 additions
and
3,387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: test-linux-node18 | ||
|
||
on: | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: "npm" | ||
- run: rm package-lock.json | ||
- run: npm install | ||
- run: npm run build --if-present | ||
- run: npm run test | ||
- run: npm run test-js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isCompressed, readHeader, isNIFTI } from "../src/nifti"; | ||
import { assert } from "chai"; | ||
import * as fs from "fs"; | ||
import { Utils } from "../src/utilities"; | ||
|
||
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('isNIFTI() should return false', function () { | ||
assert.equal(false, isNIFTI(data)); | ||
}); | ||
|
||
it('readHeader() should return null', function () { | ||
assert.equal(null, readHeader(data)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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"; | ||
|
||
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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) { | ||
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { isCompressed, readHeader, readImage, decompress } 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_zeros.nii.gz"); | ||
let data = Utils.toArrayBuffer(buf); | ||
let nifti1: NIFTI1 | NIFTI2 | null; | ||
let imageData = null; | ||
|
||
describe('NIFTI-Reader-JS', function () { | ||
describe('compressed 5D nifti-1 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('should not throw error when reading header', function (done) { | ||
assert.doesNotThrow(function() { | ||
nifti1 = readHeader(data); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('dims[1] should be 256', function () { | ||
assert.equal(256, nifti1!.dims[1]); | ||
}); | ||
|
||
it('dims[2] should be 256', function () { | ||
assert.equal(256, nifti1!.dims[2]); | ||
}); | ||
|
||
it('dims[3] should be 170', function () { | ||
assert.equal(170, 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 33423360', function () { | ||
imageData = readImage(nifti1!, data); | ||
assert.equal(33423360, 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, 2980574675); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { readHeader, decompress, hasExtension, isNIFTI1, readExtensionData } 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 { NIFTIEXTENSION } from "../src/nifti"; | ||
|
||
var buf = fs.readFileSync('./data/with_extension.nii.gz'); | ||
var data = Utils.toArrayBuffer(buf); | ||
let nifti1: NIFTI1 | NIFTI2 | null = null; | ||
let extension: NIFTIEXTENSION | null = null; | ||
const EXPECTED_EXTENSION_LENGTH = 376; | ||
|
||
describe('NIFTI-Reader-JS', function () { | ||
describe('nifti-1 extension test', function () { | ||
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('hasExtension() should return true', function () { | ||
assert.equal(true, hasExtension(nifti1!)); | ||
}); | ||
|
||
it('extension length should be 376 (384 - 8)', function () { | ||
assert.equal(EXPECTED_EXTENSION_LENGTH + 8, nifti1!.getExtensionSize(new DataView(data))); | ||
|
||
assert.equal(EXPECTED_EXTENSION_LENGTH, readExtensionData(nifti1!, data).byteLength); | ||
}); | ||
|
||
it('should have one extension that is 376 bytes', function() { | ||
extension = nifti1!.extensions[0]; | ||
assert.equal(EXPECTED_EXTENSION_LENGTH, extension.edata.byteLength); | ||
assert.equal(1, nifti1!.extensions.length); | ||
}); | ||
|
||
it('removed extension changes the vox offset', function() { | ||
extension = nifti1!.extensions[0]; | ||
assert.equal(EXPECTED_EXTENSION_LENGTH, extension.edata.byteLength); | ||
assert.equal(1, nifti1!.extensions.length); | ||
}); | ||
|
||
it('removed extension updates the vox offset', function() { | ||
let oldVoxOffset = nifti1!.vox_offset; | ||
nifti1!.removeExtension(0); | ||
assert.equal(0, nifti1!.extensions.length); | ||
assert.equal(nifti1!.vox_offset + extension!.esize, oldVoxOffset); | ||
}); | ||
|
||
it('added extension updates vox_offset', function() { | ||
let oldVoxOffset = nifti1!.vox_offset; | ||
nifti1!.addExtension(extension!); | ||
assert.equal(1, nifti1!.extensions.length); | ||
assert.equal(nifti1!.vox_offset, oldVoxOffset + extension!.esize); | ||
}); | ||
|
||
it('toArrayBuffer properly allocates extension byte array', function() { | ||
assert.equal(1, nifti1!.extensions.length); | ||
let bytesWithHeader = nifti1!.toArrayBuffer(true); | ||
let bytesWithoutHeader = nifti1!.toArrayBuffer(); | ||
let headerBytesGreater = bytesWithHeader.byteLength > bytesWithoutHeader.byteLength; | ||
|
||
assert.equal(true, headerBytesGreater); | ||
}); | ||
|
||
it('toArrayBuffer properly preserves extension bytes', function() { | ||
let bytes = nifti1!.toArrayBuffer(true); | ||
let copy = readHeader(bytes); | ||
assert.equal(1, copy!.extensions.length); | ||
assert.equal(EXPECTED_EXTENSION_LENGTH, copy!.extensions[0].edata.byteLength); | ||
}); | ||
|
||
it('extensions can be added and serialized', function() { | ||
let edata = new Int32Array(6); | ||
edata.fill(8); | ||
let newExtension = new NIFTIEXTENSION(32, 4, edata.buffer, true); | ||
nifti1!.addExtension(newExtension); | ||
assert.equal(2, nifti1!.extensions.length); | ||
let bytes = nifti1!.toArrayBuffer(true); | ||
let copy = readHeader(bytes); | ||
assert.equal(2, copy!.extensions.length); | ||
assert.equal(4, copy!.extensions[1].ecode); | ||
assert.equal(24, copy!.extensions[1].edata.byteLength); | ||
}); | ||
|
||
it('extensions can be removed by index', function() { | ||
nifti1!.removeExtension(1); | ||
assert.equal(1, nifti1!.extensions.length); | ||
let bytes = nifti1!.toArrayBuffer(true); | ||
let copy = readHeader(bytes); | ||
assert.equal(1, copy!.extensions.length); | ||
assert.equal(EXPECTED_EXTENSION_LENGTH, copy!.extensions[0].edata.byteLength); | ||
}) | ||
|
||
it('extensions can be inserted and serialized', function() { | ||
let newExtension = new NIFTIEXTENSION(32, 4, new Uint8Array(16), true); | ||
nifti1!.addExtension(newExtension, 0); | ||
assert.equal(2, nifti1!.extensions.length); | ||
let bytes = nifti1!.toArrayBuffer(true); | ||
let copy = readHeader(bytes); | ||
assert.equal(2, copy!.extensions.length); | ||
assert.equal(4, copy!.extensions[0].ecode); | ||
assert.equal(32, copy!.extensions[0].esize); | ||
assert.equal(24, copy!.extensions[0].edata.byteLength); | ||
|
||
}) | ||
|
||
}); | ||
}); |
Oops, something went wrong.