Build image / build-and-push (push) Successful in 14s
Co-authored-by: Steve Dudenhoeffer <[email protected]>
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { computeDerivedCount, effectiveCount } from './plantings'
|
|
|
|
describe('computeDerivedCount', () => {
|
|
it('mirrors the server formula max(1, round(π·r²/spacing²))', () => {
|
|
expect(computeDerivedCount(10, 10)).toBe(3) // π·100/100 = 3.14 → 3
|
|
expect(computeDerivedCount(50, 10)).toBe(79) // π·2500/100 = 78.5 → 79
|
|
expect(computeDerivedCount(30, 15)).toBe(13) // π·900/225 = 12.57 → 13
|
|
})
|
|
|
|
it('floors at 1 for tiny / non-positive inputs', () => {
|
|
expect(computeDerivedCount(0.1, 10)).toBe(1)
|
|
expect(computeDerivedCount(0, 10)).toBe(1)
|
|
expect(computeDerivedCount(10, 0)).toBe(1)
|
|
})
|
|
|
|
it('caps like the server', () => {
|
|
expect(computeDerivedCount(10_000, 0.1)).toBe(1_000_000)
|
|
})
|
|
})
|
|
|
|
describe('effectiveCount', () => {
|
|
it('prefers the override, else the derived value', () => {
|
|
expect(effectiveCount({ count: 12, derivedCount: 79 })).toBe(12)
|
|
expect(effectiveCount({ count: null, derivedCount: 79 })).toBe(79)
|
|
})
|
|
})
|