Skip to content

Commit

Permalink
fix: xAdd/substract/divide/multiply also work with floatarray (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjappelbaum authored Feb 16, 2021
1 parent 3fbd82b commit 6460573
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/x/__tests__/xAdd.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ describe('xAdd', function () {
let array1 = [10, 11, 12, 13, 14];
expect(xAdd(array1, 5)).toStrictEqual([15, 16, 17, 18, 19]);
});

it('test xAdd of array and floatarray', () => {
let array1 = [10, 11, 12, 13, 14];
let array2 = new Float32Array([5, 4, 3, 2, 1]);
expect(xAdd(array1, array2)).toStrictEqual([15, 15, 15, 15, 15]);
});
});
5 changes: 5 additions & 0 deletions src/x/__tests__/xDivide.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ describe('divide', function () {
expect(xDivide(array1, array2)).toStrictEqual([5, 5, 5, 5, 5]);
});

it('test divide of Array and FloatArray', () => {
let array1 = [10, 15, 20, 25, 30];
let array2 = new Float64Array([2, 3, 4, 5, 6]);
expect(xDivide(array1, array2)).toStrictEqual([5, 5, 5, 5, 5]);
});
it('test mul of 2 a constant', () => {
let array1 = [10, 15, 20, 25, 30];
expect(xDivide(array1, 5)).toStrictEqual([2, 3, 4, 5, 6]);
Expand Down
12 changes: 12 additions & 0 deletions src/x/__tests__/xMultiply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ describe('xMultiply', function () {
]);
});

it('test mul of array and floatarray', () => {
let array1 = [10, 11, 12, 13, 14];
let array2 = new Float64Array([5, 4, 3, 2, 1]);
expect(Array.from(xMultiply(array1, array2))).toStrictEqual([
50,
44,
36,
26,
14,
]);
});

it('test mul of 2 a constant', () => {
let array1 = [10, 11, 12, 13, 14];
expect(Array.from(xMultiply(array1, 5))).toStrictEqual([
Expand Down
6 changes: 6 additions & 0 deletions src/x/__tests__/xSubtract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ describe('xSubtract', function () {
let array1 = [10, 11, 12, 13, 14];
expect(xSubtract(array1, 5)).toStrictEqual([5, 6, 7, 8, 9]);
});

it('test xSubtract of array and floatarray', () => {
let array1 = new Float32Array([10, 11, 12, 13, 14]);
let array2 = [5, 4, 3, 2, 1];
expect(xSubtract(array1, array2)).toStrictEqual([5, 7, 9, 11, 13]);
});
});
4 changes: 2 additions & 2 deletions src/x/xAdd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
import isAnyArray from 'is-any-array';

/**
* This function xAdd the first array by the second array or a constant value to each element of the first array
Expand All @@ -9,7 +9,7 @@
export function xAdd(array1, array2) {
let isConstant = false;
let constant;
if (Array.isArray(array2)) {
if (isAnyArray(array2)) {
if (array1.length !== array2.length) {
throw new Error('sub: size of array1 and array2 must be identical');
}
Expand Down
4 changes: 2 additions & 2 deletions src/x/xDivide.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
import isAnyArray from 'is-any-array';

/**
* This function divide the first array by the second array or a constant value to each element of the first array
Expand All @@ -9,7 +9,7 @@
export function xDivide(array1, array2) {
let isConstant = false;
let constant;
if (Array.isArray(array2)) {
if (isAnyArray(array2)) {
if (array1.length !== array2.length) {
throw new Error('sub: size of array1 and array2 must be identical');
}
Expand Down
5 changes: 2 additions & 3 deletions src/x/xMultiply.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
import isAnyArray from 'is-any-array';
/**
* This function xMultiply the first array by the second array or a constant value to each element of the first array
* @param {Array} array1 - the array that will be rotated
Expand All @@ -9,7 +8,7 @@
export function xMultiply(array1, array2) {
let isConstant = false;
let constant;
if (Array.isArray(array2)) {
if (isAnyArray(array2)) {
if (array1.length !== array2.length) {
throw new Error('sub: size of array1 and array2 must be identical');
}
Expand Down
3 changes: 2 additions & 1 deletion src/x/xSubtract.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isAnyArray from 'is-any-array';
/**
* This function xSubtract the first array by the second array or a constant value from each element of the first array
* @param {Array} array1 - the array that will be rotated
Expand All @@ -7,7 +8,7 @@
export function xSubtract(array1, array2) {
let isConstant = false;
let constant;
if (Array.isArray(array2)) {
if (isAnyArray(array2)) {
if (array1.length !== array2.length) {
throw new Error('sub: size of array1 and array2 must be identical');
}
Expand Down

0 comments on commit 6460573

Please sign in to comment.