authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-02-26 15:14:43-08:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-02-26 15:18:31-08:00
log726a1149e05669e5cc05a16ce877bbb2be787e39
tree0f5ae1dd819410e2b88def157161141fd79c8b6a
parent16b3d1004ee520341839305826fe065eb5d8c818

Change many test blocks to doctests/decltests


51 files changed, 143 insertions(+), 145 deletions(-)

lib/std/Random/Isaac64.zig+1-1
...@@ -201,7 +201,7 @@ test "sequence" {...@@ -201,7 +201,7 @@ test "sequence" {
201 }201 }
202}202}
203203
204test "fill" {204test fill {
205 var r = Isaac64.init(0);205 var r = Isaac64.init(0);
206206
207 // from reference implementation207 // from reference implementation
lib/std/Random/Pcg.zig+1-1
...@@ -92,7 +92,7 @@ test "sequence" {...@@ -92,7 +92,7 @@ test "sequence" {
92 }92 }
93}93}
9494
95test "fill" {95test fill {
96 var r = Pcg.init(0);96 var r = Pcg.init(0);
97 const s0: u64 = 0x9394bf54ce5d79de;97 const s0: u64 = 0x9394bf54ce5d79de;
98 const s1: u64 = 0x84e9c579ef59bbf7;98 const s1: u64 = 0x84e9c579ef59bbf7;
lib/std/Random/RomuTrio.zig+1-1
...@@ -94,7 +94,7 @@ test "sequence" {...@@ -94,7 +94,7 @@ test "sequence" {
94 }94 }
95}95}
9696
97test "fill" {97test fill {
98 // Unfortunately there does not seem to be an official test sequence.98 // Unfortunately there does not seem to be an official test sequence.
99 var r = RomuTrio.init(0);99 var r = RomuTrio.init(0);
100100
lib/std/Random/Sfc64.zig+1-1
...@@ -98,7 +98,7 @@ test "sequence" {...@@ -98,7 +98,7 @@ test "sequence" {
98 }98 }
99}99}
100100
101test "fill" {101test fill {
102 // Unfortunately there does not seem to be an official test sequence.102 // Unfortunately there does not seem to be an official test sequence.
103 var r = Sfc64.init(0);103 var r = Sfc64.init(0);
104104
lib/std/Random/Xoroshiro128.zig+1-1
...@@ -122,7 +122,7 @@ test "sequence" {...@@ -122,7 +122,7 @@ test "sequence" {
122 }122 }
123}123}
124124
125test "fill" {125test fill {
126 var r = Xoroshiro128.init(0);126 var r = Xoroshiro128.init(0);
127 r.s[0] = 0xaeecf86f7878dd75;127 r.s[0] = 0xaeecf86f7878dd75;
128 r.s[1] = 0x01cd153642e72622;128 r.s[1] = 0x01cd153642e72622;
lib/std/Random/Xoshiro256.zig+1-1
...@@ -122,7 +122,7 @@ test "sequence" {...@@ -122,7 +122,7 @@ test "sequence" {
122 }122 }
123}123}
124124
125test "fill" {125test fill {
126 var r = Xoshiro256.init(0);126 var r = Xoshiro256.init(0);
127127
128 const seq = [_]u64{128 const seq = [_]u64{
lib/std/SemanticVersion.zig+1-1
...@@ -166,7 +166,7 @@ pub fn format(...@@ -166,7 +166,7 @@ pub fn format(
166const expect = std.testing.expect;166const expect = std.testing.expect;
167const expectError = std.testing.expectError;167const expectError = std.testing.expectError;
168168
169test "format" {169test format {
170 // Many of these test strings are from https://github.com/semver/semver.org/issues/59#issuecomment-390854010.170 // Many of these test strings are from https://github.com/semver/semver.org/issues/59#issuecomment-390854010.
171171
172 // Valid version strings should be accepted.172 // Valid version strings should be accepted.
lib/std/Thread.zig+2-2
...@@ -1437,7 +1437,7 @@ fn testIncrementNotify(value: *usize, event: *ResetEvent) void {...@@ -1437,7 +1437,7 @@ fn testIncrementNotify(value: *usize, event: *ResetEvent) void {
1437 event.set();1437 event.set();
1438}1438}
14391439
1440test "join" {1440test join {
1441 if (builtin.single_threaded) return error.SkipZigTest;1441 if (builtin.single_threaded) return error.SkipZigTest;
14421442
1443 var value: usize = 0;1443 var value: usize = 0;
...@@ -1449,7 +1449,7 @@ test "join" {...@@ -1449,7 +1449,7 @@ test "join" {
1449 try std.testing.expectEqual(value, 1);1449 try std.testing.expectEqual(value, 1);
1450}1450}
14511451
1452test "detach" {1452test detach {
1453 if (builtin.single_threaded) return error.SkipZigTest;1453 if (builtin.single_threaded) return error.SkipZigTest;
14541454
1455 var value: usize = 0;1455 var value: usize = 0;
lib/std/Thread/Condition.zig+2-2
...@@ -362,7 +362,7 @@ test "wait and signal" {...@@ -362,7 +362,7 @@ test "wait and signal" {
362 }362 }
363}363}
364364
365test "signal" {365test signal {
366 // This test requires spawning threads366 // This test requires spawning threads
367 if (builtin.single_threaded) {367 if (builtin.single_threaded) {
368 return error.SkipZigTest;368 return error.SkipZigTest;
...@@ -491,7 +491,7 @@ test "multi signal" {...@@ -491,7 +491,7 @@ test "multi signal" {
491 }491 }
492}492}
493493
494test "broadcasting" {494test broadcast {
495 // This test requires spawning threads495 // This test requires spawning threads
496 if (builtin.single_threaded) {496 if (builtin.single_threaded) {
497 return error.SkipZigTest;497 return error.SkipZigTest;
lib/std/Thread/Semaphore.zig+2-2
...@@ -71,7 +71,7 @@ pub fn post(sem: *Semaphore) void {...@@ -71,7 +71,7 @@ pub fn post(sem: *Semaphore) void {
71 sem.cond.signal();71 sem.cond.signal();
72}72}
7373
74test "Semaphore" {74test Semaphore {
75 if (builtin.single_threaded) {75 if (builtin.single_threaded) {
76 return error.SkipZigTest;76 return error.SkipZigTest;
77 }77 }
...@@ -97,7 +97,7 @@ test "Semaphore" {...@@ -97,7 +97,7 @@ test "Semaphore" {
97 try testing.expect(n == num_threads);97 try testing.expect(n == num_threads);
98}98}
9999
100test "timedWait" {100test timedWait {
101 var sem = Semaphore{};101 var sem = Semaphore{};
102 try testing.expectEqual(0, sem.permits);102 try testing.expectEqual(0, sem.permits);
103103
lib/std/buf_set.zig+17-17
...@@ -90,6 +90,23 @@ pub const BufSet = struct {...@@ -90,6 +90,23 @@ pub const BufSet = struct {
90 return self.cloneWithAllocator(self.allocator());90 return self.cloneWithAllocator(self.allocator());
91 }91 }
9292
93 test clone {
94 var original = BufSet.init(testing.allocator);
95 defer original.deinit();
96 try original.insert("x");
97
98 var cloned = try original.clone();
99 defer cloned.deinit();
100 cloned.remove("x");
101 try testing.expect(original.count() == 1);
102 try testing.expect(cloned.count() == 0);
103
104 try testing.expectError(
105 error.OutOfMemory,
106 original.cloneWithAllocator(testing.failing_allocator),
107 );
108 }
109
93 fn free(self: *const BufSet, value: []const u8) void {110 fn free(self: *const BufSet, value: []const u8) void {
94 self.hash_map.allocator.free(value);111 self.hash_map.allocator.free(value);
95 }112 }
...@@ -115,23 +132,6 @@ test BufSet {...@@ -115,23 +132,6 @@ test BufSet {
115 try bufset.insert("z");132 try bufset.insert("z");
116}133}
117134
118test "clone" {
119 var original = BufSet.init(testing.allocator);
120 defer original.deinit();
121 try original.insert("x");
122
123 var cloned = try original.clone();
124 defer cloned.deinit();
125 cloned.remove("x");
126 try testing.expect(original.count() == 1);
127 try testing.expect(cloned.count() == 0);
128
129 try testing.expectError(
130 error.OutOfMemory,
131 original.cloneWithAllocator(testing.failing_allocator),
132 );
133}
134
135test "clone with arena" {135test "clone with arena" {
136 const allocator = std.testing.allocator;136 const allocator = std.testing.allocator;
137 var arena = std.heap.ArenaAllocator.init(allocator);137 var arena = std.heap.ArenaAllocator.init(allocator);
lib/std/compress/flate/CircularBuffer.zig+3-3
...@@ -130,7 +130,7 @@ pub fn full(self: *Self) bool {...@@ -130,7 +130,7 @@ pub fn full(self: *Self) bool {
130}130}
131131
132// example from: https://youtu.be/SJPvNi4HrWQ?t=3558132// example from: https://youtu.be/SJPvNi4HrWQ?t=3558
133test "writeMatch" {133test writeMatch {
134 var cb: Self = .{};134 var cb: Self = .{};
135135
136 cb.writeAll("a salad; ");136 cb.writeAll("a salad; ");
...@@ -150,7 +150,7 @@ test "writeMatch overlap" {...@@ -150,7 +150,7 @@ test "writeMatch overlap" {
150 try testing.expectEqualStrings("a b c b c b c d", cb.read());150 try testing.expectEqualStrings("a b c b c b c d", cb.read());
151}151}
152152
153test "readAtMost" {153test readAtMost {
154 var cb: Self = .{};154 var cb: Self = .{};
155155
156 cb.writeAll("0123456789");156 cb.writeAll("0123456789");
...@@ -165,7 +165,7 @@ test "readAtMost" {...@@ -165,7 +165,7 @@ test "readAtMost" {
165 try testing.expectEqualStrings("", cb.read());165 try testing.expectEqualStrings("", cb.read());
166}166}
167167
168test "CircularBuffer" {168test Self {
169 var cb: Self = .{};169 var cb: Self = .{};
170170
171 const data = "0123456789abcdef" ** (1024 / 16);171 const data = "0123456789abcdef" ** (1024 / 16);
lib/std/compress/flate/Lookup.zig+2-2
...@@ -83,7 +83,7 @@ fn hashu(v: u32) u32 {...@@ -83,7 +83,7 @@ fn hashu(v: u32) u32 {
83 return @intCast((v *% prime4) >> consts.lookup.shift);83 return @intCast((v *% prime4) >> consts.lookup.shift);
84}84}
8585
86test "add/prev" {86test add {
87 const data = [_]u8{87 const data = [_]u8{
88 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,88 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
89 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,89 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
...@@ -107,7 +107,7 @@ test "add/prev" {...@@ -107,7 +107,7 @@ test "add/prev" {
107 try expect(h.chain[2 + 8] == 2);107 try expect(h.chain[2 + 8] == 2);
108}108}
109109
110test "bulkAdd" {110test bulkAdd {
111 const data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";111 const data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
112112
113 // one by one113 // one by one
lib/std/compress/flate/SlidingWindow.zig+2-2
...@@ -122,7 +122,7 @@ pub fn tokensBuffer(self: *Self) ?[]const u8 {...@@ -122,7 +122,7 @@ pub fn tokensBuffer(self: *Self) ?[]const u8 {
122 return self.buffer[@intCast(self.fp)..self.rp];122 return self.buffer[@intCast(self.fp)..self.rp];
123}123}
124124
125test "match" {125test match {
126 const data = "Blah blah blah blah blah!";126 const data = "Blah blah blah blah blah!";
127 var win: Self = .{};127 var win: Self = .{};
128 try expect(win.write(data) == data.len);128 try expect(win.write(data) == data.len);
...@@ -142,7 +142,7 @@ test "match" {...@@ -142,7 +142,7 @@ test "match" {
142 try expect(win.match(15, 20, 4) == 0);142 try expect(win.match(15, 20, 4) == 0);
143}143}
144144
145test "slide" {145test slide {
146 var win: Self = .{};146 var win: Self = .{};
147 win.wp = Self.buffer_len - 11;147 win.wp = Self.buffer_len - 11;
148 win.rp = Self.buffer_len - 111;148 win.rp = Self.buffer_len - 111;
lib/std/compress/flate/huffman_encoder.zig+1-1
...@@ -458,7 +458,7 @@ fn bitReverse(comptime T: type, value: T, n: usize) T {...@@ -458,7 +458,7 @@ fn bitReverse(comptime T: type, value: T, n: usize) T {
458 return r >> @as(math.Log2Int(T), @intCast(@typeInfo(T).Int.bits - n));458 return r >> @as(math.Log2Int(T), @intCast(@typeInfo(T).Int.bits - n));
459}459}
460460
461test "bitReverse" {461test bitReverse {
462 const ReverseBitsTest = struct {462 const ReverseBitsTest = struct {
463 in: u16,463 in: u16,
464 bit_count: u5,464 bit_count: u5,
lib/std/enums.zig+6-6
...@@ -120,7 +120,7 @@ pub fn directEnumArray(...@@ -120,7 +120,7 @@ pub fn directEnumArray(
120 return directEnumArrayDefault(E, Data, null, max_unused_slots, init_values);120 return directEnumArrayDefault(E, Data, null, max_unused_slots, init_values);
121}121}
122122
123test "directEnumArray" {123test directEnumArray {
124 const E = enum(i4) { a = 4, b = 6, c = 2 };124 const E = enum(i4) { a = 4, b = 6, c = 2 };
125 var runtime_false: bool = false;125 var runtime_false: bool = false;
126 _ = &runtime_false;126 _ = &runtime_false;
...@@ -163,7 +163,7 @@ pub fn directEnumArrayDefault(...@@ -163,7 +163,7 @@ pub fn directEnumArrayDefault(
163 return result;163 return result;
164}164}
165165
166test "directEnumArrayDefault" {166test directEnumArrayDefault {
167 const E = enum(i4) { a = 4, b = 6, c = 2 };167 const E = enum(i4) { a = 4, b = 6, c = 2 };
168 var runtime_false: bool = false;168 var runtime_false: bool = false;
169 _ = &runtime_false;169 _ = &runtime_false;
...@@ -214,7 +214,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {...@@ -214,7 +214,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
214 };214 };
215}215}
216216
217test "nameCast" {217test nameCast {
218 const A = enum(u1) { a = 0, b = 1 };218 const A = enum(u1) { a = 0, b = 1 };
219 const B = enum(u1) { a = 1, b = 0 };219 const B = enum(u1) { a = 1, b = 0 };
220 try testing.expectEqual(A.a, nameCast(A, .a));220 try testing.expectEqual(A.a, nameCast(A, .a));
...@@ -515,7 +515,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -515,7 +515,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
515 };515 };
516}516}
517517
518test "EnumMultiset" {518test EnumMultiset {
519 const Ball = enum { red, green, blue };519 const Ball = enum { red, green, blue };
520520
521 const empty = EnumMultiset(Ball).initEmpty();521 const empty = EnumMultiset(Ball).initEmpty();
...@@ -1298,7 +1298,7 @@ pub fn ensureIndexer(comptime T: type) void {...@@ -1298,7 +1298,7 @@ pub fn ensureIndexer(comptime T: type) void {
1298 }1298 }
1299}1299}
13001300
1301test "ensureIndexer" {1301test ensureIndexer {
1302 ensureIndexer(struct {1302 ensureIndexer(struct {
1303 pub const Key = u32;1303 pub const Key = u32;
1304 pub const count: comptime_int = 8;1304 pub const count: comptime_int = 8;
...@@ -1535,7 +1535,7 @@ test "EnumIndexer empty" {...@@ -1535,7 +1535,7 @@ test "EnumIndexer empty" {
1535 try testing.expectEqual(0, Indexer.count);1535 try testing.expectEqual(0, Indexer.count);
1536}1536}
15371537
1538test "enumValues" {1538test values {
1539 const E = enum {1539 const E = enum {
1540 X,1540 X,
1541 Y,1541 Y,
lib/std/math/acos.zig+3-3
...@@ -148,12 +148,12 @@ fn acos64(x: f64) f64 {...@@ -148,12 +148,12 @@ fn acos64(x: f64) f64 {
148 return 2 * (df + w);148 return 2 * (df + w);
149}149}
150150
151test "acos" {151test acos {
152 try expect(acos(@as(f32, 0.0)) == acos32(0.0));152 try expect(acos(@as(f32, 0.0)) == acos32(0.0));
153 try expect(acos(@as(f64, 0.0)) == acos64(0.0));153 try expect(acos(@as(f64, 0.0)) == acos64(0.0));
154}154}
155155
156test "acos32" {156test acos32 {
157 const epsilon = 0.000001;157 const epsilon = 0.000001;
158158
159 try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));159 try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
...@@ -164,7 +164,7 @@ test "acos32" {...@@ -164,7 +164,7 @@ test "acos32" {
164 try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));164 try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
165}165}
166166
167test "acos64" {167test acos64 {
168 const epsilon = 0.000001;168 const epsilon = 0.000001;
169169
170 try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));170 try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
lib/std/math/acosh.zig+3-3
...@@ -59,12 +59,12 @@ fn acosh64(x: f64) f64 {...@@ -59,12 +59,12 @@ fn acosh64(x: f64) f64 {
59 }59 }
60}60}
6161
62test "acosh" {62test acosh {
63 try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));63 try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
64 try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));64 try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
65}65}
6666
67test "acosh32" {67test acosh32 {
68 const epsilon = 0.000001;68 const epsilon = 0.000001;
6969
70 try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));70 try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
...@@ -73,7 +73,7 @@ test "acosh32" {...@@ -73,7 +73,7 @@ test "acosh32" {
73 try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));73 try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
74}74}
7575
76test "acosh64" {76test acosh64 {
77 const epsilon = 0.000001;77 const epsilon = 0.000001;
7878
79 try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));79 try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
lib/std/math/asin.zig+3-3
...@@ -141,12 +141,12 @@ fn asin64(x: f64) f64 {...@@ -141,12 +141,12 @@ fn asin64(x: f64) f64 {
141 }141 }
142}142}
143143
144test "asin" {144test asin {
145 try expect(asin(@as(f32, 0.0)) == asin32(0.0));145 try expect(asin(@as(f32, 0.0)) == asin32(0.0));
146 try expect(asin(@as(f64, 0.0)) == asin64(0.0));146 try expect(asin(@as(f64, 0.0)) == asin64(0.0));
147}147}
148148
149test "asin32" {149test asin32 {
150 const epsilon = 0.000001;150 const epsilon = 0.000001;
151151
152 try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));152 try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
...@@ -157,7 +157,7 @@ test "asin32" {...@@ -157,7 +157,7 @@ test "asin32" {
157 try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));157 try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
158}158}
159159
160test "asin64" {160test asin64 {
161 const epsilon = 0.000001;161 const epsilon = 0.000001;
162162
163 try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));163 try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
lib/std/math/asinh.zig+3-3
...@@ -80,12 +80,12 @@ fn asinh64(x: f64) f64 {...@@ -80,12 +80,12 @@ fn asinh64(x: f64) f64 {
80 return if (s != 0) -rx else rx;80 return if (s != 0) -rx else rx;
81}81}
8282
83test "asinh" {83test asinh {
84 try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));84 try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
85 try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));85 try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
86}86}
8787
88test "asinh32" {88test asinh32 {
89 const epsilon = 0.000001;89 const epsilon = 0.000001;
9090
91 try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));91 try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
...@@ -98,7 +98,7 @@ test "asinh32" {...@@ -98,7 +98,7 @@ test "asinh32" {
98 try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));98 try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
99}99}
100100
101test "asinh64" {101test asinh64 {
102 const epsilon = 0.000001;102 const epsilon = 0.000001;
103103
104 try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));104 try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
lib/std/math/atan.zig+3-3
...@@ -212,12 +212,12 @@ fn atan64(x_: f64) f64 {...@@ -212,12 +212,12 @@ fn atan64(x_: f64) f64 {
212 }212 }
213}213}
214214
215test "atan" {215test atan {
216 try expect(@as(u32, @bitCast(atan(@as(f32, 0.2)))) == @as(u32, @bitCast(atan32(0.2))));216 try expect(@as(u32, @bitCast(atan(@as(f32, 0.2)))) == @as(u32, @bitCast(atan32(0.2))));
217 try expect(atan(@as(f64, 0.2)) == atan64(0.2));217 try expect(atan(@as(f64, 0.2)) == atan64(0.2));
218}218}
219219
220test "atan32" {220test atan32 {
221 const epsilon = 0.000001;221 const epsilon = 0.000001;
222222
223 try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));223 try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
...@@ -227,7 +227,7 @@ test "atan32" {...@@ -227,7 +227,7 @@ test "atan32" {
227 try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));227 try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
228}228}
229229
230test "atan64" {230test atan64 {
231 const epsilon = 0.000001;231 const epsilon = 0.000001;
232232
233 try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));233 try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
lib/std/math/atan2.zig+3-3
...@@ -214,7 +214,7 @@ fn atan2_64(y: f64, x: f64) f64 {...@@ -214,7 +214,7 @@ fn atan2_64(y: f64, x: f64) f64 {
214 }214 }
215}215}
216216
217test "atan2" {217test atan2 {
218 const y32: f32 = 0.2;218 const y32: f32 = 0.2;
219 const x32: f32 = 0.21;219 const x32: f32 = 0.21;
220 const y64: f64 = 0.2;220 const y64: f64 = 0.2;
...@@ -223,7 +223,7 @@ test "atan2" {...@@ -223,7 +223,7 @@ test "atan2" {
223 try expect(atan2(y64, x64) == atan2_64(0.2, 0.21));223 try expect(atan2(y64, x64) == atan2_64(0.2, 0.21));
224}224}
225225
226test "atan2_32" {226test atan2_32 {
227 const epsilon = 0.000001;227 const epsilon = 0.000001;
228228
229 try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));229 try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
...@@ -235,7 +235,7 @@ test "atan2_32" {...@@ -235,7 +235,7 @@ test "atan2_32" {
235 try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));235 try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
236}236}
237237
238test "atan2_64" {238test atan2_64 {
239 const epsilon = 0.000001;239 const epsilon = 0.000001;
240240
241 try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));241 try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
lib/std/math/atanh.zig+3-3
...@@ -84,12 +84,12 @@ fn atanh_64(x: f64) f64 {...@@ -84,12 +84,12 @@ fn atanh_64(x: f64) f64 {
84 return if (s != 0) -y else y;84 return if (s != 0) -y else y;
85}85}
8686
87test "atanh" {87test atanh {
88 try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));88 try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
89 try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));89 try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
90}90}
9191
92test "atanh_32" {92test atanh_32 {
93 const epsilon = 0.000001;93 const epsilon = 0.000001;
9494
95 try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));95 try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
...@@ -97,7 +97,7 @@ test "atanh_32" {...@@ -97,7 +97,7 @@ test "atanh_32" {
97 try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));97 try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
98}98}
9999
100test "atanh_64" {100test atanh_64 {
101 const epsilon = 0.000001;101 const epsilon = 0.000001;
102102
103 try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));103 try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
lib/std/math/big/rational.zig+1-1
...@@ -493,7 +493,7 @@ fn extractLowBits(a: Int, comptime T: type) T {...@@ -493,7 +493,7 @@ fn extractLowBits(a: Int, comptime T: type) T {
493 }493 }
494}494}
495495
496test "extractLowBits" {496test extractLowBits {
497 var a = try Int.initSet(testing.allocator, 0x11112222333344441234567887654321);497 var a = try Int.initSet(testing.allocator, 0x11112222333344441234567887654321);
498 defer a.deinit();498 defer a.deinit();
499499
lib/std/math/cbrt.zig+3-3
...@@ -119,12 +119,12 @@ fn cbrt64(x: f64) f64 {...@@ -119,12 +119,12 @@ fn cbrt64(x: f64) f64 {
119 return t + t * q;119 return t + t * q;
120}120}
121121
122test "cbrt" {122test cbrt {
123 try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));123 try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
124 try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));124 try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
125}125}
126126
127test "cbrt32" {127test cbrt32 {
128 const epsilon = 0.000001;128 const epsilon = 0.000001;
129129
130 try expect(math.isPositiveZero(cbrt32(0.0)));130 try expect(math.isPositiveZero(cbrt32(0.0)));
...@@ -135,7 +135,7 @@ test "cbrt32" {...@@ -135,7 +135,7 @@ test "cbrt32" {
135 try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));135 try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
136}136}
137137
138test "cbrt64" {138test cbrt64 {
139 const epsilon = 0.000001;139 const epsilon = 0.000001;
140140
141 try expect(math.isPositiveZero(cbrt64(0.0)));141 try expect(math.isPositiveZero(cbrt64(0.0)));
lib/std/math/complex/atan.zig+2-2
...@@ -120,7 +120,7 @@ fn atan64(z: Complex(f64)) Complex(f64) {...@@ -120,7 +120,7 @@ fn atan64(z: Complex(f64)) Complex(f64) {
120120
121const epsilon = 0.0001;121const epsilon = 0.0001;
122122
123test "atan32" {123test atan32 {
124 const a = Complex(f32).init(5, 3);124 const a = Complex(f32).init(5, 3);
125 const c = atan(a);125 const c = atan(a);
126126
...@@ -128,7 +128,7 @@ test "atan32" {...@@ -128,7 +128,7 @@ test "atan32" {
128 try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));128 try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
129}129}
130130
131test "atan64" {131test atan64 {
132 const a = Complex(f64).init(5, 3);132 const a = Complex(f64).init(5, 3);
133 const c = atan(a);133 const c = atan(a);
134134
lib/std/math/complex/atanh.zig+1-1
...@@ -14,7 +14,7 @@ pub fn atanh(z: anytype) Complex(@TypeOf(z.re, z.im)) {...@@ -14,7 +14,7 @@ pub fn atanh(z: anytype) Complex(@TypeOf(z.re, z.im)) {
1414
15const epsilon = 0.0001;15const epsilon = 0.0001;
1616
17test "atanh" {17test atanh {
18 const a = Complex(f32).init(5, 3);18 const a = Complex(f32).init(5, 3);
19 const c = atanh(a);19 const c = atanh(a);
2020
lib/std/math/complex/conj.zig+1-1
...@@ -10,7 +10,7 @@ pub fn conj(z: anytype) Complex(@TypeOf(z.re, z.im)) {...@@ -10,7 +10,7 @@ pub fn conj(z: anytype) Complex(@TypeOf(z.re, z.im)) {
10 return Complex(T).init(z.re, -z.im);10 return Complex(T).init(z.re, -z.im);
11}11}
1212
13test "onj" {13test conj {
14 const a = Complex(f32).init(5, 3);14 const a = Complex(f32).init(5, 3);
15 const c = a.conjugate();15 const c = a.conjugate();
1616
lib/std/math/complex/cos.zig+1-1
...@@ -13,7 +13,7 @@ pub fn cos(z: anytype) Complex(@TypeOf(z.re, z.im)) {...@@ -13,7 +13,7 @@ pub fn cos(z: anytype) Complex(@TypeOf(z.re, z.im)) {
1313
14const epsilon = 0.0001;14const epsilon = 0.0001;
1515
16test "cos" {16test cos {
17 const a = Complex(f32).init(5, 3);17 const a = Complex(f32).init(5, 3);
18 const c = cos(a);18 const c = cos(a);
1919
lib/std/math/complex/cosh.zig+2-2
...@@ -155,7 +155,7 @@ fn cosh64(z: Complex(f64)) Complex(f64) {...@@ -155,7 +155,7 @@ fn cosh64(z: Complex(f64)) Complex(f64) {
155155
156const epsilon = 0.0001;156const epsilon = 0.0001;
157157
158test "cosh32" {158test cosh32 {
159 const a = Complex(f32).init(5, 3);159 const a = Complex(f32).init(5, 3);
160 const c = cosh(a);160 const c = cosh(a);
161161
...@@ -163,7 +163,7 @@ test "cosh32" {...@@ -163,7 +163,7 @@ test "cosh32" {
163 try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));163 try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
164}164}
165165
166test "cosh64" {166test cosh64 {
167 const a = Complex(f64).init(5, 3);167 const a = Complex(f64).init(5, 3);
168 const c = cosh(a);168 const c = cosh(a);
169169
lib/std/math/complex/exp.zig+2-2
...@@ -119,7 +119,7 @@ fn exp64(z: Complex(f64)) Complex(f64) {...@@ -119,7 +119,7 @@ fn exp64(z: Complex(f64)) Complex(f64) {
119 }119 }
120}120}
121121
122test "exp32" {122test exp32 {
123 const tolerance_f32 = @sqrt(math.floatEps(f32));123 const tolerance_f32 = @sqrt(math.floatEps(f32));
124124
125 {125 {
...@@ -139,7 +139,7 @@ test "exp32" {...@@ -139,7 +139,7 @@ test "exp32" {
139 }139 }
140}140}
141141
142test "exp64" {142test exp64 {
143 const tolerance_f64 = @sqrt(math.floatEps(f64));143 const tolerance_f64 = @sqrt(math.floatEps(f64));
144144
145 {145 {
lib/std/math/complex/log.zig+1-1
...@@ -15,7 +15,7 @@ pub fn log(z: anytype) Complex(@TypeOf(z.re, z.im)) {...@@ -15,7 +15,7 @@ pub fn log(z: anytype) Complex(@TypeOf(z.re, z.im)) {
1515
16const epsilon = 0.0001;16const epsilon = 0.0001;
1717
18test "log" {18test log {
19 const a = Complex(f32).init(5, 3);19 const a = Complex(f32).init(5, 3);
20 const c = log(a);20 const c = log(a);
2121
lib/std/math/complex/pow.zig+1-1
...@@ -11,7 +11,7 @@ pub fn pow(z: anytype, s: anytype) Complex(@TypeOf(z.re, z.im, s.re, s.im)) {...@@ -11,7 +11,7 @@ pub fn pow(z: anytype, s: anytype) Complex(@TypeOf(z.re, z.im, s.re, s.im)) {
1111
12const epsilon = 0.0001;12const epsilon = 0.0001;
1313
14test "pow" {14test pow {
15 const a = Complex(f32).init(5, 3);15 const a = Complex(f32).init(5, 3);
16 const b = Complex(f32).init(2.3, -1.3);16 const b = Complex(f32).init(2.3, -1.3);
17 const c = pow(a, b);17 const c = pow(a, b);
lib/std/math/complex/proj.zig+1-3
...@@ -15,9 +15,7 @@ pub fn proj(z: anytype) Complex(@TypeOf(z.re, z.im)) {...@@ -15,9 +15,7 @@ pub fn proj(z: anytype) Complex(@TypeOf(z.re, z.im)) {
15 return Complex(T).init(z.re, z.im);15 return Complex(T).init(z.re, z.im);
16}16}
1717
18const epsilon = 0.0001;18test proj {
19
20test "proj" {
21 const a = Complex(f32).init(5, 3);19 const a = Complex(f32).init(5, 3);
22 const c = proj(a);20 const c = proj(a);
2321
lib/std/math/complex/sin.zig+1-1
...@@ -14,7 +14,7 @@ pub fn sin(z: anytype) Complex(@TypeOf(z.re, z.im)) {...@@ -14,7 +14,7 @@ pub fn sin(z: anytype) Complex(@TypeOf(z.re, z.im)) {
1414
15const epsilon = 0.0001;15const epsilon = 0.0001;
1616
17test "sin" {17test sin {
18 const a = Complex(f32).init(5, 3);18 const a = Complex(f32).init(5, 3);
19 const c = sin(a);19 const c = sin(a);
2020
lib/std/math/complex/sinh.zig+2-2
...@@ -154,7 +154,7 @@ fn sinh64(z: Complex(f64)) Complex(f64) {...@@ -154,7 +154,7 @@ fn sinh64(z: Complex(f64)) Complex(f64) {
154154
155const epsilon = 0.0001;155const epsilon = 0.0001;
156156
157test "sinh32" {157test sinh32 {
158 const a = Complex(f32).init(5, 3);158 const a = Complex(f32).init(5, 3);
159 const c = sinh(a);159 const c = sinh(a);
160160
...@@ -162,7 +162,7 @@ test "sinh32" {...@@ -162,7 +162,7 @@ test "sinh32" {
162 try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));162 try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
163}163}
164164
165test "sinh64" {165test sinh64 {
166 const a = Complex(f64).init(5, 3);166 const a = Complex(f64).init(5, 3);
167 const c = sinh(a);167 const c = sinh(a);
168168
lib/std/math/complex/sqrt.zig+2-2
...@@ -129,7 +129,7 @@ fn sqrt64(z: Complex(f64)) Complex(f64) {...@@ -129,7 +129,7 @@ fn sqrt64(z: Complex(f64)) Complex(f64) {
129129
130const epsilon = 0.0001;130const epsilon = 0.0001;
131131
132test "sqrt32" {132test sqrt32 {
133 const a = Complex(f32).init(5, 3);133 const a = Complex(f32).init(5, 3);
134 const c = sqrt(a);134 const c = sqrt(a);
135135
...@@ -137,7 +137,7 @@ test "sqrt32" {...@@ -137,7 +137,7 @@ test "sqrt32" {
137 try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));137 try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
138}138}
139139
140test "sqrt64" {140test sqrt64 {
141 const a = Complex(f64).init(5, 3);141 const a = Complex(f64).init(5, 3);
142 const c = sqrt(a);142 const c = sqrt(a);
143143
lib/std/math/complex/tan.zig+1-1
...@@ -14,7 +14,7 @@ pub fn tan(z: anytype) Complex(@TypeOf(z.re, z.im)) {...@@ -14,7 +14,7 @@ pub fn tan(z: anytype) Complex(@TypeOf(z.re, z.im)) {
1414
15const epsilon = 0.0001;15const epsilon = 0.0001;
1616
17test "tan" {17test tan {
18 const a = Complex(f32).init(5, 3);18 const a = Complex(f32).init(5, 3);
19 const c = tan(a);19 const c = tan(a);
2020
lib/std/math/complex/tanh.zig+2-2
...@@ -103,7 +103,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {...@@ -103,7 +103,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
103103
104const epsilon = 0.0001;104const epsilon = 0.0001;
105105
106test "tanh32" {106test tanh32 {
107 const a = Complex(f32).init(5, 3);107 const a = Complex(f32).init(5, 3);
108 const c = tanh(a);108 const c = tanh(a);
109109
...@@ -111,7 +111,7 @@ test "tanh32" {...@@ -111,7 +111,7 @@ test "tanh32" {
111 try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));111 try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
112}112}
113113
114test "tanh64" {114test tanh64 {
115 const a = Complex(f64).init(5, 3);115 const a = Complex(f64).init(5, 3);
116 const c = tanh(a);116 const c = tanh(a);
117117
lib/std/math/cosh.zig+3-3
...@@ -86,12 +86,12 @@ fn cosh64(x: f64) f64 {...@@ -86,12 +86,12 @@ fn cosh64(x: f64) f64 {
86 return expo2(ax);86 return expo2(ax);
87}87}
8888
89test "cosh" {89test cosh {
90 try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));90 try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
91 try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));91 try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
92}92}
9393
94test "cosh32" {94test cosh32 {
95 const epsilon = 0.000001;95 const epsilon = 0.000001;
9696
97 try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));97 try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
...@@ -104,7 +104,7 @@ test "cosh32" {...@@ -104,7 +104,7 @@ test "cosh32" {
104 try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));104 try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
105}105}
106106
107test "cosh64" {107test cosh64 {
108 const epsilon = 0.000001;108 const epsilon = 0.000001;
109109
110 try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));110 try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
lib/std/math/expm1.zig+3-3
...@@ -286,12 +286,12 @@ fn expm1_64(x_: f64) f64 {...@@ -286,12 +286,12 @@ fn expm1_64(x_: f64) f64 {
286 }286 }
287}287}
288288
289test "exp1m" {289test expm1 {
290 try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));290 try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
291 try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));291 try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
292}292}
293293
294test "expm1_32" {294test expm1_32 {
295 const epsilon = 0.000001;295 const epsilon = 0.000001;
296296
297 try expect(math.isPositiveZero(expm1_32(0.0)));297 try expect(math.isPositiveZero(expm1_32(0.0)));
...@@ -301,7 +301,7 @@ test "expm1_32" {...@@ -301,7 +301,7 @@ test "expm1_32" {
301 try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));301 try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
302}302}
303303
304test "expm1_64" {304test expm1_64 {
305 const epsilon = 0.000001;305 const epsilon = 0.000001;
306306
307 try expect(math.isPositiveZero(expm1_64(0.0)));307 try expect(math.isPositiveZero(expm1_64(0.0)));
lib/std/math/float.zig+3-3
...@@ -132,7 +132,7 @@ test "float bits" {...@@ -132,7 +132,7 @@ test "float bits" {
132 }132 }
133}133}
134134
135test "inf" {135test inf {
136 const inf_u16: u16 = 0x7C00;136 const inf_u16: u16 = 0x7C00;
137 const inf_u32: u32 = 0x7F800000;137 const inf_u32: u32 = 0x7F800000;
138 const inf_u64: u64 = 0x7FF0000000000000;138 const inf_u64: u64 = 0x7FF0000000000000;
...@@ -145,7 +145,7 @@ test "inf" {...@@ -145,7 +145,7 @@ test "inf" {
145 try expectEqual(inf_u128, @as(u128, @bitCast(inf(f128))));145 try expectEqual(inf_u128, @as(u128, @bitCast(inf(f128))));
146}146}
147147
148test "nan" {148test nan {
149 const qnan_u16: u16 = 0x7E00;149 const qnan_u16: u16 = 0x7E00;
150 const qnan_u32: u32 = 0x7FC00000;150 const qnan_u32: u32 = 0x7FC00000;
151 const qnan_u64: u64 = 0x7FF8000000000000;151 const qnan_u64: u64 = 0x7FF8000000000000;
...@@ -158,7 +158,7 @@ test "nan" {...@@ -158,7 +158,7 @@ test "nan" {
158 try expectEqual(qnan_u128, @as(u128, @bitCast(nan(f128))));158 try expectEqual(qnan_u128, @as(u128, @bitCast(nan(f128))));
159}159}
160160
161test "snan" {161test snan {
162 // TODO: https://github.com/ziglang/zig/issues/14366162 // TODO: https://github.com/ziglang/zig/issues/14366
163 if (builtin.zig_backend == .stage2_llvm and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;163 if (builtin.zig_backend == .stage2_llvm and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
164164
lib/std/math/gamma.zig+2-2
...@@ -240,7 +240,7 @@ const expect = std.testing.expect;...@@ -240,7 +240,7 @@ const expect = std.testing.expect;
240const expectEqual = std.testing.expectEqual;240const expectEqual = std.testing.expectEqual;
241const expectApproxEqRel = std.testing.expectApproxEqRel;241const expectApproxEqRel = std.testing.expectApproxEqRel;
242242
243test "gamma" {243test gamma {
244 inline for (&.{ f32, f64 }) |T| {244 inline for (&.{ f32, f64 }) |T| {
245 const eps = @sqrt(std.math.floatEps(T));245 const eps = @sqrt(std.math.floatEps(T));
246 try expectApproxEqRel(@as(T, 120), gamma(T, 6), eps);246 try expectApproxEqRel(@as(T, 120), gamma(T, 6), eps);
...@@ -286,7 +286,7 @@ test "gamma.special" {...@@ -286,7 +286,7 @@ test "gamma.special" {
286 }286 }
287}287}
288288
289test "lgamma" {289test lgamma {
290 inline for (&.{ f32, f64 }) |T| {290 inline for (&.{ f32, f64 }) |T| {
291 const eps = @sqrt(std.math.floatEps(T));291 const eps = @sqrt(std.math.floatEps(T));
292 try expectApproxEqRel(@as(T, @log(24.0)), lgamma(T, 5), eps);292 try expectApproxEqRel(@as(T, @log(24.0)), lgamma(T, 5), eps);
lib/std/math/hypot.zig+3-3
...@@ -124,7 +124,7 @@ fn hypot64(x: f64, y: f64) f64 {...@@ -124,7 +124,7 @@ fn hypot64(x: f64, y: f64) f64 {
124 return z * @sqrt(ly + lx + hy + hx);124 return z * @sqrt(ly + lx + hy + hx);
125}125}
126126
127test "hypot" {127test hypot {
128 const x32: f32 = 0.0;128 const x32: f32 = 0.0;
129 const y32: f32 = -1.2;129 const y32: f32 = -1.2;
130 const x64: f64 = 0.0;130 const x64: f64 = 0.0;
...@@ -133,7 +133,7 @@ test "hypot" {...@@ -133,7 +133,7 @@ test "hypot" {
133 try expect(hypot(x64, y64) == hypot64(0.0, -1.2));133 try expect(hypot(x64, y64) == hypot64(0.0, -1.2));
134}134}
135135
136test "hypot32" {136test hypot32 {
137 const epsilon = 0.000001;137 const epsilon = 0.000001;
138138
139 try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));139 try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
...@@ -145,7 +145,7 @@ test "hypot32" {...@@ -145,7 +145,7 @@ test "hypot32" {
145 try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));145 try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
146}146}
147147
148test "hypot64" {148test hypot64 {
149 const epsilon = 0.000001;149 const epsilon = 0.000001;
150150
151 try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));151 try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));
lib/std/math/log1p.zig+3-3
...@@ -182,12 +182,12 @@ fn log1p_64(x: f64) f64 {...@@ -182,12 +182,12 @@ fn log1p_64(x: f64) f64 {
182 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;182 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
183}183}
184184
185test "log1p" {185test log1p {
186 try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));186 try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
187 try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));187 try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
188}188}
189189
190test "log1p_32" {190test log1p_32 {
191 const epsilon = 0.000001;191 const epsilon = 0.000001;
192192
193 try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));193 try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
...@@ -199,7 +199,7 @@ test "log1p_32" {...@@ -199,7 +199,7 @@ test "log1p_32" {
199 try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));199 try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
200}200}
201201
202test "log1p_64" {202test log1p_64 {
203 const epsilon = 0.000001;203 const epsilon = 0.000001;
204204
205 try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));205 try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
lib/std/math/log2.zig+1-1
...@@ -42,7 +42,7 @@ pub fn log2(x: anytype) @TypeOf(x) {...@@ -42,7 +42,7 @@ pub fn log2(x: anytype) @TypeOf(x) {
42 }42 }
43}43}
4444
45test "log2" {45test log2 {
46 // https://github.com/ziglang/zig/issues/1370346 // https://github.com/ziglang/zig/issues/13703
47 if (builtin.cpu.arch == .aarch64 and builtin.os.tag == .windows) return error.SkipZigTest;47 if (builtin.cpu.arch == .aarch64 and builtin.os.tag == .windows) return error.SkipZigTest;
4848
lib/std/math/modf.zig+3-3
...@@ -123,14 +123,14 @@ fn modf64(x: f64) modf64_result {...@@ -123,14 +123,14 @@ fn modf64(x: f64) modf64_result {
123 return result;123 return result;
124}124}
125125
126test "modf" {126test modf {
127 const a = modf(@as(f32, 1.0));127 const a = modf(@as(f32, 1.0));
128 const b = modf32(1.0);128 const b = modf32(1.0);
129 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.129 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
130 try expectEqual(a, b);130 try expectEqual(a, b);
131}131}
132132
133test "modf32" {133test modf32 {
134 const epsilon = 0.000001;134 const epsilon = 0.000001;
135 var r: modf32_result = undefined;135 var r: modf32_result = undefined;
136136
...@@ -155,7 +155,7 @@ test "modf32" {...@@ -155,7 +155,7 @@ test "modf32" {
155 try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));155 try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
156}156}
157157
158test "modf64" {158test modf64 {
159 const epsilon = 0.000001;159 const epsilon = 0.000001;
160 var r: modf64_result = undefined;160 var r: modf64_result = undefined;
161161
lib/std/math/powi.zig+1-1
...@@ -91,7 +91,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{...@@ -91,7 +91,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
91 return acc;91 return acc;
92}92}
9393
94test "powi" {94test powi {
95 try testing.expectError(error.Overflow, powi(i8, -66, 6));95 try testing.expectError(error.Overflow, powi(i8, -66, 6));
96 try testing.expectError(error.Overflow, powi(i16, -13, 13));96 try testing.expectError(error.Overflow, powi(i16, -13, 13));
97 try testing.expectError(error.Overflow, powi(i32, -32, 21));97 try testing.expectError(error.Overflow, powi(i32, -32, 21));
lib/std/math/sinh.zig+3-3
...@@ -91,12 +91,12 @@ fn sinh64(x: f64) f64 {...@@ -91,12 +91,12 @@ fn sinh64(x: f64) f64 {
91 return 2 * h * expo2(ax);91 return 2 * h * expo2(ax);
92}92}
9393
94test "sinh" {94test sinh {
95 try expect(sinh(@as(f32, 1.5)) == sinh32(1.5));95 try expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
96 try expect(sinh(@as(f64, 1.5)) == sinh64(1.5));96 try expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
97}97}
9898
99test "sinh32" {99test sinh32 {
100 const epsilon = 0.000001;100 const epsilon = 0.000001;
101101
102 try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));102 try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
...@@ -109,7 +109,7 @@ test "sinh32" {...@@ -109,7 +109,7 @@ test "sinh32" {
109 try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));109 try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
110}110}
111111
112test "sinh64" {112test sinh64 {
113 const epsilon = 0.000001;113 const epsilon = 0.000001;
114114
115 try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));115 try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
lib/std/math/tanh.zig+3-3
...@@ -104,12 +104,12 @@ fn tanh64(x: f64) f64 {...@@ -104,12 +104,12 @@ fn tanh64(x: f64) f64 {
104 return if (sign) -t else t;104 return if (sign) -t else t;
105}105}
106106
107test "tanh" {107test tanh {
108 try expect(tanh(@as(f32, 1.5)) == tanh32(1.5));108 try expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
109 try expect(tanh(@as(f64, 1.5)) == tanh64(1.5));109 try expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
110}110}
111111
112test "tanh32" {112test tanh32 {
113 const epsilon = 0.000001;113 const epsilon = 0.000001;
114114
115 try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));115 try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
...@@ -122,7 +122,7 @@ test "tanh32" {...@@ -122,7 +122,7 @@ test "tanh32" {
122 try expect(math.approxEqAbs(f32, tanh32(-37.45), -1.0, epsilon));122 try expect(math.approxEqAbs(f32, tanh32(-37.45), -1.0, epsilon));
123}123}
124124
125test "tanh64" {125test tanh64 {
126 const epsilon = 0.000001;126 const epsilon = 0.000001;
127127
128 try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));128 try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
lib/std/meta.zig+26-26
...@@ -46,7 +46,7 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T {...@@ -46,7 +46,7 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
46 }46 }
47}47}
4848
49test "stringToEnum" {49test stringToEnum {
50 const E1 = enum {50 const E1 = enum {
51 A,51 A,
52 B,52 B,
...@@ -73,7 +73,7 @@ pub fn alignment(comptime T: type) comptime_int {...@@ -73,7 +73,7 @@ pub fn alignment(comptime T: type) comptime_int {
73 };73 };
74}74}
7575
76test "alignment" {76test alignment {
77 try testing.expect(alignment(u8) == 1);77 try testing.expect(alignment(u8) == 1);
78 try testing.expect(alignment(*align(1) u8) == 1);78 try testing.expect(alignment(*align(1) u8) == 1);
79 try testing.expect(alignment(*align(2) u8) == 2);79 try testing.expect(alignment(*align(2) u8) == 2);
...@@ -94,7 +94,7 @@ pub fn Child(comptime T: type) type {...@@ -94,7 +94,7 @@ pub fn Child(comptime T: type) type {
94 };94 };
95}95}
9696
97test "Child" {97test Child {
98 try testing.expect(Child([1]u8) == u8);98 try testing.expect(Child([1]u8) == u8);
99 try testing.expect(Child(*u8) == u8);99 try testing.expect(Child(*u8) == u8);
100 try testing.expect(Child([]u8) == u8);100 try testing.expect(Child([]u8) == u8);
...@@ -121,7 +121,7 @@ pub fn Elem(comptime T: type) type {...@@ -121,7 +121,7 @@ pub fn Elem(comptime T: type) type {
121 @compileError("Expected pointer, slice, array or vector type, found '" ++ @typeName(T) ++ "'");121 @compileError("Expected pointer, slice, array or vector type, found '" ++ @typeName(T) ++ "'");
122}122}
123123
124test "Elem" {124test Elem {
125 try testing.expect(Elem([1]u8) == u8);125 try testing.expect(Elem([1]u8) == u8);
126 try testing.expect(Elem([*]u8) == u8);126 try testing.expect(Elem([*]u8) == u8);
127 try testing.expect(Elem([]u8) == u8);127 try testing.expect(Elem([]u8) == u8);
...@@ -255,7 +255,7 @@ pub fn containerLayout(comptime T: type) Type.ContainerLayout {...@@ -255,7 +255,7 @@ pub fn containerLayout(comptime T: type) Type.ContainerLayout {
255 };255 };
256}256}
257257
258test "containerLayout" {258test containerLayout {
259 const S1 = struct {};259 const S1 = struct {};
260 const S2 = packed struct {};260 const S2 = packed struct {};
261 const S3 = extern struct {};261 const S3 = extern struct {};
...@@ -289,7 +289,7 @@ pub fn declarations(comptime T: type) []const Type.Declaration {...@@ -289,7 +289,7 @@ pub fn declarations(comptime T: type) []const Type.Declaration {
289 };289 };
290}290}
291291
292test "declarations" {292test declarations {
293 const E1 = enum {293 const E1 = enum {
294 A,294 A,
295295
...@@ -329,7 +329,7 @@ pub fn declarationInfo(comptime T: type, comptime decl_name: []const u8) Type.De...@@ -329,7 +329,7 @@ pub fn declarationInfo(comptime T: type, comptime decl_name: []const u8) Type.De
329 @compileError("'" ++ @typeName(T) ++ "' has no declaration '" ++ decl_name ++ "'");329 @compileError("'" ++ @typeName(T) ++ "' has no declaration '" ++ decl_name ++ "'");
330}330}
331331
332test "declarationInfo" {332test declarationInfo {
333 const E1 = enum {333 const E1 = enum {
334 A,334 A,
335335
...@@ -370,7 +370,7 @@ pub fn fields(comptime T: type) switch (@typeInfo(T)) {...@@ -370,7 +370,7 @@ pub fn fields(comptime T: type) switch (@typeInfo(T)) {
370 };370 };
371}371}
372372
373test "fields" {373test fields {
374 const E1 = enum {374 const E1 = enum {
375 A,375 A,
376 };376 };
...@@ -409,7 +409,7 @@ pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeIn...@@ -409,7 +409,7 @@ pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeIn
409 return fields(T)[@intFromEnum(field)];409 return fields(T)[@intFromEnum(field)];
410}410}
411411
412test "fieldInfo" {412test fieldInfo {
413 const E1 = enum {413 const E1 = enum {
414 A,414 A,
415 };415 };
...@@ -442,7 +442,7 @@ pub fn FieldType(comptime T: type, comptime field: FieldEnum(T)) type {...@@ -442,7 +442,7 @@ pub fn FieldType(comptime T: type, comptime field: FieldEnum(T)) type {
442 return fieldInfo(T, field).type;442 return fieldInfo(T, field).type;
443}443}
444444
445test "FieldType" {445test FieldType {
446 const S = struct {446 const S = struct {
447 a: u8,447 a: u8,
448 b: u16,448 b: u16,
...@@ -470,7 +470,7 @@ pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 {...@@ -470,7 +470,7 @@ pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 {
470 };470 };
471}471}
472472
473test "fieldNames" {473test fieldNames {
474 const E1 = enum { A, B };474 const E1 = enum { A, B };
475 const E2 = error{A};475 const E2 = error{A};
476 const S1 = struct {476 const S1 = struct {
...@@ -511,7 +511,7 @@ pub fn tags(comptime T: type) *const [fields(T).len]T {...@@ -511,7 +511,7 @@ pub fn tags(comptime T: type) *const [fields(T).len]T {
511 };511 };
512}512}
513513
514test "tags" {514test tags {
515 const E1 = enum { A, B };515 const E1 = enum { A, B };
516 const E2 = error{A};516 const E2 = error{A};
517517
...@@ -604,7 +604,7 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {...@@ -604,7 +604,7 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
604 );604 );
605}605}
606606
607test "FieldEnum" {607test FieldEnum {
608 try expectEqualEnum(enum {}, FieldEnum(struct {}));608 try expectEqualEnum(enum {}, FieldEnum(struct {}));
609 try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));609 try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
610 try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));610 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 {...@@ -639,7 +639,7 @@ pub fn DeclEnum(comptime T: type) type {
639 });639 });
640}640}
641641
642test "DeclEnum" {642test DeclEnum {
643 const A = struct {643 const A = struct {
644 pub const a: u8 = 0;644 pub const a: u8 = 0;
645 };645 };
...@@ -670,7 +670,7 @@ pub fn Tag(comptime T: type) type {...@@ -670,7 +670,7 @@ pub fn Tag(comptime T: type) type {
670 };670 };
671}671}
672672
673test "Tag" {673test Tag {
674 const E = enum(u8) {674 const E = enum(u8) {
675 C = 33,675 C = 33,
676 D,676 D,
...@@ -690,7 +690,7 @@ pub fn activeTag(u: anytype) Tag(@TypeOf(u)) {...@@ -690,7 +690,7 @@ pub fn activeTag(u: anytype) Tag(@TypeOf(u)) {
690 return @as(Tag(T), u);690 return @as(Tag(T), u);
691}691}
692692
693test "activeTag" {693test activeTag {
694 const UE = enum {694 const UE = enum {
695 Int,695 Int,
696 Float,696 Float,
...@@ -727,7 +727,7 @@ pub fn TagPayload(comptime U: type, comptime tag: Tag(U)) type {...@@ -727,7 +727,7 @@ pub fn TagPayload(comptime U: type, comptime tag: Tag(U)) type {
727 return TagPayloadByName(U, @tagName(tag));727 return TagPayloadByName(U, @tagName(tag));
728}728}
729729
730test "TagPayload" {730test TagPayload {
731 const Event = union(enum) {731 const Event = union(enum) {
732 Moved: struct {732 Moved: struct {
733 from: i32,733 from: i32,
...@@ -802,7 +802,7 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {...@@ -802,7 +802,7 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {
802 }802 }
803}803}
804804
805test "eql" {805test eql {
806 const S = struct {806 const S = struct {
807 a: u32,807 a: u32,
808 b: f64,808 b: f64,
...@@ -863,7 +863,7 @@ test "eql" {...@@ -863,7 +863,7 @@ test "eql" {
863 try testing.expect(!eql(v1, v3));863 try testing.expect(!eql(v1, v3));
864}864}
865865
866test "intToEnum with error return" {866test intToEnum {
867 const E1 = enum {867 const E1 = enum {
868 A,868 A,
869 };869 };
...@@ -965,7 +965,7 @@ pub fn Float(comptime bit_count: u8) type {...@@ -965,7 +965,7 @@ pub fn Float(comptime bit_count: u8) type {
965 });965 });
966}966}
967967
968test "Float" {968test Float {
969 try testing.expectEqual(f16, Float(16));969 try testing.expectEqual(f16, Float(16));
970 try testing.expectEqual(f32, Float(32));970 try testing.expectEqual(f32, Float(32));
971 try testing.expectEqual(f64, Float(64));971 try testing.expectEqual(f64, Float(64));
...@@ -1057,7 +1057,7 @@ const TupleTester = struct {...@@ -1057,7 +1057,7 @@ const TupleTester = struct {
1057 }1057 }
1058};1058};
10591059
1060test "ArgsTuple" {1060test ArgsTuple {
1061 TupleTester.assertTuple(.{}, ArgsTuple(fn () void));1061 TupleTester.assertTuple(.{}, ArgsTuple(fn () void));
1062 TupleTester.assertTuple(.{u32}, ArgsTuple(fn (a: u32) []const u8));1062 TupleTester.assertTuple(.{u32}, ArgsTuple(fn (a: u32) []const u8));
1063 TupleTester.assertTuple(.{ u32, f16 }, ArgsTuple(fn (a: u32, b: f16) noreturn));1063 TupleTester.assertTuple(.{ u32, f16 }, ArgsTuple(fn (a: u32, b: f16) noreturn));
...@@ -1065,7 +1065,7 @@ test "ArgsTuple" {...@@ -1065,7 +1065,7 @@ test "ArgsTuple" {
1065 TupleTester.assertTuple(.{u32}, ArgsTuple(fn (comptime a: u32) []const u8));1065 TupleTester.assertTuple(.{u32}, ArgsTuple(fn (comptime a: u32) []const u8));
1066}1066}
10671067
1068test "Tuple" {1068test Tuple {
1069 TupleTester.assertTuple(.{}, Tuple(&[_]type{}));1069 TupleTester.assertTuple(.{}, Tuple(&[_]type{}));
1070 TupleTester.assertTuple(.{u32}, Tuple(&[_]type{u32}));1070 TupleTester.assertTuple(.{u32}, Tuple(&[_]type{u32}));
1071 TupleTester.assertTuple(.{ u32, f16 }, Tuple(&[_]type{ u32, f16 }));1071 TupleTester.assertTuple(.{ u32, f16 }, Tuple(&[_]type{ u32, f16 }));
...@@ -1103,7 +1103,7 @@ pub fn isError(error_union: anytype) bool {...@@ -1103,7 +1103,7 @@ pub fn isError(error_union: anytype) bool {
1103 return if (error_union) |_| false else |_| true;1103 return if (error_union) |_| false else |_| true;
1104}1104}
11051105
1106test "isError" {1106test isError {
1107 try std.testing.expect(isError(math.divTrunc(u8, 5, 0)));1107 try std.testing.expect(isError(math.divTrunc(u8, 5, 0)));
1108 try std.testing.expect(!isError(math.divTrunc(u8, 5, 5)));1108 try std.testing.expect(!isError(math.divTrunc(u8, 5, 5)));
1109}1109}
...@@ -1121,7 +1121,7 @@ pub inline fn hasFn(comptime T: type, comptime name: []const u8) bool {...@@ -1121,7 +1121,7 @@ pub inline fn hasFn(comptime T: type, comptime name: []const u8) bool {
1121 return @typeInfo(@TypeOf(@field(T, name))) == .Fn;1121 return @typeInfo(@TypeOf(@field(T, name))) == .Fn;
1122}1122}
11231123
1124test "hasFn" {1124test hasFn {
1125 const S1 = struct {1125 const S1 = struct {
1126 pub fn foo() void {}1126 pub fn foo() void {}
1127 };1127 };
...@@ -1149,7 +1149,7 @@ pub inline fn hasMethod(comptime T: type, comptime name: []const u8) bool {...@@ -1149,7 +1149,7 @@ pub inline fn hasMethod(comptime T: type, comptime name: []const u8) bool {
1149 };1149 };
1150}1150}
11511151
1152test "hasMethod" {1152test hasMethod {
1153 try std.testing.expect(!hasMethod(u32, "foo"));1153 try std.testing.expect(!hasMethod(u32, "foo"));
1154 try std.testing.expect(!hasMethod([]u32, "len"));1154 try std.testing.expect(!hasMethod([]u32, "len"));
1155 try std.testing.expect(!hasMethod(struct { u32, u64 }, "len"));1155 try std.testing.expect(!hasMethod(struct { u32, u64 }, "len"));
...@@ -1218,7 +1218,7 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {...@@ -1218,7 +1218,7 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
1218 };1218 };
1219}1219}
12201220
1221test "hasUniqueRepresentation" {1221test hasUniqueRepresentation {
1222 const TestStruct1 = struct {1222 const TestStruct1 = struct {
1223 a: u32,1223 a: u32,
1224 b: u32,1224 b: u32,