UNPKG

@aptpod/data-viz-create-visual-parts-react

Version:

template of npm project with typescript

64 lines (55 loc) 1.88 kB
import { arraySearchIndexLe, arraySearchIndexGe } from './utils' /** * arraySearchIndexLe のテスト */ describe('arraySearchIndexLe', () => { type TestData = { args: { array: number[] searchElement: number } exp: number } const nums = [0, 1, 2, 3, 4, 5] const compiler = (a: number, b: number) => a - b const testDatas: TestData[] = [ { args: { array: nums, searchElement: -1 }, exp: -1 }, { args: { array: nums, searchElement: 0.5 }, exp: 0 }, { args: { array: nums, searchElement: 2 }, exp: 2 }, { args: { array: nums, searchElement: 4.5 }, exp: 4 }, { args: { array: nums, searchElement: 10 }, exp: 5 }, ] testDatas.forEach(({ args: { array, searchElement }, exp }) => { const arrayString = JSON.stringify(array) test(`returns ${exp} when array=${arrayString}, searchElement=${searchElement}`, () => { expect(arraySearchIndexLe(array, searchElement, compiler)).toBe(exp) }) }) }) /** * arraySearchIndexGe のテスト */ describe('arraySearchIndexGe', () => { type TestData = { args: { array: number[] searchElement: number } exp: number } const nums = [0, 1, 2, 3, 4, 5] const compiler = (a: number, b: number) => a - b const testDatas: TestData[] = [ { args: { array: nums, searchElement: -1 }, exp: 0 }, { args: { array: nums, searchElement: 0.5 }, exp: 1 }, { args: { array: nums, searchElement: 2 }, exp: 2 }, { args: { array: nums, searchElement: 4.5 }, exp: 5 }, { args: { array: nums, searchElement: 10 }, exp: -1 }, ] testDatas.forEach(({ args: { array, searchElement }, exp }) => { const arrayString = JSON.stringify(array) test(`returns ${exp} when array=${arrayString}, searchElement=${searchElement}`, () => { expect(arraySearchIndexGe(array, searchElement, compiler)).toBe(exp) }) }) })