Change many test blocks to doctests/decltests

This commit is contained in:
Ryan Liptak 2024-02-26 15:14:43 -08:00
parent 16b3d1004e
commit 726a1149e0
51 changed files with 143 additions and 145 deletions

View File

@ -201,7 +201,7 @@ test "sequence" {
} }
} }
test "fill" { test fill {
var r = Isaac64.init(0); var r = Isaac64.init(0);
// from reference implementation // from reference implementation

View File

@ -92,7 +92,7 @@ test "sequence" {
} }
} }
test "fill" { test fill {
var r = Pcg.init(0); var r = Pcg.init(0);
const s0: u64 = 0x9394bf54ce5d79de; const s0: u64 = 0x9394bf54ce5d79de;
const s1: u64 = 0x84e9c579ef59bbf7; const s1: u64 = 0x84e9c579ef59bbf7;

View File

@ -94,7 +94,7 @@ test "sequence" {
} }
} }
test "fill" { test fill {
// Unfortunately there does not seem to be an official test sequence. // Unfortunately there does not seem to be an official test sequence.
var r = RomuTrio.init(0); var r = RomuTrio.init(0);

View File

@ -98,7 +98,7 @@ test "sequence" {
} }
} }
test "fill" { test fill {
// Unfortunately there does not seem to be an official test sequence. // Unfortunately there does not seem to be an official test sequence.
var r = Sfc64.init(0); var r = Sfc64.init(0);

View File

@ -122,7 +122,7 @@ test "sequence" {
} }
} }
test "fill" { test fill {
var r = Xoroshiro128.init(0); var r = Xoroshiro128.init(0);
r.s[0] = 0xaeecf86f7878dd75; r.s[0] = 0xaeecf86f7878dd75;
r.s[1] = 0x01cd153642e72622; r.s[1] = 0x01cd153642e72622;

View File

@ -122,7 +122,7 @@ test "sequence" {
} }
} }
test "fill" { test fill {
var r = Xoshiro256.init(0); var r = Xoshiro256.init(0);
const seq = [_]u64{ const seq = [_]u64{

View File

@ -166,7 +166,7 @@ pub fn format(
const expect = std.testing.expect; const expect = std.testing.expect;
const expectError = std.testing.expectError; const expectError = std.testing.expectError;
test "format" { test format {
// Many of these test strings are from https://github.com/semver/semver.org/issues/59#issuecomment-390854010. // Many of these test strings are from https://github.com/semver/semver.org/issues/59#issuecomment-390854010.
// Valid version strings should be accepted. // Valid version strings should be accepted.

View File

@ -1437,7 +1437,7 @@ fn testIncrementNotify(value: *usize, event: *ResetEvent) void {
event.set(); event.set();
} }
test "join" { test join {
if (builtin.single_threaded) return error.SkipZigTest; if (builtin.single_threaded) return error.SkipZigTest;
var value: usize = 0; var value: usize = 0;
@ -1449,7 +1449,7 @@ test "join" {
try std.testing.expectEqual(value, 1); try std.testing.expectEqual(value, 1);
} }
test "detach" { test detach {
if (builtin.single_threaded) return error.SkipZigTest; if (builtin.single_threaded) return error.SkipZigTest;
var value: usize = 0; var value: usize = 0;

View File

@ -362,7 +362,7 @@ test "wait and signal" {
} }
} }
test "signal" { test signal {
// This test requires spawning threads // This test requires spawning threads
if (builtin.single_threaded) { if (builtin.single_threaded) {
return error.SkipZigTest; return error.SkipZigTest;
@ -491,7 +491,7 @@ test "multi signal" {
} }
} }
test "broadcasting" { test broadcast {
// This test requires spawning threads // This test requires spawning threads
if (builtin.single_threaded) { if (builtin.single_threaded) {
return error.SkipZigTest; return error.SkipZigTest;

View File

@ -71,7 +71,7 @@ pub fn post(sem: *Semaphore) void {
sem.cond.signal(); sem.cond.signal();
} }
test "Semaphore" { test Semaphore {
if (builtin.single_threaded) { if (builtin.single_threaded) {
return error.SkipZigTest; return error.SkipZigTest;
} }
@ -97,7 +97,7 @@ test "Semaphore" {
try testing.expect(n == num_threads); try testing.expect(n == num_threads);
} }
test "timedWait" { test timedWait {
var sem = Semaphore{}; var sem = Semaphore{};
try testing.expectEqual(0, sem.permits); try testing.expectEqual(0, sem.permits);

View File

@ -90,6 +90,23 @@ pub const BufSet = struct {
return self.cloneWithAllocator(self.allocator()); return self.cloneWithAllocator(self.allocator());
} }
test clone {
var original = BufSet.init(testing.allocator);
defer original.deinit();
try original.insert("x");
var cloned = try original.clone();
defer cloned.deinit();
cloned.remove("x");
try testing.expect(original.count() == 1);
try testing.expect(cloned.count() == 0);
try testing.expectError(
error.OutOfMemory,
original.cloneWithAllocator(testing.failing_allocator),
);
}
fn free(self: *const BufSet, value: []const u8) void { fn free(self: *const BufSet, value: []const u8) void {
self.hash_map.allocator.free(value); self.hash_map.allocator.free(value);
} }
@ -115,23 +132,6 @@ test BufSet {
try bufset.insert("z"); try bufset.insert("z");
} }
test "clone" {
var original = BufSet.init(testing.allocator);
defer original.deinit();
try original.insert("x");
var cloned = try original.clone();
defer cloned.deinit();
cloned.remove("x");
try testing.expect(original.count() == 1);
try testing.expect(cloned.count() == 0);
try testing.expectError(
error.OutOfMemory,
original.cloneWithAllocator(testing.failing_allocator),
);
}
test "clone with arena" { test "clone with arena" {
const allocator = std.testing.allocator; const allocator = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(allocator); var arena = std.heap.ArenaAllocator.init(allocator);

View File

@ -130,7 +130,7 @@ pub fn full(self: *Self) bool {
} }
// example from: https://youtu.be/SJPvNi4HrWQ?t=3558 // example from: https://youtu.be/SJPvNi4HrWQ?t=3558
test "writeMatch" { test writeMatch {
var cb: Self = .{}; var cb: Self = .{};
cb.writeAll("a salad; "); cb.writeAll("a salad; ");
@ -150,7 +150,7 @@ test "writeMatch overlap" {
try testing.expectEqualStrings("a b c b c b c d", cb.read()); try testing.expectEqualStrings("a b c b c b c d", cb.read());
} }
test "readAtMost" { test readAtMost {
var cb: Self = .{}; var cb: Self = .{};
cb.writeAll("0123456789"); cb.writeAll("0123456789");
@ -165,7 +165,7 @@ test "readAtMost" {
try testing.expectEqualStrings("", cb.read()); try testing.expectEqualStrings("", cb.read());
} }
test "CircularBuffer" { test Self {
var cb: Self = .{}; var cb: Self = .{};
const data = "0123456789abcdef" ** (1024 / 16); const data = "0123456789abcdef" ** (1024 / 16);

View File

@ -83,7 +83,7 @@ fn hashu(v: u32) u32 {
return @intCast((v *% prime4) >> consts.lookup.shift); return @intCast((v *% prime4) >> consts.lookup.shift);
} }
test "add/prev" { test add {
const data = [_]u8{ const data = [_]u8{
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
@ -107,7 +107,7 @@ test "add/prev" {
try expect(h.chain[2 + 8] == 2); try expect(h.chain[2 + 8] == 2);
} }
test "bulkAdd" { test bulkAdd {
const data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; const data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
// one by one // one by one

View File

@ -122,7 +122,7 @@ pub fn tokensBuffer(self: *Self) ?[]const u8 {
return self.buffer[@intCast(self.fp)..self.rp]; return self.buffer[@intCast(self.fp)..self.rp];
} }
test "match" { test match {
const data = "Blah blah blah blah blah!"; const data = "Blah blah blah blah blah!";
var win: Self = .{}; var win: Self = .{};
try expect(win.write(data) == data.len); try expect(win.write(data) == data.len);
@ -142,7 +142,7 @@ test "match" {
try expect(win.match(15, 20, 4) == 0); try expect(win.match(15, 20, 4) == 0);
} }
test "slide" { test slide {
var win: Self = .{}; var win: Self = .{};
win.wp = Self.buffer_len - 11; win.wp = Self.buffer_len - 11;
win.rp = Self.buffer_len - 111; win.rp = Self.buffer_len - 111;

View File

@ -458,7 +458,7 @@ fn bitReverse(comptime T: type, value: T, n: usize) T {
return r >> @as(math.Log2Int(T), @intCast(@typeInfo(T).Int.bits - n)); return r >> @as(math.Log2Int(T), @intCast(@typeInfo(T).Int.bits - n));
} }
test "bitReverse" { test bitReverse {
const ReverseBitsTest = struct { const ReverseBitsTest = struct {
in: u16, in: u16,
bit_count: u5, bit_count: u5,

View File

@ -120,7 +120,7 @@ pub fn directEnumArray(
return directEnumArrayDefault(E, Data, null, max_unused_slots, init_values); return directEnumArrayDefault(E, Data, null, max_unused_slots, init_values);
} }
test "directEnumArray" { test directEnumArray {
const E = enum(i4) { a = 4, b = 6, c = 2 }; const E = enum(i4) { a = 4, b = 6, c = 2 };
var runtime_false: bool = false; var runtime_false: bool = false;
_ = &runtime_false; _ = &runtime_false;
@ -163,7 +163,7 @@ pub fn directEnumArrayDefault(
return result; return result;
} }
test "directEnumArrayDefault" { test directEnumArrayDefault {
const E = enum(i4) { a = 4, b = 6, c = 2 }; const E = enum(i4) { a = 4, b = 6, c = 2 };
var runtime_false: bool = false; var runtime_false: bool = false;
_ = &runtime_false; _ = &runtime_false;
@ -214,7 +214,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
}; };
} }
test "nameCast" { test nameCast {
const A = enum(u1) { a = 0, b = 1 }; const A = enum(u1) { a = 0, b = 1 };
const B = enum(u1) { a = 1, b = 0 }; const B = enum(u1) { a = 1, b = 0 };
try testing.expectEqual(A.a, nameCast(A, .a)); try testing.expectEqual(A.a, nameCast(A, .a));
@ -515,7 +515,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
}; };
} }
test "EnumMultiset" { test EnumMultiset {
const Ball = enum { red, green, blue }; const Ball = enum { red, green, blue };
const empty = EnumMultiset(Ball).initEmpty(); const empty = EnumMultiset(Ball).initEmpty();
@ -1298,7 +1298,7 @@ pub fn ensureIndexer(comptime T: type) void {
} }
} }
test "ensureIndexer" { test ensureIndexer {
ensureIndexer(struct { ensureIndexer(struct {
pub const Key = u32; pub const Key = u32;
pub const count: comptime_int = 8; pub const count: comptime_int = 8;
@ -1535,7 +1535,7 @@ test "EnumIndexer empty" {
try testing.expectEqual(0, Indexer.count); try testing.expectEqual(0, Indexer.count);
} }
test "enumValues" { test values {
const E = enum { const E = enum {
X, X,
Y, Y,

View File

@ -148,12 +148,12 @@ fn acos64(x: f64) f64 {
return 2 * (df + w); return 2 * (df + w);
} }
test "acos" { test acos {
try expect(acos(@as(f32, 0.0)) == acos32(0.0)); try expect(acos(@as(f32, 0.0)) == acos32(0.0));
try expect(acos(@as(f64, 0.0)) == acos64(0.0)); try expect(acos(@as(f64, 0.0)) == acos64(0.0));
} }
test "acos32" { test acos32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon)); try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
@ -164,7 +164,7 @@ test "acos32" {
try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon)); try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
} }
test "acos64" { test acos64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon)); try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));

View File

@ -59,12 +59,12 @@ fn acosh64(x: f64) f64 {
} }
} }
test "acosh" { test acosh {
try expect(acosh(@as(f32, 1.5)) == acosh32(1.5)); try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
try expect(acosh(@as(f64, 1.5)) == acosh64(1.5)); try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
} }
test "acosh32" { test acosh32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon)); try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
@ -73,7 +73,7 @@ test "acosh32" {
try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon)); try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
} }
test "acosh64" { test acosh64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon)); try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));

View File

@ -141,12 +141,12 @@ fn asin64(x: f64) f64 {
} }
} }
test "asin" { test asin {
try expect(asin(@as(f32, 0.0)) == asin32(0.0)); try expect(asin(@as(f32, 0.0)) == asin32(0.0));
try expect(asin(@as(f64, 0.0)) == asin64(0.0)); try expect(asin(@as(f64, 0.0)) == asin64(0.0));
} }
test "asin32" { test asin32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
@ -157,7 +157,7 @@ test "asin32" {
try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon)); try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
} }
test "asin64" { test asin64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));

View File

@ -80,12 +80,12 @@ fn asinh64(x: f64) f64 {
return if (s != 0) -rx else rx; return if (s != 0) -rx else rx;
} }
test "asinh" { test asinh {
try expect(asinh(@as(f32, 0.0)) == asinh32(0.0)); try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
try expect(asinh(@as(f64, 0.0)) == asinh64(0.0)); try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
} }
test "asinh32" { test asinh32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
@ -98,7 +98,7 @@ test "asinh32" {
try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon)); try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
} }
test "asinh64" { test asinh64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));

View File

@ -212,12 +212,12 @@ fn atan64(x_: f64) f64 {
} }
} }
test "atan" { test atan {
try expect(@as(u32, @bitCast(atan(@as(f32, 0.2)))) == @as(u32, @bitCast(atan32(0.2)))); try expect(@as(u32, @bitCast(atan(@as(f32, 0.2)))) == @as(u32, @bitCast(atan32(0.2))));
try expect(atan(@as(f64, 0.2)) == atan64(0.2)); try expect(atan(@as(f64, 0.2)) == atan64(0.2));
} }
test "atan32" { test atan32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon)); try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
@ -227,7 +227,7 @@ test "atan32" {
try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon)); try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
} }
test "atan64" { test atan64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon)); try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));

