| 1 | import { describe, it, expect } from 'vitest'
|
| 2 | import { avg, formatHours, formatDiff } from '@app/utils/calc'
|
| 3 |
|
| 4 | describe('avg', () => {
|
| 5 | it('averages a list of numbers', () => {
|
| 6 | expect(avg([2, 4, 6])).toBe(4)
|
| 7 | })
|
| 8 |
|
| 9 | it('yields NaN for an empty list', () => {
|
| 10 | expect(avg([])).toBeNaN()
|
| 11 | })
|
| 12 | })
|
| 13 |
|
| 14 | describe('formatHours', () => {
|
| 15 | it('drops the minutes for a whole hour', () => {
|
| 16 | expect(formatHours(7)).toBe('7h')
|
| 17 | })
|
| 18 |
|
| 19 | it('renders the remaining minutes', () => {
|
| 20 | expect(formatHours(7.5)).toBe('7h 30min')
|
| 21 | })
|
| 22 | })
|
| 23 |
|
| 24 | describe('formatDiff', () => {
|
| 25 | it('signs a positive whole-hour difference', () => {
|
| 26 | expect(formatDiff(120)).toBe('+2h')
|
| 27 | })
|
| 28 |
|
| 29 | it('signs a negative whole-hour difference', () => {
|
| 30 | expect(formatDiff(-120)).toBe('-2h')
|
| 31 | })
|
| 32 |
|
| 33 | it('signs a positive difference with hours and minutes', () => {
|
| 34 | expect(formatDiff(90)).toBe('+1h 30min')
|
| 35 | })
|
| 36 |
|
| 37 | it('signs a negative difference with hours and minutes', () => {
|
| 38 | expect(formatDiff(-90)).toBe('-1h 30min')
|
| 39 | })
|
| 40 |
|
| 41 | it('renders a positive sub-hour difference in minutes only', () => {
|
| 42 | expect(formatDiff(30)).toBe('+30min')
|
| 43 | })
|
| 44 |
|
| 45 | it('renders a negative sub-hour difference in minutes only', () => {
|
| 46 | expect(formatDiff(-30)).toBe('-30min')
|
| 47 | })
|
| 48 | })
|