Fix test to use Date

This commit is contained in:
Matthias 2022-09-14 20:20:15 +02:00
parent 43d6ae3884
commit d94c2e72be

View File

@ -1,6 +1,6 @@
import { binData } from '@/shared/charts/binCount'; import { binData } from '@/shared/charts/binCount';
describe.only('binCount.ts', () => { describe('binCount.ts', () => {
it('Bins data as expected', () => { it('Bins data as expected', () => {
const testData = [1, 1, 2, 3, 5, 6, 8, 10]; const testData = [1, 1, 2, 3, 5, 6, 8, 10];
const res = binData(testData, 3); const res = binData(testData, 3);
@ -37,10 +37,10 @@ describe.only('binCount.ts', () => {
it('Bins data performant', () => { it('Bins data performant', () => {
const randomSize = 20000; const randomSize = 20000;
const randomData = Array.from({ length: randomSize }, () => Math.floor(Math.random() * 10)); const randomData = Array.from({ length: randomSize }, () => Math.floor(Math.random() * 10));
const startTime = performance.now(); const startTime = Date.now();
const res = binData(randomData, 5); const res = binData(randomData, 5);
const endTime = performance.now(); const endTime = Date.now();
expect(endTime - startTime).toBeLessThan(20); expect(endTime - startTime).toBeLessThan(20);
expect(res.map((v) => v[1]).reduce((a, b) => a + b)).toEqual(randomData.length); expect(res.map((v) => v[1]).reduce((a, b) => a + b)).toEqual(randomData.length);