Files
modeling-app/src/lib/utils.test.ts
Jess Frazelle 61943055e5 refactor a bit before more rust port (#739)
* partially there

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* cleanup

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixups

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-09-29 11:11:01 -07:00

35 lines
1002 B
TypeScript

import { isOverlap, roundOff } from './utils'
import { SourceRange } from '../lang/wasm'
describe('testing isOverlapping', () => {
testBothOrders([0, 3], [3, 10])
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)
})
function testBothOrders(a: SourceRange, b: SourceRange, result = true) {
it(`test is overlapping ${a} ${b}`, () => {
expect(isOverlap(a, b)).toBe(result)
expect(isOverlap(b, a)).toBe(result)
})
}
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)
})
})