Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Nov 19, 2019
1 parent cb34407 commit df8daef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/array.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import value from "./value.js";
import {default as numberArray, isNumberArray} from "./numberArray.js";
import numberArray, {isNumberArray} from "./numberArray.js";

export default function(a, b) {
if (isNumberArray(b)) return numberArray(a, b);
Expand Down
2 changes: 1 addition & 1 deletion src/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import number from "./number.js";
import object from "./object.js";
import string from "./string.js";
import constant from "./constant.js";
import {default as numberArray, isNumberArray} from "./numberArray.js";
import numberArray, {isNumberArray} from "./numberArray.js";

export default function(a, b) {
var t = typeof b, c;
Expand Down
23 changes: 15 additions & 8 deletions test/numberArray-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ var tape = require("tape"),
interpolate = require("../");

tape("interpolateNumberArray(a, b) interpolates defined elements in a and b", function(test) {
test.deepEqual(interpolate.interpolateNumberArray(Float64Array.from([2, 12]), Float64Array.from([4, 24]))(0.5), Float64Array.from([3, 18]));
test.deepEqual(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Float64Array.of(4, 24))(0.5), Float64Array.of(3, 18));
test.end();
});

tape("interpolateNumberArray(a, b) ignores elements in a that are not in b", function(test) {
test.deepEqual(interpolate.interpolateNumberArray(Float64Array.from([2, 12, 12]), Float64Array.from([4, 24]))(0.5), Float64Array.from([3, 18]));
test.deepEqual(interpolate.interpolateNumberArray(Float64Array.of(2, 12, 12), Float64Array.of(4, 24))(0.5), Float64Array.of(3, 18));
test.end();
});

tape("interpolateNumberArray(a, b) uses constant elements in b that are not in a", function(test) {
test.deepEqual(interpolate.interpolateNumberArray(Float64Array.from([2, 12]), Float64Array.from([4, 24, 12]))(0.5), Float64Array.from([3, 18, 12]));
test.deepEqual(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Float64Array.of(4, 24, 12))(0.5), Float64Array.of(3, 18, 12));
test.end();
});

Expand All @@ -24,14 +24,21 @@ tape("interpolateNumberArray(a, b) treats undefined as an empty array", function
});

tape("interpolateNumberArray(a, b) uses b’s array type", function(test) {
test.ok(interpolate.interpolateNumberArray(Float64Array.from([2, 12]), Float64Array.from([4, 24, 12]))(0.5) instanceof Float64Array);
test.ok(interpolate.interpolateNumberArray(Float64Array.from([2, 12]), Float32Array.from([4, 24, 12]))(0.5) instanceof Float32Array);
test.ok(interpolate.interpolateNumberArray(Float64Array.from([2, 12]), Uint8Array.from([4, 24, 12]))(0.5) instanceof Uint8Array);
test.ok(interpolate.interpolateNumberArray(Float64Array.from([2, 12]), Uint16Array.from([4, 24, 12]))(0.5) instanceof Uint16Array);
test.ok(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Float64Array.of(4, 24, 12))(0.5) instanceof Float64Array);
test.ok(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Float32Array.of(4, 24, 12))(0.5) instanceof Float32Array);
test.ok(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Uint8Array.of(4, 24, 12))(0.5) instanceof Uint8Array);
test.ok(interpolate.interpolateNumberArray(Float64Array.of(2, 12), Uint16Array.of(4, 24, 12))(0.5) instanceof Uint16Array);
test.end();
});

tape("interpolateNumberArray(a, b) works with unsigned data", function(test) {
test.deepEqual(interpolate.interpolateNumberArray(Uint8Array.from([1, 12]), Uint8Array.from([255, 0]))(0.5), Uint8Array.from([128, 6]));
test.deepEqual(interpolate.interpolateNumberArray(Uint8Array.of(1, 12), Uint8Array.of(255, 0))(0.5), Uint8Array.of(128, 6));
test.end();
});

tape("interpolateNumberArray(a, b) gives exact ends", function(test) {
var i = interpolate.interpolateNumberArray(Float64Array.of(2e42), Float64Array.of(355));
test.deepEqual(i(0), Float64Array.of(2e42));
test.deepEqual(i(1), Float64Array.of(355));
test.end();
});
16 changes: 8 additions & 8 deletions test/value-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ tape("interpolate(a, b) interpolates objects with toString as objects if toStrin
});

tape("interpolate(a, b) interpolates number arrays if b is a typed array", function(test) {
test.deepEqual(interpolate.interpolate([0, 0], Float64Array.from([-1, 1]))(0.5), Float64Array.from([-0.5, 0.5]));
test.assert(interpolate.interpolate([0, 0], Float64Array.from([-1, 1]))(0.5) instanceof Float64Array);
test.deepEqual(interpolate.interpolate([0, 0], Float32Array.from([-1, 1]))(0.5), Float32Array.from([-0.5, 0.5]));
test.assert(interpolate.interpolate([0, 0], Float32Array.from([-1, 1]))(0.5) instanceof Float32Array);
test.deepEqual(interpolate.interpolate([0, 0], Uint32Array.from([-2, 2]))(0.5), Uint32Array.from([Math.pow(2, 31) - 1, 1]));
test.assert(interpolate.interpolate([0, 0], Uint32Array.from([-1, 1]))(0.5) instanceof Uint32Array);
test.deepEqual(interpolate.interpolate([0, 0], Uint8Array.from([-2, 2]))(0.5), Uint8Array.from([Math.pow(2, 7) - 1, 1]));
test.assert(interpolate.interpolate([0, 0], Uint8Array.from([-1, 1]))(0.5) instanceof Uint8Array);
test.deepEqual(interpolate.interpolate([0, 0], Float64Array.of(-1, 1))(0.5), Float64Array.of(-0.5, 0.5));
test.assert(interpolate.interpolate([0, 0], Float64Array.of(-1, 1))(0.5) instanceof Float64Array);
test.deepEqual(interpolate.interpolate([0, 0], Float32Array.of(-1, 1))(0.5), Float32Array.of(-0.5, 0.5));
test.assert(interpolate.interpolate([0, 0], Float32Array.of(-1, 1))(0.5) instanceof Float32Array);
test.deepEqual(interpolate.interpolate([0, 0], Uint32Array.of(-2, 2))(0.5), Uint32Array.of(Math.pow(2, 31) - 1, 1));
test.assert(interpolate.interpolate([0, 0], Uint32Array.of(-1, 1))(0.5) instanceof Uint32Array);
test.deepEqual(interpolate.interpolate([0, 0], Uint8Array.of(-2, 2))(0.5), Uint8Array.of(Math.pow(2, 7) - 1, 1));
test.assert(interpolate.interpolate([0, 0], Uint8Array.of(-1, 1))(0.5) instanceof Uint8Array);
test.end();
});

Expand Down

0 comments on commit df8daef

Please sign in to comment.