@jrc03c/js-math-tools
Version:
some math tools for JS
20 lines (17 loc) • 713 B
JavaScript
import { expect, test } from "@jrc03c/fake-jest"
import { filter } from "./filter.mjs"
import { isEqual } from "./is-equal.mjs"
import { range } from "./range.mjs"
import { time } from "./time.mjs"
test("tests that the `filter` function works as expected", () => {
const x = range(0, 100).map(() => Math.random())
const ytrue = x.filter(v => v > 0.5)
const ypred = filter(x, v => v > 0.5)
expect(isEqual(ypred, ytrue)).toBe(true)
})
test("tests that the `filter` function is faster than `Array.prototype.filter`", () => {
const x = range(0, 1e7).map(() => Math.random())
const t1 = time(() => x.filter(v => v > 0.5))
const t2 = time(() => filter(x, v => v > 0.5))
expect(t2).toBeLessThan(t1)
})