View File

@ -214,7 +214,7 @@ fn atan2_64(y: f64, x: f64) f64 {
} }
} }
test "atan2" { test atan2 {
const y32: f32 = 0.2; const y32: f32 = 0.2;
const x32: f32 = 0.21; const x32: f32 = 0.21;
const y64: f64 = 0.2; const y64: f64 = 0.2;
@ -223,7 +223,7 @@ test "atan2" {
try expect(atan2(y64, x64) == atan2_64(0.2, 0.21)); try expect(atan2(y64, x64) == atan2_64(0.2, 0.21));
} }
test "atan2_32" { test atan2_32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
@ -235,7 +235,7 @@ test "atan2_32" {
try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon)); try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
} }
test "atan2_64" { test atan2_64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));

View File

@ -84,12 +84,12 @@ fn atanh_64(x: f64) f64 {
return if (s != 0) -y else y; return if (s != 0) -y else y;
} }
test "atanh" { test atanh {
try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0)); try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0)); try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
} }
test "atanh_32" { test atanh_32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
@ -97,7 +97,7 @@ test "atanh_32" {
try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon)); try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
} }
test "atanh_64" { test atanh_64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));

View File

@ -493,7 +493,7 @@ fn extractLowBits(a: Int, comptime T: type) T {
} }
} }
test "extractLowBits" { test extractLowBits {
var a = try Int.initSet(testing.allocator, 0x11112222333344441234567887654321); var a = try Int.initSet(testing.allocator, 0x11112222333344441234567887654321);
defer a.deinit(); defer a.deinit();

View File

@ -119,12 +119,12 @@ fn cbrt64(x: f64) f64 {
return t + t * q; return t + t * q;
} }
test "cbrt" { test cbrt {
try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0)); try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0)); try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
} }
test "cbrt32" { test cbrt32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.isPositiveZero(cbrt32(0.0))); try expect(math.isPositiveZero(cbrt32(0.0)));
@ -135,7 +135,7 @@ test "cbrt32" {
try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon)); try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
} }
test "cbrt64" { test cbrt64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.isPositiveZero(cbrt64(0.0))); try expect(math.isPositiveZero(cbrt64(0.0)));

