2023-02-12 10:56:45 +11:00
|
|
|
import { isOverlap, roundOff } from './utils'
|
2022-11-26 08:34:23 +11:00
|
|
|
import { Range } from '../useStore'
|
2022-11-26 05:13:07 +11:00
|
|
|
|
2022-11-26 08:34:23 +11:00
|
|
|
describe('testing isOverlapping', () => {
|
2023-02-12 10:56:45 +11:00
|
|
|
testBothOrders([0, 3], [3, 10])
|
2022-11-26 08:34:23 +11:00
|
|
|
testBothOrders([0, 5], [3, 4])
|
|
|
|
testBothOrders([0, 5], [5, 10])
|
|
|
|
testBothOrders([0, 5], [6, 10], false)
|
|
|
|
testBothOrders([0, 5], [-1, 1])
|
|
|
|
testBothOrders([0, 5], [-1, 0])
|
|
|
|
testBothOrders([0, 5], [-2, -1], false)
|
|
|
|
})
|
2022-11-26 05:13:07 +11:00
|
|
|
|
|
|
|
function testBothOrders(a: Range, b: Range, result = true) {
|
|
|
|
it(`test is overlapping ${a} ${b}`, () => {
|
2023-02-12 10:56:45 +11:00
|
|
|
expect(isOverlap(a, b)).toBe(result)
|
|
|
|
expect(isOverlap(b, a)).toBe(result)
|
2022-11-26 08:34:23 +11:00
|
|
|
})
|
2022-11-26 05:13:07 +11:00
|
|
|
}
|
2023-02-12 10:56:45 +11:00
|
|
|
|
|
|
|
describe('testing roundOff', () => {
|
|
|
|
it('defaults to 2 decimal places', () => {
|
|
|
|
expect(roundOff(1.23456789)).toBe(1.23)
|
|
|
|
})
|
|
|
|
it('rounds off to 3 decimal places', () => {
|
|
|
|
expect(roundOff(1.23456789, 3)).toBe(1.235)
|
|
|
|
})
|
|
|
|
it('works with whole numbers', () => {
|
|
|
|
expect(roundOff(1.23456789, 0)).toBe(1)
|
|
|
|
})
|
|
|
|
it('rounds up ok', () => {
|
|
|
|
expect(roundOff(1.273456789, 1)).toBe(1.3)
|
|
|
|
})
|
|
|
|
})
|