diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-08 18:18:47 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-02-08 18:23:38 -0500 |
| commit | c2db077574be841da586fa62d67619c901dd535d (patch) | |
| tree | c8eb64846fa7ffb9027fa1ca035dd8ca5712b9d4 /std/math/log10.zig | |
| parent | be6d022257d8d7e99bd080823d4d8f0175f320c5 (diff) | |
| download | zig-c2db077574be841da586fa62d67619c901dd535d.tar.gz zig-c2db077574be841da586fa62d67619c901dd535d.zip | |
std.debug.assert: remove special case for test builds
Previously, std.debug.assert would `@panic` in test builds,
if the assertion failed. Now, it's always `unreachable`.
This makes release mode test builds more accurately test
the actual code that will be run.
However this requires tests to call `std.testing.expect`
rather than `std.debug.assert` to make sure output is correct.
Here is the explanation of when to use either one, copied from
the assert doc comments:
Inside a test block, it is best to use the `std.testing` module
rather than assert, because assert may not detect a test failure
in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert
is the correct function to use.
closes #1304
Diffstat (limited to 'std/math/log10.zig')
| -rw-r--r-- | std/math/log10.zig | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/std/math/log10.zig b/std/math/log10.zig index 2b53d8a6ae..8055f71280 100644 --- a/std/math/log10.zig +++ b/std/math/log10.zig @@ -7,7 +7,7 @@ const std = @import("../index.zig"); const math = std.math; -const assert = std.debug.assert; +const testing = std.testing; const builtin = @import("builtin"); const TypeId = builtin.TypeId; const maxInt = std.math.maxInt; @@ -171,42 +171,42 @@ pub fn log10_64(x_: f64) f64 { } test "math.log10" { - assert(log10(f32(0.2)) == log10_32(0.2)); - assert(log10(f64(0.2)) == log10_64(0.2)); + testing.expect(log10(f32(0.2)) == log10_32(0.2)); + testing.expect(log10(f64(0.2)) == log10_64(0.2)); } test "math.log10_32" { const epsilon = 0.000001; - assert(math.approxEq(f32, log10_32(0.2), -0.698970, epsilon)); - assert(math.approxEq(f32, log10_32(0.8923), -0.049489, epsilon)); - assert(math.approxEq(f32, log10_32(1.5), 0.176091, epsilon)); - assert(math.approxEq(f32, log10_32(37.45), 1.573452, epsilon)); - assert(math.approxEq(f32, log10_32(89.123), 1.94999, epsilon)); - assert(math.approxEq(f32, log10_32(123123.234375), 5.09034, epsilon)); + testing.expect(math.approxEq(f32, log10_32(0.2), -0.698970, epsilon)); + testing.expect(math.approxEq(f32, log10_32(0.8923), -0.049489, epsilon)); + testing.expect(math.approxEq(f32, log10_32(1.5), 0.176091, epsilon)); + testing.expect(math.approxEq(f32, log10_32(37.45), 1.573452, epsilon)); + testing.expect(math.approxEq(f32, log10_32(89.123), 1.94999, epsilon)); + testing.expect(math.approxEq(f32, log10_32(123123.234375), 5.09034, epsilon)); } test "math.log10_64" { const epsilon = 0.000001; - assert(math.approxEq(f64, log10_64(0.2), -0.698970, epsilon)); - assert(math.approxEq(f64, log10_64(0.8923), -0.049489, epsilon)); - assert(math.approxEq(f64, log10_64(1.5), 0.176091, epsilon)); - assert(math.approxEq(f64, log10_64(37.45), 1.573452, epsilon)); - assert(math.approxEq(f64, log10_64(89.123), 1.94999, epsilon)); - assert(math.approxEq(f64, log10_64(123123.234375), 5.09034, epsilon)); + testing.expect(math.approxEq(f64, log10_64(0.2), -0.698970, epsilon)); + testing.expect(math.approxEq(f64, log10_64(0.8923), -0.049489, epsilon)); + testing.expect(math.approxEq(f64, log10_64(1.5), 0.176091, epsilon)); + testing.expect(math.approxEq(f64, log10_64(37.45), 1.573452, epsilon)); + testing.expect(math.approxEq(f64, log10_64(89.123), 1.94999, epsilon)); + testing.expect(math.approxEq(f64, log10_64(123123.234375), 5.09034, epsilon)); } test "math.log10_32.special" { - assert(math.isPositiveInf(log10_32(math.inf(f32)))); - assert(math.isNegativeInf(log10_32(0.0))); - assert(math.isNan(log10_32(-1.0))); - assert(math.isNan(log10_32(math.nan(f32)))); + testing.expect(math.isPositiveInf(log10_32(math.inf(f32)))); + testing.expect(math.isNegativeInf(log10_32(0.0))); + testing.expect(math.isNan(log10_32(-1.0))); + testing.expect(math.isNan(log10_32(math.nan(f32)))); } test "math.log10_64.special" { - assert(math.isPositiveInf(log10_64(math.inf(f64)))); - assert(math.isNegativeInf(log10_64(0.0))); - assert(math.isNan(log10_64(-1.0))); - assert(math.isNan(log10_64(math.nan(f64)))); + testing.expect(math.isPositiveInf(log10_64(math.inf(f64)))); + testing.expect(math.isNegativeInf(log10_64(0.0))); + testing.expect(math.isNan(log10_64(-1.0))); + testing.expect(math.isNan(log10_64(math.nan(f64)))); } |
