change debug.assert to testing.expect in tests

This commit is contained in:
xackus 2020-11-06 22:36:18 +01:00
parent 030f00391a
commit 5c8f7f81cd
7 changed files with 25 additions and 30 deletions

View File

@ -736,7 +736,7 @@ test "WasmPageAllocator internals" {
if (comptime std.Target.current.isWasm()) {
const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;
const initial = try page_allocator.alloc(u8, mem.page_size);
std.debug.assert(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
var inplace = try page_allocator.realloc(initial, 1);
testing.expectEqual(initial.ptr, inplace.ptr);

View File

@ -93,7 +93,7 @@ test "LoggingAllocator" {
var a = try allocator.alloc(u8, 10);
a = allocator.shrink(a, 5);
std.debug.assert(a.len == 5);
std.testing.expect(a.len == 5);
std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
allocator.free(a);

View File

@ -40,11 +40,7 @@ test "write a file, read it, then delete it" {
{
// Make sure the exclusive flag is honored.
if (tmp.dir.createFile(tmp_file_name, .{ .exclusive = true })) |file| {
unreachable;
} else |err| {
std.debug.assert(err == File.OpenError.PathAlreadyExists);
}
expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));
}
{

View File

@ -11,8 +11,7 @@
const std = @import("../std.zig");
const math = std.math;
const assert = std.debug.assert;
const builtin = @import("builtin");
const expect = std.testing.expect;
/// Returns e raised to the power of x (e^x).
///
@ -188,36 +187,36 @@ fn exp64(x_: f64) f64 {
}
test "math.exp" {
assert(exp(@as(f32, 0.0)) == exp32(0.0));
assert(exp(@as(f64, 0.0)) == exp64(0.0));
expect(exp(@as(f32, 0.0)) == exp32(0.0));
expect(exp(@as(f64, 0.0)) == exp64(0.0));
}
test "math.exp32" {
const epsilon = 0.000001;
assert(exp32(0.0) == 1.0);
assert(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
assert(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
assert(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
assert(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
expect(exp32(0.0) == 1.0);
expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
}
test "math.exp64" {
const epsilon = 0.000001;
assert(exp64(0.0) == 1.0);
assert(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
assert(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
assert(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
assert(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
expect(exp64(0.0) == 1.0);
expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
}
test "math.exp32.special" {
assert(math.isPositiveInf(exp32(math.inf(f32))));
assert(math.isNan(exp32(math.nan(f32))));
expect(math.isPositiveInf(exp32(math.inf(f32))));
expect(math.isNan(exp32(math.nan(f32))));
}
test "math.exp64.special" {
assert(math.isPositiveInf(exp64(math.inf(f64))));
assert(math.isNan(exp64(math.nan(f64))));
expect(math.isPositiveInf(exp64(math.inf(f64))));
expect(math.isNan(exp64(math.nan(f64))));
}

View File

@ -1152,7 +1152,7 @@ test "CSPRNG" {
const a = csprng.random.int(u64);
const b = csprng.random.int(u64);
const c = csprng.random.int(u64);
assert(a ^ b ^ c != 0);
expect(a ^ b ^ c != 0);
}
test "" {

View File

@ -1,4 +1,4 @@
const assert = @import("std").debug.assert;
const expect = @import("std").testing.expect;
test "bitCast to array" {
comptime testBitCastArray();
@ -6,7 +6,7 @@ test "bitCast to array" {
}
fn testBitCastArray() void {
assert(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);
expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);
}
fn extractOne64(a: u128) u64 {

View File

@ -1,10 +1,10 @@
const c = @import("c.zig");
const assert = @import("std").debug.assert;
const expect = @import("std").testing.expect;
test "symbol exists" {
var foo = c.Foo{
.a = 1,
.b = 1,
};
assert(foo.a + foo.b == 2);
expect(foo.a + foo.b == 2);
}