-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDuration.spec.ts
32 lines (27 loc) · 1.06 KB
/
Duration.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/** Typeclass law tests for the `Duration` datatype. */
import {MonoidMax, MonoidMin, MonoidSum} from '@effect/typeclass/data/Duration'
import {Duration as DU, pipe} from 'effect'
import {boundedDuration, duration} from 'effect-ts-laws'
import {testConcreteTypeclassLaws, testMonoids} from 'effect-ts-laws/vitest'
import {Equivalence, Order} from 'effect/Duration'
import fc from 'fast-check'
describe('@effect/typeclass/data/Duration', () => {
const a = duration,
equalsA = (a: DU.Duration, b: DU.Duration) =>
DU.toMillis(a) === DU.toMillis(b)
describe('Equivalence/order', () => {
testConcreteTypeclassLaws({Equivalence, Order}, {a, equalsA})
})
describe('Bounded', () => {
const [sampled] = fc.sample(boundedDuration, {numRuns: 1})
if (sampled === undefined) throw new Error('Cannot sample')
const [arbitrary, F] = sampled
testConcreteTypeclassLaws({Bounded: F}, {a: arbitrary, equalsA})
})
describe('Semigroup/monoid', () => {
pipe(
{Σ: MonoidSum, min: MonoidMin, max: MonoidMax},
testMonoids(a, equalsA),
)
})
})