View File

@ -120,7 +120,7 @@ fn atan64(z: Complex(f64)) Complex(f64) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "atan32" { test atan32 {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = atan(a); const c = atan(a);
@ -128,7 +128,7 @@ test "atan32" {
try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon)); try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
} }
test "atan64" { test atan64 {
const a = Complex(f64).init(5, 3); const a = Complex(f64).init(5, 3);
const c = atan(a); const c = atan(a);

View File

@ -14,7 +14,7 @@ pub fn atanh(z: anytype) Complex(@TypeOf(z.re, z.im)) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "atanh" { test atanh {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = atanh(a); const c = atanh(a);

View File

@ -10,7 +10,7 @@ pub fn conj(z: anytype) Complex(@TypeOf(z.re, z.im)) {
return Complex(T).init(z.re, -z.im); return Complex(T).init(z.re, -z.im);
} }
test "onj" { test conj {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = a.conjugate(); const c = a.conjugate();

View File

@ -13,7 +13,7 @@ pub fn cos(z: anytype) Complex(@TypeOf(z.re, z.im)) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "cos" { test cos {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = cos(a); const c = cos(a);

View File

@ -155,7 +155,7 @@ fn cosh64(z: Complex(f64)) Complex(f64) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "cosh32" { test cosh32 {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = cosh(a); const c = cosh(a);
@ -163,7 +163,7 @@ test "cosh32" {
try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon)); try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
} }
test "cosh64" { test cosh64 {
const a = Complex(f64).init(5, 3); const a = Complex(f64).init(5, 3);
const c = cosh(a); const c = cosh(a);

View File

@ -119,7 +119,7 @@ fn exp64(z: Complex(f64)) Complex(f64) {
} }
} }
test "exp32" { test exp32 {
const tolerance_f32 = @sqrt(math.floatEps(f32)); const tolerance_f32 = @sqrt(math.floatEps(f32));
{ {
@ -139,7 +139,7 @@ test "exp32" {
} }
} }
test "exp64" { test exp64 {
const tolerance_f64 = @sqrt(math.floatEps(f64)); const tolerance_f64 = @sqrt(math.floatEps(f64));
{ {

View File

@ -15,7 +15,7 @@ pub fn log(z: anytype) Complex(@TypeOf(z.re, z.im)) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "log" { test log {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = log(a); const c = log(a);

View File

@ -11,7 +11,7 @@ pub fn pow(z: anytype, s: anytype) Complex(@TypeOf(z.re, z.im, s.re, s.im)) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "pow" { test pow {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const b = Complex(f32).init(2.3, -1.3); const b = Complex(f32).init(2.3, -1.3);
const c = pow(a, b); const c = pow(a, b);

View File

@ -15,9 +15,7 @@ pub fn proj(z: anytype) Complex(@TypeOf(z.re, z.im)) {
return Complex(T).init(z.re, z.im); return Complex(T).init(z.re, z.im);
} }
const epsilon = 0.0001; test proj {
test "proj" {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = proj(a); const c = proj(a);

View File

@ -14,7 +14,7 @@ pub fn sin(z: anytype) Complex(@TypeOf(z.re, z.im)) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "sin" { test sin {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = sin(a); const c = sin(a);

View File

@ -154,7 +154,7 @@ fn sinh64(z: Complex(f64)) Complex(f64) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "sinh32" { test sinh32 {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = sinh(a); const c = sinh(a);
@ -162,7 +162,7 @@ test "sinh32" {
try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon)); try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
} }
test "sinh64" { test sinh64 {
const a = Complex(f64).init(5, 3); const a = Complex(f64).init(5, 3);
const c = sinh(a); const c = sinh(a);

View File

@ -129,7 +129,7 @@ fn sqrt64(z: Complex(f64)) Complex(f64) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "sqrt32" { test sqrt32 {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = sqrt(a); const c = sqrt(a);
@ -137,7 +137,7 @@ test "sqrt32" {
try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon)); try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
} }
test "sqrt64" { test sqrt64 {
const a = Complex(f64).init(5, 3); const a = Complex(f64).init(5, 3);
const c = sqrt(a); const c = sqrt(a);

View File

@ -14,7 +14,7 @@ pub fn tan(z: anytype) Complex(@TypeOf(z.re, z.im)) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "tan" { test tan {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = tan(a); const c = tan(a);

View File

@ -103,7 +103,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
const epsilon = 0.0001; const epsilon = 0.0001;
test "tanh32" { test tanh32 {
const a = Complex(f32).init(5, 3); const a = Complex(f32).init(5, 3);
const c = tanh(a); const c = tanh(a);
@ -111,7 +111,7 @@ test "tanh32" {
try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon)); try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
} }
test "tanh64" { test tanh64 {
const a = Complex(f64).init(5, 3); const a = Complex(f64).init(5, 3);
const c = tanh(a); const c = tanh(a);

View File

@ -86,12 +86,12 @@ fn cosh64(x: f64) f64 {
return expo2(ax); return expo2(ax);
} }
test "cosh" { test cosh {
try expect(cosh(@as(f32, 1.5)) == cosh32(1.5)); try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
try expect(cosh(@as(f64, 1.5)) == cosh64(1.5)); try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
} }
test "cosh32" { test cosh32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon)); try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
@ -104,7 +104,7 @@ test "cosh32" {
try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon)); try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
} }
test "cosh64" { test cosh64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon)); try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));

View File

@ -286,12 +286,12 @@ fn expm1_64(x_: f64) f64 {
} }
} }
test "exp1m" { test expm1 {
try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0)); try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0)); try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
} }
test "expm1_32" { test expm1_32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.isPositiveZero(expm1_32(0.0))); try expect(math.isPositiveZero(expm1_32(0.0)));
@ -301,7 +301,7 @@ test "expm1_32" {
try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon)); try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
} }
test "expm1_64" { test expm1_64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.isPositiveZero(expm1_64(0.0))); try expect(math.isPositiveZero(expm1_64(0.0)));

View File

@ -132,7 +132,7 @@ test "float bits" {
} }
} }
test "inf" { test inf {
const inf_u16: u16 = 0x7C00; const inf_u16: u16 = 0x7C00;
const inf_u32: u32 = 0x7F800000; const inf_u32: u32 = 0x7F800000;
const inf_u64: u64 = 0x7FF0000000000000; const inf_u64: u64 = 0x7FF0000000000000;
@ -145,7 +145,7 @@ test "inf" {
try expectEqual(inf_u128, @as(u128, @bitCast(inf(f128)))); try expectEqual(inf_u128, @as(u128, @bitCast(inf(f128))));
} }
test "nan" { test nan {
const qnan_u16: u16 = 0x7E00; const qnan_u16: u16 = 0x7E00;
const qnan_u32: u32 = 0x7FC00000; const qnan_u32: u32 = 0x7FC00000;
const qnan_u64: u64 = 0x7FF8000000000000; const qnan_u64: u64 = 0x7FF8000000000000;
@ -158,7 +158,7 @@ test "nan" {
try expectEqual(qnan_u128, @as(u128, @bitCast(nan(f128)))); try expectEqual(qnan_u128, @as(u128, @bitCast(nan(f128))));
} }
test "snan" { test snan {
// TODO: https://github.com/ziglang/zig/issues/14366 // TODO: https://github.com/ziglang/zig/issues/14366
if (builtin.zig_backend == .stage2_llvm and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; if (builtin.zig_backend == .stage2_llvm and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;

View File

@ -240,7 +240,7 @@ const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const expectApproxEqRel = std.testing.expectApproxEqRel; const expectApproxEqRel = std.testing.expectApproxEqRel;
test "gamma" { test gamma {
inline for (&.{ f32, f64 }) |T| { inline for (&.{ f32, f64 }) |T| {
const eps = @sqrt(std.math.floatEps(T)); const eps = @sqrt(std.math.floatEps(T));
try expectApproxEqRel(@as(T, 120), gamma(T, 6), eps); try expectApproxEqRel(@as(T, 120), gamma(T, 6), eps);
@ -286,7 +286,7 @@ test "gamma.special" {
} }
} }
test "lgamma" { test lgamma {
inline for (&.{ f32, f64 }) |T| { inline for (&.{ f32, f64 }) |T| {
const eps = @sqrt(std.math.floatEps(T)); const eps = @sqrt(std.math.floatEps(T));
try expectApproxEqRel(@as(T, @log(24.0)), lgamma(T, 5), eps); try expectApproxEqRel(@as(T, @log(24.0)), lgamma(T, 5), eps);

View File

@ -124,7 +124,7 @@ fn hypot64(x: f64, y: f64) f64 {
return z * @sqrt(ly + lx + hy + hx); return z * @sqrt(ly + lx + hy + hx);
} }
test "hypot" { test hypot {
const x32: f32 = 0.0; const x32: f32 = 0.0;
const y32: f32 = -1.2; const y32: f32 = -1.2;
const x64: f64 = 0.0; const x64: f64 = 0.0;
@ -133,7 +133,7 @@ test "hypot" {
try expect(hypot(x64, y64) == hypot64(0.0, -1.2)); try expect(hypot(x64, y64) == hypot64(0.0, -1.2));
} }
test "hypot32" { test hypot32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon)); try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
@ -145,7 +145,7 @@ test "hypot32" {
try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon)); try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
} }
test "hypot64" { test hypot64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon)); try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));

View File

@ -182,12 +182,12 @@ fn log1p_64(x: f64) f64 {
return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi; return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
} }
test "log1p" { test log1p {
try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0)); try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0)); try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
} }
test "log1p_32" { test log1p_32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
@ -199,7 +199,7 @@ test "log1p_32" {
try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon)); try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
} }
test "log1p_64" { test log1p_64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));

