summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/stdlib/tmath.nim30
1 files changed, 26 insertions, 4 deletions
diff --git a/tests/stdlib/tmath.nim b/tests/stdlib/tmath.nim
index fbc6b80ad..e5cb58eba 100644
--- a/tests/stdlib/tmath.nim
+++ b/tests/stdlib/tmath.nim
@@ -10,6 +10,10 @@ import std/[math, random, os]
 import std/[unittest]
 import std/[sets, tables]
 
+
+# Function for approximate comparison of floats
+proc `==~`(x, y: float): bool = (abs(x-y) < 1e-9)
+
 block: # random int
   block: # there might be some randomness
     var set = initHashSet[int](128)
@@ -158,10 +162,6 @@ block:
     doAssert(erf(6.0) > erf(5.0))
     doAssert(erfc(6.0) < erfc(5.0))
 
-    proc `==~`(x, y: float): bool = (abs(x-y) < 1e-9)
-      # Function for approximate comparison of floats
-      # xxx use `almostEqual`
-
     block: # prod
       doAssert prod([1, 2, 3, 4]) == 24
       doAssert prod([1.5, 3.4]).almostEqual 5.1
@@ -349,6 +349,28 @@ template main =
     doAssert copySign(-NaN, 0.0).isNaN
     doAssert copySign(-NaN, -0.0).isNaN
 
+    block: # round() tests
+      # Round to 0 decimal places
+      doAssert round(54.652) == 55.0
+      doAssert round(54.352) == 54.0
+      doAssert round(-54.652) == -55.0
+      doAssert round(-54.352) == -54.0
+      doAssert round(0.0) == 0.0
+      doAssert 1 / round(0.0) == Inf
+      doAssert 1 / round(-0.0) == -Inf
+      doAssert round(Inf) == Inf
+      doAssert round(-Inf) == -Inf
+      doAssert round(NaN).isNaN
+      doAssert round(-NaN).isNaN
+      doAssert round(-0.5) == -1.0
+      doAssert round(0.5) == 1.0
+      doAssert round(-1.5) == -2.0
+      doAssert round(1.5) == 2.0
+      doAssert round(-2.5) == -3.0
+      doAssert round(2.5) == 3.0
+      doAssert round(2.5'f32) == 3.0'f32
+      doAssert round(2.5'f64) == 3.0'f64
+
     when nimvm:
       discard
     else: