Skip to content

Commit

Permalink
added tests for new delta functions
Browse files Browse the repository at this point in the history
  • Loading branch information
imclerran committed Feb 1, 2024
1 parent 6152e35 commit 2ae3b59
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions platform/Utc.roc
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ deltaAsNanos = \@Utc first, @Utc second ->
secondCast = Num.bitwiseXor (Num.toU128 second) (Num.shiftLeftBy 1 127)
Num.absDiff firstCast secondCast

# TESTS
expect deltaAsNanos (fromNanosSinceEpoch 0) (fromNanosSinceEpoch 0) == 0
expect deltaAsNanos (fromNanosSinceEpoch 1) (fromNanosSinceEpoch 2) == 1
expect deltaAsNanos (fromNanosSinceEpoch -1) (fromNanosSinceEpoch 1) == 2
expect deltaAsNanos (fromNanosSinceEpoch Num.minI128) (fromNanosSinceEpoch Num.maxI128) == Num.maxU128

expect deltaAsMillis (fromMillisSinceEpoch 0) (fromMillisSinceEpoch 0) == 0
expect deltaAsMillis (fromNanosSinceEpoch 1) (fromNanosSinceEpoch 2) == 0
expect deltaAsMillis (fromMillisSinceEpoch 1) (fromMillisSinceEpoch 2) == 1
expect deltaAsMillis (fromMillisSinceEpoch -1) (fromMillisSinceEpoch 1) == 2
expect deltaAsMillis (fromNanosSinceEpoch Num.minI128) (fromNanosSinceEpoch Num.maxI128) == Num.maxU128 // nanosPerMilli

0 comments on commit 2ae3b59

Please sign in to comment.