Skip to content

Commit

Permalink
tslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlund-wandb committed Dec 13, 2024
1 parent 2a6fcff commit 01b7661
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions weave-js/src/common/components/elements/SliderInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,62 @@ import {getClosestTick} from './SliderInput';

describe('getClosestTick', () => {
test('lower previous value returns next greater', () => {
let ticks = [...new Set([2, 4, 6, 8, 10])],
previous = 4,
val = 5;

const ticks = [2, 4, 6, 8, 10];
const previous = 4;
const val = 5;
expect(getClosestTick(ticks, val, previous)).toBe(6);
});
test('lower previous value returns next greater, large step', () => {
const ticks = [2, 4, 60, 80, 10];
const previous = 4;
const val = 5;
expect(getClosestTick(ticks, val, previous)).toBe(60);
});
test('greater previous value returns next lesser', () => {
let ticks = [...new Set([2, 4, 6, 8, 10])],
previous = 4,
val = 3;
const ticks = [2, 4, 6, 8, 10];
const previous = 4;
const val = 3;
const actual = getClosestTick(ticks, val, previous);
expect(actual).toBe(2);
});
test('greater previous value returns next lesser, consecutive', () => {
let ticks = [...new Set([1, 2, 3, 4, 5, 6])],
previous = 4,
val = 3;
const ticks = [1, 2, 3, 4, 5, 6];
const previous = 4;
const val = 3;
const actual = getClosestTick(ticks, val, previous);
expect(actual).toBe(3);
});
test('lower previous value returns next greater, consecutive', () => {
let ticks = [...new Set([1, 2, 3, 4, 5, 6])],
previous = 3,
val = 4;
const ticks = [1, 2, 3, 4, 5, 6];
const previous = 3;
const val = 4;
const actual = getClosestTick(ticks, val, previous);
expect(actual).toBe(4);
});
test('lower previous value returns next greater, erratic', () => {
let ticks = [...new Set([1, 4, 5, 7, 9, 12])],
previous = 9,
val = 10;
const ticks = [1, 4, 5, 7, 9, 12];
const previous = 9;
const val = 10;
const actual = getClosestTick(ticks, val, previous);
expect(actual).toBe(12);
});
test('greater previous value returns next lower, erratic', () => {
let ticks = [...new Set([1, 2, 5, 7, 9, 12])],
previous = 5,
val = 4;
const ticks = [1, 2, 5, 7, 9, 12];
const previous = 5;
const val = 4;
const actual = getClosestTick(ticks, val, previous);
expect(actual).toBe(2);
});

// Modified logic, retaining for expected performance
test('large number of ticks', () => {
let ticks = [...new Set<number>()],
previous = 500000,
val = 500001;

const ticks = [];
for (let i = 0; i < 10000000; i += 2) {
ticks.push(i);
}

const previous = 500000;
const val = 500001;
const start = Date.now();
const actual = getClosestTick(ticks, val, previous);
const end = Date.now();
Expand Down

0 comments on commit 01b7661

Please sign in to comment.