You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte-kit-vice/src/libs/plots/test/ticks.test.ts

38 lines
1.1 KiB

import { describe, expect, it } from 'vitest'
import { nice, tickStep, ticks } from '../ticks'
describe('ticks', () => {
it('produces round multiples across a range', () => {
expect(ticks(0, 100, 5)).toEqual([0, 20, 40, 60, 80, 100])
expect(ticks(0, 10, 10)).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
})
it('handles sub-unit steps without float drift', () => {
expect(ticks(0, 1, 10)).toEqual([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1])
})
it('stays within the exact extent', () => {
const t = ticks(2, 97, 5)
expect(t[0]).toBeGreaterThanOrEqual(2)
expect(t[t.length - 1]).toBeLessThanOrEqual(97)
})
it('mirrors order when the range descends', () => {
expect(ticks(100, 0, 5)).toEqual([100, 80, 60, 40, 20, 0])
})
it('returns a single tick for a zero-width range', () => {
expect(ticks(5, 5, 10)).toEqual([5])
})
it('nice rounds the domain outward', () => {
expect(nice(0.1, 9.9, 10)).toEqual([0, 10])
expect(nice(2, 97, 5)).toEqual([0, 100])
})
it('tickStep returns the nice step', () => {
expect(tickStep(0, 100, 5)).toBe(20)
expect(tickStep(0, 1, 10)).toBeCloseTo(0.1, 10)
})
})

Powered by TurnKey Linux.