Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
petamoriken committed Dec 20, 2021
1 parent 5a54bfa commit 6723ac3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions test/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import {
} from "../../src/index.mjs";

const float16 = new Float16Array([1.0, 1.1, 1.2]);
assert(float16.reduce((prev, current) => prev + current) === 3.298828125);
assertEqualsTrue(float16.reduce((prev, current) => prev + current) === 3.298828125);

assert(isFloat16Array(float16));
assert(isFloat16Array(new Float32Array()) === false);
assert(isFloat16Array(new Uint16Array()) === false);
assertEqualsTrue(isFloat16Array(float16));
assertEqualsTrue(isFloat16Array(new Float32Array()) === false);
assertEqualsTrue(isFloat16Array(new Uint16Array()) === false);

assert(isTypedArray(float16));
assert(isTypedArray(new Float32Array()));
assert(isTypedArray(new Uint16Array()));
assertEqualsTrue(isTypedArray(float16));
assertEqualsTrue(isTypedArray(new Float32Array()));
assertEqualsTrue(isTypedArray(new Uint16Array()));

const buffer = new ArrayBuffer(2);
const view = new DataView(buffer);

setFloat16(view, 0, Math.PI, true);
assert(getFloat16(view, 0, true) === 3.140625);
assertEqualsTrue(getFloat16(view, 0, true) === 3.140625);

assert(hfround(1.337) === 1.3369140625);
assertEqualsTrue(hfround(1.337) === 1.3369140625);

function assert(target) {
function assertEqualsTrue(target) {
if (target !== true) {
throw new Error("Assertion failed");
}
Expand Down

0 comments on commit 6723ac3

Please sign in to comment.