48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { describe, it } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import {
|
|
calcTripLegDays,
|
|
sumTripLegDays,
|
|
isHalfDayMultiple
|
|
} from './oa-trip-days'
|
|
|
|
describe('calcTripLegDays', () => {
|
|
it('same day morning->morning => 0.5', () => {
|
|
assert.equal(calcTripLegDays('2026-08-01', '上午', '2026-08-01', '上午'), 0.5)
|
|
})
|
|
it('same day morning->afternoon => 1', () => {
|
|
assert.equal(calcTripLegDays('2026-08-01', '上午', '2026-08-01', '下午'), 1)
|
|
})
|
|
it('same day afternoon->afternoon => 0.5', () => {
|
|
assert.equal(calcTripLegDays('2026-08-01', '下午', '2026-08-01', '下午'), 0.5)
|
|
})
|
|
it('same day afternoon->morning => null', () => {
|
|
assert.equal(calcTripLegDays('2026-08-01', '下午', '2026-08-01', '上午'), null)
|
|
})
|
|
it('D1 morning -> D2 afternoon => 2', () => {
|
|
assert.equal(calcTripLegDays('2026-08-01', '上午', '2026-08-02', '下午'), 2)
|
|
})
|
|
it('D1 afternoon -> D2 morning => 1', () => {
|
|
assert.equal(calcTripLegDays('2026-08-01', '下午', '2026-08-02', '上午'), 1)
|
|
})
|
|
it('invalid date => null', () => {
|
|
assert.equal(calcTripLegDays('', '上午', '2026-08-01', '下午'), null)
|
|
})
|
|
})
|
|
|
|
describe('sumTripLegDays', () => {
|
|
it('sums durations', () => {
|
|
assert.equal(sumTripLegDays([{ duration: 0.5 }, { duration: 1 }, { duration: 2 }]), 3.5)
|
|
})
|
|
it('ignores non-number', () => {
|
|
assert.equal(sumTripLegDays([{ duration: 1 }, { duration: null }]), 1)
|
|
})
|
|
})
|
|
|
|
describe('isHalfDayMultiple', () => {
|
|
it('accepts 0.5 steps', () => {
|
|
assert.equal(isHalfDayMultiple(1.5), true)
|
|
assert.equal(isHalfDayMultiple(1.25), false)
|
|
})
|
|
})
|