diff options
author | n5m <72841454+n5m@users.noreply.github.com> | 2022-09-26 19:42:26 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-26 15:42:26 -0400 |
commit | 6b4ea88734bf8dfaef96a29d5c09aa309b3db093 (patch) | |
tree | 2b0a40b36807c5d78d18fc6b8fd22718bf9e4cd8 /tests | |
parent | cb24eea86b730a99311086f028d378ab53fd20e2 (diff) | |
download | Nim-6b4ea88734bf8dfaef96a29d5c09aa309b3db093.tar.gz |
use almostEqual in tstats.nim (#20431)
prefer math.almostEqual
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stdlib/tstats.nim | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/tests/stdlib/tstats.nim b/tests/stdlib/tstats.nim index 92a2ed8b8..a2dee7ecd 100644 --- a/tests/stdlib/tstats.nim +++ b/tests/stdlib/tstats.nim @@ -1,7 +1,8 @@ +import std/math import std/stats -proc `~=`(x, y: float): bool = - abs(x - y) < 10e-8 +func `~=`(x, y: float32): bool = + math.almostEqual(x, y) template main() = var rs: RunningStat @@ -28,21 +29,21 @@ template main() = doAssert rs1.kurtosis ~= rs.kurtosis rs1.clear() rs1.push(@[1.0, 2.2, 1.4, 4.9]) - doAssert(rs1.sum == 9.5) - doAssert(rs1.mean() == 2.375) + doAssert rs1.sum ~= 9.5 + doAssert rs1.mean() ~= 2.375 when not defined(cpu32): # XXX For some reason on 32bit CPUs these results differ var rr: RunningRegress rr.push(@[0.0, 1.0, 2.8, 3.0, 4.0], @[0.0, 1.0, 2.3, 3.0, 4.0]) - doAssert(rr.slope() == 0.9695585996955861) - doAssert(rr.intercept() == -0.03424657534246611) - doAssert(rr.correlation() == 0.9905100362239381) + doAssert rr.slope() ~= 0.9695585996955861 + doAssert rr.intercept() ~= -0.03424657534246611 + doAssert rr.correlation() ~= 0.9905100362239381 var rr1, rr2: RunningRegress rr1.push(@[0.0, 1.0], @[0.0, 1.0]) rr2.push(@[2.8, 3.0, 4.0], @[2.3, 3.0, 4.0]) let rr3 = rr1 + rr2 - doAssert(rr3.correlation() == rr.correlation()) + doAssert rr3.correlation() ~= rr.correlation() doAssert rr3.slope() ~= rr.slope() doAssert rr3.intercept() ~= rr.intercept() |