Skip to content

Commit

Permalink
Add tests for custom arrayable functions (#12892)
Browse files Browse the repository at this point in the history
* Add tests for custom arrayable functions

* add more tests for arrayable

* fix ESLint error

* fix another ESLint error
  • Loading branch information
DerTimonius committed Mar 15, 2023
1 parent e76262b commit 4f5d842
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion bokehjs/test/unit/core/util/arrayable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect} from "assertions"
import * as arrayable from "@bokehjs/core/util/arrayable"
import {expect} from "assertions"

describe("core/util/arrayable module", () => {

Expand Down Expand Up @@ -159,4 +159,60 @@ describe("core/util/arrayable module", () => {
expect(arrayable.interpolate([], [], [])).to.be.equal([])
expect(arrayable.interpolate([1], [], [])).to.be.equal([NaN])
})

it("should support subselect() function", () => {
const a = [1, 2, 3, 4, 5, 6, undefined]
const b = [1, 4, 5]
expect(arrayable.subselect(a, b)).to.be.equal([2, 5, 6])
const c = [0, 100]
const d = [10, NaN]
expect(arrayable.subselect(a, c)).to.be.equal([1, undefined])
expect(arrayable.subselect(a, d)).to.be.equal([undefined, undefined])
})

it("should support insert() function", () => {
expect(arrayable.insert([1, 2, 3], 4, 1)).to.be.equal([1, 4, 2, 3])
})

it("should support append() function", () => {
expect(arrayable.append([1, 2, 3], 4)).to.be.equal([1, 2, 3, 4])
})

it("should support prepend() function", () => {
expect(arrayable.prepend([1, 2, 3], 4)).to.be.equal([4, 1, 2, 3])
})

it("should support mul() function", () => {
const a = [1, 2, 3]
const b = [2, 4, 6]
expect(arrayable.mul(a, 2)).to.be.equal(b)
})

it("should support map() function", () => {
const a = [1, 2, 3]
const b = [2, 4, 6]
expect(arrayable.map(a, (num) => num * 2)).to.be.equal(b)
})

it("should support map() function with Float32Array", () => {
const arr = Float32Array.of(1, 2, 3)
const ret = arrayable.map(arr, (num) => num * 2)
expect(ret).to.be.instanceof(Float32Array)
expect(ret).to.be.equal(Float32Array.of(2, 4, 6))
})

it("should support sum() function", () => {
expect(arrayable.sum([1, 2, 3, 4])).to.be.equal(10)
expect(arrayable.sum([1, 2, 3, NaN])).to.be.equal(NaN)
})

it("should support some() function", () => {
expect(arrayable.some([-1, 2, 6, 11], (num) => num % 2 === 0)).to.be.true
expect(arrayable.some([1, 2, 3, 4], (num) => num > 5)).to.be.false
})

it("should support every() function", () => {
expect(arrayable.every([1, 2, 3, 4], (num) => num > 0)).to.be.true
expect(arrayable.every([-2, 1, 2, 3, 4], (num) => num > 0)).to.be.false
})
})

0 comments on commit 4f5d842

Please sign in to comment.