View File

@ -42,7 +42,7 @@ pub fn log2(x: anytype) @TypeOf(x) {
} }
} }
test "log2" { test log2 {
// https://github.com/ziglang/zig/issues/13703 // https://github.com/ziglang/zig/issues/13703
if (builtin.cpu.arch == .aarch64 and builtin.os.tag == .windows) return error.SkipZigTest; if (builtin.cpu.arch == .aarch64 and builtin.os.tag == .windows) return error.SkipZigTest;

View File

@ -123,14 +123,14 @@ fn modf64(x: f64) modf64_result {
return result; return result;
} }
test "modf" { test modf {
const a = modf(@as(f32, 1.0)); const a = modf(@as(f32, 1.0));
const b = modf32(1.0); const b = modf32(1.0);
// NOTE: No struct comparison on generic return type function? non-named, makes sense, but still. // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
try expectEqual(a, b); try expectEqual(a, b);
} }
test "modf32" { test modf32 {
const epsilon = 0.000001; const epsilon = 0.000001;
var r: modf32_result = undefined; var r: modf32_result = undefined;
@ -155,7 +155,7 @@ test "modf32" {
try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon)); try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
} }
test "modf64" { test modf64 {
const epsilon = 0.000001; const epsilon = 0.000001;
var r: modf64_result = undefined; var r: modf64_result = undefined;

View File

@ -91,7 +91,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
return acc; return acc;
} }
test "powi" { test powi {
try testing.expectError(error.Overflow, powi(i8, -66, 6)); try testing.expectError(error.Overflow, powi(i8, -66, 6));
try testing.expectError(error.Overflow, powi(i16, -13, 13)); try testing.expectError(error.Overflow, powi(i16, -13, 13));
try testing.expectError(error.Overflow, powi(i32, -32, 21)); try testing.expectError(error.Overflow, powi(i32, -32, 21));

View File

@ -91,12 +91,12 @@ fn sinh64(x: f64) f64 {
return 2 * h * expo2(ax); return 2 * h * expo2(ax);
} }
test "sinh" { test sinh {
try expect(sinh(@as(f32, 1.5)) == sinh32(1.5)); try expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
try expect(sinh(@as(f64, 1.5)) == sinh64(1.5)); try expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
} }
test "sinh32" { test sinh32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
@ -109,7 +109,7 @@ test "sinh32" {
try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon)); try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
} }
test "sinh64" { test sinh64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));

View File

@ -104,12 +104,12 @@ fn tanh64(x: f64) f64 {
return if (sign) -t else t; return if (sign) -t else t;
} }
test "tanh" { test tanh {
try expect(tanh(@as(f32, 1.5)) == tanh32(1.5)); try expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
try expect(tanh(@as(f64, 1.5)) == tanh64(1.5)); try expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
} }
test "tanh32" { test tanh32 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
@ -122,7 +122,7 @@ test "tanh32" {
try expect(math.approxEqAbs(f32, tanh32(-37.45), -1.0, epsilon)); try expect(math.approxEqAbs(f32, tanh32(-37.45), -1.0, epsilon));
} }
test "tanh64" { test tanh64 {
const epsilon = 0.000001; const epsilon = 0.000001;
try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon)); try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));

View File

@ -46,7 +46,7 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
} }
} }
test "stringToEnum" { test stringToEnum {
const E1 = enum { const E1 = enum {
A, A,
B, B,
@ -73,7 +73,7 @@ pub fn alignment(comptime T: type) comptime_int {
}; };
} }
test "alignment" { test alignment {
try testing.expect(alignment(u8) == 1); try testing.expect(alignment(u8) == 1);
try testing.expect(alignment(*align(1) u8) == 1); try testing.expect(alignment(*align(1) u8) == 1);
try testing.expect(alignment(*align(2) u8) == 2); try testing.expect(alignment(*align(2) u8) == 2);
@ -94,7 +94,7 @@ pub fn Child(comptime T: type) type {
}; };
} }
test "Child" { test Child {
try testing.expect(Child([1]u8) == u8); try testing.expect(Child([1]u8) == u8);
try testing.expect(Child(*u8) == u8); try testing.expect(Child(*u8) == u8);
try testing.expect(Child([]u8) == u8); try testing.expect(Child([]u8) == u8);
@ -121,7 +121,7 @@ pub fn Elem(comptime T: type) type {
@compileError("Expected pointer, slice, array or vector type, found '" ++ @typeName(T) ++ "'"); @compileError("Expected pointer, slice, array or vector type, found '" ++ @typeName(T) ++ "'");
} }
test "Elem" { test Elem {
try testing.expect(Elem([1]u8) == u8); try testing.expect(Elem([1]u8) == u8);
try testing.expect(Elem([*]u8) == u8); try testing.expect(Elem([*]u8) == u8);
try testing.expect(Elem([]u8) == u8); try testing.expect(Elem([]u8) == u8);
@ -255,7 +255,7 @@ pub fn containerLayout(comptime T: type) Type.ContainerLayout {
}; };
} }
test "containerLayout" { test containerLayout {
const S1 = struct {}; const S1 = struct {};
const S2 = packed struct {}; const S2 = packed struct {};
const S3 = extern struct {}; const S3 = extern struct {};
@ -289,7 +289,7 @@ pub fn declarations(comptime T: type) []const Type.Declaration {
}; };
} }
test "declarations" { test declarations {
const E1 = enum { const E1 = enum {
A, A,
@ -329,7 +329,7 @@ pub fn declarationInfo(comptime T: type, comptime decl_name: []const u8) Type.De
@compileError("'" ++ @typeName(T) ++ "' has no declaration '" ++ decl_name ++ "'"); @compileError("'" ++ @typeName(T) ++ "' has no declaration '" ++ decl_name ++ "'");
} }
test "declarationInfo" { test declarationInfo {
const E1 = enum { const E1 = enum {
A, A,
@ -370,7 +370,7 @@ pub fn fields(comptime T: type) switch (@typeInfo(T)) {
}; };
} }
test "fields" { test fields {
const E1 = enum { const E1 = enum {
A, A,
}; };
@ -409,7 +409,7 @@ pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeIn
return fields(T)[@intFromEnum(field)]; return fields(T)[@intFromEnum(field)];
} }
test "fieldInfo" { test fieldInfo {
const E1 = enum { const E1 = enum {
A, A,
}; };
@ -442,7 +442,7 @@ pub fn FieldType(comptime T: type, comptime field: FieldEnum(T)) type {
return fieldInfo(T, field).type; return fieldInfo(T, field).type;
} }
test "FieldType" { test FieldType {
const S = struct { const S = struct {
a: u8, a: u8,
b: u16, b: u16,
@ -470,7 +470,7 @@ pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 {
}; };
} }
test "fieldNames" { test fieldNames {
const E1 = enum { A, B }; const E1 = enum { A, B };
const E2 = error{A}; const E2 = error{A};
const S1 = struct { const S1 = struct {
@ -511,7 +511,7 @@ pub fn tags(comptime T: type) *const [fields(T).len]T {
}; };
} }
test "tags" { test tags {
const E1 = enum { A, B }; const E1 = enum { A, B };
const E2 = error{A}; const E2 = error{A};
@ -604,7 +604,7 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
); );
} }
test "FieldEnum" { test FieldEnum {
try expectEqualEnum(enum {}, FieldEnum(struct {})); try expectEqualEnum(enum {}, FieldEnum(struct {}));
try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 })); try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 })); try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));
@ -639,7 +639,7 @@ pub fn DeclEnum(comptime T: type) type {
}); });
} }
test "DeclEnum" { test DeclEnum {
const A = struct { const A = struct {
pub const a: u8 = 0; pub const a: u8 = 0;
}; };
@ -670,7 +670,7 @@ pub fn Tag(comptime T: type) type {
}; };
} }
test "Tag" { test Tag {
const E = enum(u8) { const E = enum(u8) {
C = 33, C = 33,
D, D,
@ -690,7 +690,7 @@ pub fn activeTag(u: anytype) Tag(@TypeOf(u)) {
return @as(Tag(T), u); return @as(Tag(T), u);
} }
test "activeTag" { test activeTag {
const UE = enum { const UE = enum {
Int, Int,
Float, Float,
@ -727,7 +727,7 @@ pub fn TagPayload(comptime U: type, comptime tag: Tag(U)) type {
return TagPayloadByName(U, @tagName(tag)); return TagPayloadByName(U, @tagName(tag));
} }
test "TagPayload" { test TagPayload {
const Event = union(enum) { const Event = union(enum) {
Moved: struct { Moved: struct {
from: i32, from: i32,
@ -802,7 +802,7 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {
} }
} }
test "eql" { test eql {
const S = struct { const S = struct {
a: u32, a: u32,
b: f64, b: f64,
@ -863,7 +863,7 @@ test "eql" {
try testing.expect(!eql(v1, v3)); try testing.expect(!eql(v1, v3));
} }
test "intToEnum with error return" { test intToEnum {
const E1 = enum { const E1 = enum {
A, A,
}; };
@ -965,7 +965,7 @@ pub fn Float(comptime bit_count: u8) type {
}); });
} }
test "Float" { test Float {
try testing.expectEqual(f16, Float(16)); try testing.expectEqual(f16, Float(16));
try testing.expectEqual(f32, Float(32)); try testing.expectEqual(f32, Float(32));
try testing.expectEqual(f64, Float(64)); try testing.expectEqual(f64, Float(64));
@ -1057,7 +1057,7 @@ const TupleTester = struct {
} }
}; };
test "ArgsTuple" { test ArgsTuple {
TupleTester.assertTuple(.{}, ArgsTuple(fn () void)); TupleTester.assertTuple(.{}, ArgsTuple(fn () void));
TupleTester.assertTuple(.{u32}, ArgsTuple(fn (a: u32) []const u8)); TupleTester.assertTuple(.{u32}, ArgsTuple(fn (a: u32) []const u8));
TupleTester.assertTuple(.{ u32, f16 }, ArgsTuple(fn (a: u32, b: f16) noreturn)); TupleTester.assertTuple(.{ u32, f16 }, ArgsTuple(fn (a: u32, b: f16) noreturn));
@ -1065,7 +1065,7 @@ test "ArgsTuple" {
TupleTester.assertTuple(.{u32}, ArgsTuple(fn (comptime a: u32) []const u8)); TupleTester.assertTuple(.{u32}, ArgsTuple(fn (comptime a: u32) []const u8));
} }
test "Tuple" { test Tuple {
TupleTester.assertTuple(.{}, Tuple(&[_]type{})); TupleTester.assertTuple(.{}, Tuple(&[_]type{}));
TupleTester.assertTuple(.{u32}, Tuple(&[_]type{u32})); TupleTester.assertTuple(.{u32}, Tuple(&[_]type{u32}));
TupleTester.assertTuple(.{ u32, f16 }, Tuple(&[_]type{ u32, f16 })); TupleTester.assertTuple(.{ u32, f16 }, Tuple(&[_]type{ u32, f16 }));
@ -1103,7 +1103,7 @@ pub fn isError(error_union: anytype) bool {
return if (error_union) |_| false else |_| true; return if (error_union) |_| false else |_| true;
} }
test "isError" { test isError {
try std.testing.expect(isError(math.divTrunc(u8, 5, 0))); try std.testing.expect(isError(math.divTrunc(u8, 5, 0)));
try std.testing.expect(!isError(math.divTrunc(u8, 5, 5))); try std.testing.expect(!isError(math.divTrunc(u8, 5, 5)));
} }
@ -1121,7 +1121,7 @@ pub inline fn hasFn(comptime T: type, comptime name: []const u8) bool {
return @typeInfo(@TypeOf(@field(T, name))) == .Fn; return @typeInfo(@TypeOf(@field(T, name))) == .Fn;
} }
test "hasFn" { test hasFn {
const S1 = struct { const S1 = struct {
pub fn foo() void {} pub fn foo() void {}
}; };
@ -1149,7 +1149,7 @@ pub inline fn hasMethod(comptime T: type, comptime name: []const u8) bool {
}; };
} }
test "hasMethod" { test hasMethod {
try std.testing.expect(!hasMethod(u32, "foo")); try std.testing.expect(!hasMethod(u32, "foo"));
try std.testing.expect(!hasMethod([]u32, "len")); try std.testing.expect(!hasMethod([]u32, "len"));
try std.testing.expect(!hasMethod(struct { u32, u64 }, "len")); try std.testing.expect(!hasMethod(struct { u32, u64 }, "len"));
@ -1218,7 +1218,7 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
}; };
} }
test "hasUniqueRepresentation" { test hasUniqueRepresentation {
const TestStruct1 = struct { const TestStruct1 = struct {
a: u32, a: u32,
b: u32, b: u32,