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" {
201201 }
202202}
203203
204test "fill" {
204test fill {
205205 var r = Isaac64.init(0);
206206
207207 // from reference implementation
lib/std/Random/Pcg.zig+1-1
......@@ -92,7 +92,7 @@ test "sequence" {
9292 }
9393}
9494
95test "fill" {
95test fill {
9696 var r = Pcg.init(0);
9797 const s0: u64 = 0x9394bf54ce5d79de;
9898 const s1: u64 = 0x84e9c579ef59bbf7;
lib/std/Random/RomuTrio.zig+1-1
......@@ -94,7 +94,7 @@ test "sequence" {
9494 }
9595}
9696
97test "fill" {
97test fill {
9898 // Unfortunately there does not seem to be an official test sequence.
9999 var r = RomuTrio.init(0);
100100
lib/std/Random/Sfc64.zig+1-1
......@@ -98,7 +98,7 @@ test "sequence" {
9898 }
9999}
100100
101test "fill" {
101test fill {
102102 // Unfortunately there does not seem to be an official test sequence.
103103 var r = Sfc64.init(0);
104104
lib/std/Random/Xoroshiro128.zig+1-1
......@@ -122,7 +122,7 @@ test "sequence" {
122122 }
123123}
124124
125test "fill" {
125test fill {
126126 var r = Xoroshiro128.init(0);
127127 r.s[0] = 0xaeecf86f7878dd75;
128128 r.s[1] = 0x01cd153642e72622;
lib/std/Random/Xoshiro256.zig+1-1
......@@ -122,7 +122,7 @@ test "sequence" {
122122 }
123123}
124124
125test "fill" {
125test fill {
126126 var r = Xoshiro256.init(0);
127127
128128 const seq = [_]u64{
lib/std/SemanticVersion.zig+1-1
......@@ -166,7 +166,7 @@ pub fn format(
166166const expect = std.testing.expect;
167167const expectError = std.testing.expectError;
168168
169test "format" {
169test format {
170170 // Many of these test strings are from https://github.com/semver/semver.org/issues/59#issuecomment-390854010.
171171
172172 // Valid version strings should be accepted.
lib/std/Thread.zig+2-2
......@@ -1437,7 +1437,7 @@ fn testIncrementNotify(value: *usize, event: *ResetEvent) void {
14371437 event.set();
14381438}
14391439
1440test "join" {
1440test join {
14411441 if (builtin.single_threaded) return error.SkipZigTest;
14421442
14431443 var value: usize = 0;
......@@ -1449,7 +1449,7 @@ test "join" {
14491449 try std.testing.expectEqual(value, 1);
14501450}
14511451
1452test "detach" {
1452test detach {
14531453 if (builtin.single_threaded) return error.SkipZigTest;
14541454
14551455 var value: usize = 0;
lib/std/Thread/Condition.zig+2-2
......@@ -362,7 +362,7 @@ test "wait and signal" {
362362 }
363363}
364364
365test "signal" {
365test signal {
366366 // This test requires spawning threads
367367 if (builtin.single_threaded) {
368368 return error.SkipZigTest;
......@@ -491,7 +491,7 @@ test "multi signal" {
491491 }
492492}
493493
494test "broadcasting" {
494test broadcast {
495495 // This test requires spawning threads
496496 if (builtin.single_threaded) {
497497 return error.SkipZigTest;
lib/std/Thread/Semaphore.zig+2-2
......@@ -71,7 +71,7 @@ pub fn post(sem: *Semaphore) void {
7171 sem.cond.signal();
7272}
7373
74test "Semaphore" {
74test Semaphore {
7575 if (builtin.single_threaded) {
7676 return error.SkipZigTest;
7777 }
......@@ -97,7 +97,7 @@ test "Semaphore" {
9797 try testing.expect(n == num_threads);
9898}
9999
100test "timedWait" {
100test timedWait {
101101 var sem = Semaphore{};
102102 try testing.expectEqual(0, sem.permits);
103103
lib/std/buf_set.zig+17-17
......@@ -90,6 +90,23 @@ pub const BufSet = struct {
9090 return self.cloneWithAllocator(self.allocator());
9191 }
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
93110 fn free(self: *const BufSet, value: []const u8) void {
94111 self.hash_map.allocator.free(value);
95112 }
......@@ -115,23 +132,6 @@ test BufSet {
115132 try bufset.insert("z");
116133}
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
135135test "clone with arena" {
136136 const allocator = std.testing.allocator;
137137 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 {
130130}
131131
132132// example from: https://youtu.be/SJPvNi4HrWQ?t=3558
133test "writeMatch" {
133test writeMatch {
134134 var cb: Self = .{};
135135
136136 cb.writeAll("a salad; ");
......@@ -150,7 +150,7 @@ test "writeMatch overlap" {
150150 try testing.expectEqualStrings("a b c b c b c d", cb.read());
151151}
152152
153test "readAtMost" {
153test readAtMost {
154154 var cb: Self = .{};
155155
156156 cb.writeAll("0123456789");
......@@ -165,7 +165,7 @@ test "readAtMost" {
165165 try testing.expectEqualStrings("", cb.read());
166166}
167167
168test "CircularBuffer" {
168test Self {
169169 var cb: Self = .{};
170170
171171 const data = "0123456789abcdef" ** (1024 / 16);
lib/std/compress/flate/Lookup.zig+2-2
......@@ -83,7 +83,7 @@ fn hashu(v: u32) u32 {
8383 return @intCast((v *% prime4) >> consts.lookup.shift);
8484}
8585
86test "add/prev" {
86test add {
8787 const data = [_]u8{
8888 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
8989 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
......@@ -107,7 +107,7 @@ test "add/prev" {
107107 try expect(h.chain[2 + 8] == 2);
108108}
109109
110test "bulkAdd" {
110test bulkAdd {
111111 const data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
112112
113113 // one by one
lib/std/compress/flate/SlidingWindow.zig+2-2
......@@ -122,7 +122,7 @@ pub fn tokensBuffer(self: *Self) ?[]const u8 {
122122 return self.buffer[@intCast(self.fp)..self.rp];
123123}
124124
125test "match" {
125test match {
126126 const data = "Blah blah blah blah blah!";
127127 var win: Self = .{};
128128 try expect(win.write(data) == data.len);
......@@ -142,7 +142,7 @@ test "match" {
142142 try expect(win.match(15, 20, 4) == 0);
143143}
144144
145test "slide" {
145test slide {
146146 var win: Self = .{};
147147 win.wp = Self.buffer_len - 11;
148148 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 {
458458 return r >> @as(math.Log2Int(T), @intCast(@typeInfo(T).Int.bits - n));
459459}
460460
461test "bitReverse" {
461test bitReverse {
462462 const ReverseBitsTest = struct {
463463 in: u16,
464464 bit_count: u5,
lib/std/enums.zig+6-6
......@@ -120,7 +120,7 @@ pub fn directEnumArray(
120120 return directEnumArrayDefault(E, Data, null, max_unused_slots, init_values);
121121}
122122
123test "directEnumArray" {
123test directEnumArray {
124124 const E = enum(i4) { a = 4, b = 6, c = 2 };
125125 var runtime_false: bool = false;
126126 _ = &runtime_false;
......@@ -163,7 +163,7 @@ pub fn directEnumArrayDefault(
163163 return result;
164164}
165165
166test "directEnumArrayDefault" {
166test directEnumArrayDefault {
167167 const E = enum(i4) { a = 4, b = 6, c = 2 };
168168 var runtime_false: bool = false;
169169 _ = &runtime_false;
......@@ -214,7 +214,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
214214 };
215215}
216216
217test "nameCast" {
217test nameCast {
218218 const A = enum(u1) { a = 0, b = 1 };
219219 const B = enum(u1) { a = 1, b = 0 };
220220 try testing.expectEqual(A.a, nameCast(A, .a));
......@@ -515,7 +515,7 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
515515 };
516516}
517517
518test "EnumMultiset" {
518test EnumMultiset {
519519 const Ball = enum { red, green, blue };
520520
521521 const empty = EnumMultiset(Ball).initEmpty();
......@@ -1298,7 +1298,7 @@ pub fn ensureIndexer(comptime T: type) void {
12981298 }
12991299}
13001300
1301test "ensureIndexer" {
1301test ensureIndexer {
13021302 ensureIndexer(struct {
13031303 pub const Key = u32;
13041304 pub const count: comptime_int = 8;
......@@ -1535,7 +1535,7 @@ test "EnumIndexer empty" {
15351535 try testing.expectEqual(0, Indexer.count);
15361536}
15371537
1538test "enumValues" {
1538test values {
15391539 const E = enum {
15401540 X,
15411541 Y,
lib/std/math/acos.zig+3-3
......@@ -148,12 +148,12 @@ fn acos64(x: f64) f64 {
148148 return 2 * (df + w);
149149}
150150
151test "acos" {
151test acos {
152152 try expect(acos(@as(f32, 0.0)) == acos32(0.0));
153153 try expect(acos(@as(f64, 0.0)) == acos64(0.0));
154154}
155155
156test "acos32" {
156test acos32 {
157157 const epsilon = 0.000001;
158158
159159 try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
......@@ -164,7 +164,7 @@ test "acos32" {
164164 try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
165165}
166166
167test "acos64" {
167test acos64 {
168168 const epsilon = 0.000001;
169169
170170 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 {
5959 }
6060}
6161
62test "acosh" {
62test acosh {
6363 try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
6464 try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
6565}
6666
67test "acosh32" {
67test acosh32 {
6868 const epsilon = 0.000001;
6969
7070 try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
......@@ -73,7 +73,7 @@ test "acosh32" {
7373 try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
7474}
7575
76test "acosh64" {
76test acosh64 {
7777 const epsilon = 0.000001;
7878
7979 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 {
141141 }
142142}
143143
144test "asin" {
144test asin {
145145 try expect(asin(@as(f32, 0.0)) == asin32(0.0));
146146 try expect(asin(@as(f64, 0.0)) == asin64(0.0));
147147}
148148
149test "asin32" {
149test asin32 {
150150 const epsilon = 0.000001;
151151
152152 try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
......@@ -157,7 +157,7 @@ test "asin32" {
157157 try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
158158}
159159
160test "asin64" {
160test asin64 {
161161 const epsilon = 0.000001;
162162
163163 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 {
8080 return if (s != 0) -rx else rx;
8181}
8282
83test "asinh" {
83test asinh {
8484 try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
8585 try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
8686}
8787
88test "asinh32" {
88test asinh32 {
8989 const epsilon = 0.000001;
9090
9191 try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
......@@ -98,7 +98,7 @@ test "asinh32" {
9898 try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
9999}
100100
101test "asinh64" {
101test asinh64 {
102102 const epsilon = 0.000001;
103103
104104 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 {
212212 }
213213}
214214
215test "atan" {
215test atan {
216216 try expect(@as(u32, @bitCast(atan(@as(f32, 0.2)))) == @as(u32, @bitCast(atan32(0.2))));
217217 try expect(atan(@as(f64, 0.2)) == atan64(0.2));
218218}
219219
220test "atan32" {
220test atan32 {
221221 const epsilon = 0.000001;
222222
223223 try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
......@@ -227,7 +227,7 @@ test "atan32" {
227227 try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
228228}
229229
230test "atan64" {
230test atan64 {
231231 const epsilon = 0.000001;
232232
233233 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 {
214214 }
215215}
216216
217test "atan2" {
217test atan2 {
218218 const y32: f32 = 0.2;
219219 const x32: f32 = 0.21;
220220 const y64: f64 = 0.2;
......@@ -223,7 +223,7 @@ test "atan2" {
223223 try expect(atan2(y64, x64) == atan2_64(0.2, 0.21));
224224}
225225
226test "atan2_32" {
226test atan2_32 {
227227 const epsilon = 0.000001;
228228
229229 try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
......@@ -235,7 +235,7 @@ test "atan2_32" {
235235 try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
236236}
237237
238test "atan2_64" {
238test atan2_64 {
239239 const epsilon = 0.000001;
240240
241241 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 {
8484 return if (s != 0) -y else y;
8585}
8686
87test "atanh" {
87test atanh {
8888 try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
8989 try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
9090}
9191
92test "atanh_32" {
92test atanh_32 {
9393 const epsilon = 0.000001;
9494
9595 try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
......@@ -97,7 +97,7 @@ test "atanh_32" {
9797 try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
9898}
9999
100test "atanh_64" {
100test atanh_64 {
101101 const epsilon = 0.000001;
102102
103103 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 {
493493 }
494494}
495495
496test "extractLowBits" {
496test extractLowBits {
497497 var a = try Int.initSet(testing.allocator, 0x11112222333344441234567887654321);
498498 defer a.deinit();
499499
lib/std/math/cbrt.zig+3-3
......@@ -119,12 +119,12 @@ fn cbrt64(x: f64) f64 {
119119 return t + t * q;
120120}
121121
122test "cbrt" {
122test cbrt {
123123 try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
124124 try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
125125}
126126
127test "cbrt32" {
127test cbrt32 {
128128 const epsilon = 0.000001;
129129
130130 try expect(math.isPositiveZero(cbrt32(0.0)));
......@@ -135,7 +135,7 @@ test "cbrt32" {
135135 try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
136136}
137137
138test "cbrt64" {
138test cbrt64 {
139139 const epsilon = 0.000001;
140140
141141 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) {
120120
121121const epsilon = 0.0001;
122122
123test "atan32" {
123test atan32 {
124124 const a = Complex(f32).init(5, 3);
125125 const c = atan(a);
126126
......@@ -128,7 +128,7 @@ test "atan32" {
128128 try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
129129}
130130
131test "atan64" {
131test atan64 {
132132 const a = Complex(f64).init(5, 3);
133133 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)) {
1414
1515const epsilon = 0.0001;
1616
17test "atanh" {
17test atanh {
1818 const a = Complex(f32).init(5, 3);
1919 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)) {
1010 return Complex(T).init(z.re, -z.im);
1111}
1212
13test "onj" {
13test conj {
1414 const a = Complex(f32).init(5, 3);
1515 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)) {
1313
1414const epsilon = 0.0001;
1515
16test "cos" {
16test cos {
1717 const a = Complex(f32).init(5, 3);
1818 const c = cos(a);
1919
lib/std/math/complex/cosh.zig+2-2
......@@ -155,7 +155,7 @@ fn cosh64(z: Complex(f64)) Complex(f64) {
155155
156156const epsilon = 0.0001;
157157
158test "cosh32" {
158test cosh32 {
159159 const a = Complex(f32).init(5, 3);
160160 const c = cosh(a);
161161
......@@ -163,7 +163,7 @@ test "cosh32" {
163163 try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
164164}
165165
166test "cosh64" {
166test cosh64 {
167167 const a = Complex(f64).init(5, 3);
168168 const c = cosh(a);
169169
lib/std/math/complex/exp.zig+2-2
......@@ -119,7 +119,7 @@ fn exp64(z: Complex(f64)) Complex(f64) {
119119 }
120120}
121121
122test "exp32" {
122test exp32 {
123123 const tolerance_f32 = @sqrt(math.floatEps(f32));
124124
125125 {
......@@ -139,7 +139,7 @@ test "exp32" {
139139 }
140140}
141141
142test "exp64" {
142test exp64 {
143143 const tolerance_f64 = @sqrt(math.floatEps(f64));
144144
145145 {
lib/std/math/complex/log.zig+1-1
......@@ -15,7 +15,7 @@ pub fn log(z: anytype) Complex(@TypeOf(z.re, z.im)) {
1515
1616const epsilon = 0.0001;
1717
18test "log" {
18test log {
1919 const a = Complex(f32).init(5, 3);
2020 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)) {
1111
1212const epsilon = 0.0001;
1313
14test "pow" {
14test pow {
1515 const a = Complex(f32).init(5, 3);
1616 const b = Complex(f32).init(2.3, -1.3);
1717 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)) {
1515 return Complex(T).init(z.re, z.im);
1616}
1717
18const epsilon = 0.0001;
19
20test "proj" {
18test proj {
2119 const a = Complex(f32).init(5, 3);
2220 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)) {
1414
1515const epsilon = 0.0001;
1616
17test "sin" {
17test sin {
1818 const a = Complex(f32).init(5, 3);
1919 const c = sin(a);
2020
lib/std/math/complex/sinh.zig+2-2
......@@ -154,7 +154,7 @@ fn sinh64(z: Complex(f64)) Complex(f64) {
154154
155155const epsilon = 0.0001;
156156
157test "sinh32" {
157test sinh32 {
158158 const a = Complex(f32).init(5, 3);
159159 const c = sinh(a);
160160
......@@ -162,7 +162,7 @@ test "sinh32" {
162162 try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
163163}
164164
165test "sinh64" {
165test sinh64 {
166166 const a = Complex(f64).init(5, 3);
167167 const c = sinh(a);
168168
lib/std/math/complex/sqrt.zig+2-2
......@@ -129,7 +129,7 @@ fn sqrt64(z: Complex(f64)) Complex(f64) {
129129
130130const epsilon = 0.0001;
131131
132test "sqrt32" {
132test sqrt32 {
133133 const a = Complex(f32).init(5, 3);
134134 const c = sqrt(a);
135135
......@@ -137,7 +137,7 @@ test "sqrt32" {
137137 try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
138138}
139139
140test "sqrt64" {
140test sqrt64 {
141141 const a = Complex(f64).init(5, 3);
142142 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)) {
1414
1515const epsilon = 0.0001;
1616
17test "tan" {
17test tan {
1818 const a = Complex(f32).init(5, 3);
1919 const c = tan(a);
2020
lib/std/math/complex/tanh.zig+2-2
......@@ -103,7 +103,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) {
103103
104104const epsilon = 0.0001;
105105
106test "tanh32" {
106test tanh32 {
107107 const a = Complex(f32).init(5, 3);
108108 const c = tanh(a);
109109
......@@ -111,7 +111,7 @@ test "tanh32" {
111111 try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
112112}
113113
114test "tanh64" {
114test tanh64 {
115115 const a = Complex(f64).init(5, 3);
116116 const c = tanh(a);
117117
lib/std/math/cosh.zig+3-3
......@@ -86,12 +86,12 @@ fn cosh64(x: f64) f64 {
8686 return expo2(ax);
8787}
8888
89test "cosh" {
89test cosh {
9090 try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
9191 try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
9292}
9393
94test "cosh32" {
94test cosh32 {
9595 const epsilon = 0.000001;
9696
9797 try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
......@@ -104,7 +104,7 @@ test "cosh32" {
104104 try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
105105}
106106
107test "cosh64" {
107test cosh64 {
108108 const epsilon = 0.000001;
109109
110110 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 {
286286 }
287287}
288288
289test "exp1m" {
289test expm1 {
290290 try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
291291 try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
292292}
293293
294test "expm1_32" {
294test expm1_32 {
295295 const epsilon = 0.000001;
296296
297297 try expect(math.isPositiveZero(expm1_32(0.0)));
......@@ -301,7 +301,7 @@ test "expm1_32" {
301301 try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
302302}
303303
304test "expm1_64" {
304test expm1_64 {
305305 const epsilon = 0.000001;
306306
307307 try expect(math.isPositiveZero(expm1_64(0.0)));
lib/std/math/float.zig+3-3
......@@ -132,7 +132,7 @@ test "float bits" {
132132 }
133133}
134134
135test "inf" {
135test inf {
136136 const inf_u16: u16 = 0x7C00;
137137 const inf_u32: u32 = 0x7F800000;
138138 const inf_u64: u64 = 0x7FF0000000000000;
......@@ -145,7 +145,7 @@ test "inf" {
145145 try expectEqual(inf_u128, @as(u128, @bitCast(inf(f128))));
146146}
147147
148test "nan" {
148test nan {
149149 const qnan_u16: u16 = 0x7E00;
150150 const qnan_u32: u32 = 0x7FC00000;
151151 const qnan_u64: u64 = 0x7FF8000000000000;
......@@ -158,7 +158,7 @@ test "nan" {
158158 try expectEqual(qnan_u128, @as(u128, @bitCast(nan(f128))));
159159}
160160
161test "snan" {
161test snan {
162162 // TODO: https://github.com/ziglang/zig/issues/14366
163163 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;
240240const expectEqual = std.testing.expectEqual;
241241const expectApproxEqRel = std.testing.expectApproxEqRel;
242242
243test "gamma" {
243test gamma {
244244 inline for (&.{ f32, f64 }) |T| {
245245 const eps = @sqrt(std.math.floatEps(T));
246246 try expectApproxEqRel(@as(T, 120), gamma(T, 6), eps);
......@@ -286,7 +286,7 @@ test "gamma.special" {
286286 }
287287}
288288
289test "lgamma" {
289test lgamma {
290290 inline for (&.{ f32, f64 }) |T| {
291291 const eps = @sqrt(std.math.floatEps(T));
292292 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 {
124124 return z * @sqrt(ly + lx + hy + hx);
125125}
126126
127test "hypot" {
127test hypot {
128128 const x32: f32 = 0.0;
129129 const y32: f32 = -1.2;
130130 const x64: f64 = 0.0;
......@@ -133,7 +133,7 @@ test "hypot" {
133133 try expect(hypot(x64, y64) == hypot64(0.0, -1.2));
134134}
135135
136test "hypot32" {
136test hypot32 {
137137 const epsilon = 0.000001;
138138
139139 try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
......@@ -145,7 +145,7 @@ test "hypot32" {
145145 try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
146146}
147147
148test "hypot64" {
148test hypot64 {
149149 const epsilon = 0.000001;
150150
151151 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 {
182182 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
183183}
184184
185test "log1p" {
185test log1p {
186186 try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
187187 try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
188188}
189189
190test "log1p_32" {
190test log1p_32 {
191191 const epsilon = 0.000001;
192192
193193 try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
......@@ -199,7 +199,7 @@ test "log1p_32" {
199199 try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
200200}
201201
202test "log1p_64" {
202test log1p_64 {
203203 const epsilon = 0.000001;
204204
205205 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) {
4242 }
4343}
4444
45test "log2" {
45test log2 {
4646 // https://github.com/ziglang/zig/issues/13703
4747 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 {
123123 return result;
124124}
125125
126test "modf" {
126test modf {
127127 const a = modf(@as(f32, 1.0));
128128 const b = modf32(1.0);
129129 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
130130 try expectEqual(a, b);
131131}
132132
133test "modf32" {
133test modf32 {
134134 const epsilon = 0.000001;
135135 var r: modf32_result = undefined;
136136
......@@ -155,7 +155,7 @@ test "modf32" {
155155 try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
156156}
157157
158test "modf64" {
158test modf64 {
159159 const epsilon = 0.000001;
160160 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{
9191 return acc;
9292}
9393
94test "powi" {
94test powi {
9595 try testing.expectError(error.Overflow, powi(i8, -66, 6));
9696 try testing.expectError(error.Overflow, powi(i16, -13, 13));
9797 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 {
9191 return 2 * h * expo2(ax);
9292}
9393
94test "sinh" {
94test sinh {
9595 try expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
9696 try expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
9797}
9898
99test "sinh32" {
99test sinh32 {
100100 const epsilon = 0.000001;
101101
102102 try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
......@@ -109,7 +109,7 @@ test "sinh32" {
109109 try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
110110}
111111
112test "sinh64" {
112test sinh64 {
113113 const epsilon = 0.000001;
114114
115115 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 {
104104 return if (sign) -t else t;
105105}
106106
107test "tanh" {
107test tanh {
108108 try expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
109109 try expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
110110}
111111
112test "tanh32" {
112test tanh32 {
113113 const epsilon = 0.000001;
114114
115115 try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
......@@ -122,7 +122,7 @@ test "tanh32" {
122122 try expect(math.approxEqAbs(f32, tanh32(-37.45), -1.0, epsilon));
123123}
124124
125test "tanh64" {
125test tanh64 {
126126 const epsilon = 0.000001;
127127
128128 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 {
4646 }
4747}
4848
49test "stringToEnum" {
49test stringToEnum {
5050 const E1 = enum {
5151 A,
5252 B,
......@@ -73,7 +73,7 @@ pub fn alignment(comptime T: type) comptime_int {
7373 };
7474}
7575
76test "alignment" {
76test alignment {
7777 try testing.expect(alignment(u8) == 1);
7878 try testing.expect(alignment(*align(1) u8) == 1);
7979 try testing.expect(alignment(*align(2) u8) == 2);
......@@ -94,7 +94,7 @@ pub fn Child(comptime T: type) type {
9494 };
9595}
9696
97test "Child" {
97test Child {
9898 try testing.expect(Child([1]u8) == u8);
9999 try testing.expect(Child(*u8) == u8);
100100 try testing.expect(Child([]u8) == u8);
......@@ -121,7 +121,7 @@ pub fn Elem(comptime T: type) type {
121121 @compileError("Expected pointer, slice, array or vector type, found '" ++ @typeName(T) ++ "'");
122122}
123123
124test "Elem" {
124test Elem {
125125 try testing.expect(Elem([1]u8) == u8);
126126 try testing.expect(Elem([*]u8) == u8);
127127 try testing.expect(Elem([]u8) == u8);
......@@ -255,7 +255,7 @@ pub fn containerLayout(comptime T: type) Type.ContainerLayout {
255255 };
256256}
257257
258test "containerLayout" {
258test containerLayout {
259259 const S1 = struct {};
260260 const S2 = packed struct {};
261261 const S3 = extern struct {};
......@@ -289,7 +289,7 @@ pub fn declarations(comptime T: type) []const Type.Declaration {
289289 };
290290}
291291
292test "declarations" {
292test declarations {
293293 const E1 = enum {
294294 A,
295295
......@@ -329,7 +329,7 @@ pub fn declarationInfo(comptime T: type, comptime decl_name: []const u8) Type.De
329329 @compileError("'" ++ @typeName(T) ++ "' has no declaration '" ++ decl_name ++ "'");
330330}
331331
332test "declarationInfo" {
332test declarationInfo {
333333 const E1 = enum {
334334 A,
335335
......@@ -370,7 +370,7 @@ pub fn fields(comptime T: type) switch (@typeInfo(T)) {
370370 };
371371}
372372
373test "fields" {
373test fields {
374374 const E1 = enum {
375375 A,
376376 };
......@@ -409,7 +409,7 @@ pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeIn
409409 return fields(T)[@intFromEnum(field)];
410410}
411411
412test "fieldInfo" {
412test fieldInfo {
413413 const E1 = enum {
414414 A,
415415 };
......@@ -442,7 +442,7 @@ pub fn FieldType(comptime T: type, comptime field: FieldEnum(T)) type {
442442 return fieldInfo(T, field).type;
443443}
444444
445test "FieldType" {
445test FieldType {
446446 const S = struct {
447447 a: u8,
448448 b: u16,
......@@ -470,7 +470,7 @@ pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 {
470470 };
471471}
472472
473test "fieldNames" {
473test fieldNames {
474474 const E1 = enum { A, B };
475475 const E2 = error{A};
476476 const S1 = struct {
......@@ -511,7 +511,7 @@ pub fn tags(comptime T: type) *const [fields(T).len]T {
511511 };
512512}
513513
514test "tags" {
514test tags {
515515 const E1 = enum { A, B };
516516 const E2 = error{A};
517517
......@@ -604,7 +604,7 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
604604 );
605605}
606606
607test "FieldEnum" {
607test FieldEnum {
608608 try expectEqualEnum(enum {}, FieldEnum(struct {}));
609609 try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
610610 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 {
639639 });
640640}
641641
642test "DeclEnum" {
642test DeclEnum {
643643 const A = struct {
644644 pub const a: u8 = 0;
645645 };
......@@ -670,7 +670,7 @@ pub fn Tag(comptime T: type) type {
670670 };
671671}
672672
673test "Tag" {
673test Tag {
674674 const E = enum(u8) {
675675 C = 33,
676676 D,
......@@ -690,7 +690,7 @@ pub fn activeTag(u: anytype) Tag(@TypeOf(u)) {
690690 return @as(Tag(T), u);
691691}
692692
693test "activeTag" {
693test activeTag {
694694 const UE = enum {
695695 Int,
696696 Float,
......@@ -727,7 +727,7 @@ pub fn TagPayload(comptime U: type, comptime tag: Tag(U)) type {
727727 return TagPayloadByName(U, @tagName(tag));
728728}
729729
730test "TagPayload" {
730test TagPayload {
731731 const Event = union(enum) {
732732 Moved: struct {
733733 from: i32,
......@@ -802,7 +802,7 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {
802802 }
803803}
804804
805test "eql" {
805test eql {
806806 const S = struct {
807807 a: u32,
808808 b: f64,
......@@ -863,7 +863,7 @@ test "eql" {
863863 try testing.expect(!eql(v1, v3));
864864}
865865
866test "intToEnum with error return" {
866test intToEnum {
867867 const E1 = enum {
868868 A,
869869 };
......@@ -965,7 +965,7 @@ pub fn Float(comptime bit_count: u8) type {
965965 });
966966}
967967
968test "Float" {
968test Float {
969969 try testing.expectEqual(f16, Float(16));
970970 try testing.expectEqual(f32, Float(32));
971971 try testing.expectEqual(f64, Float(64));
......@@ -1057,7 +1057,7 @@ const TupleTester = struct {
10571057 }
10581058};
10591059
1060test "ArgsTuple" {
1060test ArgsTuple {
10611061 TupleTester.assertTuple(.{}, ArgsTuple(fn () void));
10621062 TupleTester.assertTuple(.{u32}, ArgsTuple(fn (a: u32) []const u8));
10631063 TupleTester.assertTuple(.{ u32, f16 }, ArgsTuple(fn (a: u32, b: f16) noreturn));
......@@ -1065,7 +1065,7 @@ test "ArgsTuple" {
10651065 TupleTester.assertTuple(.{u32}, ArgsTuple(fn (comptime a: u32) []const u8));
10661066}
10671067
1068test "Tuple" {
1068test Tuple {
10691069 TupleTester.assertTuple(.{}, Tuple(&[_]type{}));
10701070 TupleTester.assertTuple(.{u32}, Tuple(&[_]type{u32}));
10711071 TupleTester.assertTuple(.{ u32, f16 }, Tuple(&[_]type{ u32, f16 }));
......@@ -1103,7 +1103,7 @@ pub fn isError(error_union: anytype) bool {
11031103 return if (error_union) |_| false else |_| true;
11041104}
11051105
1106test "isError" {
1106test isError {
11071107 try std.testing.expect(isError(math.divTrunc(u8, 5, 0)));
11081108 try std.testing.expect(!isError(math.divTrunc(u8, 5, 5)));
11091109}
......@@ -1121,7 +1121,7 @@ pub inline fn hasFn(comptime T: type, comptime name: []const u8) bool {
11211121 return @typeInfo(@TypeOf(@field(T, name))) == .Fn;
11221122}
11231123
1124test "hasFn" {
1124test hasFn {
11251125 const S1 = struct {
11261126 pub fn foo() void {}
11271127 };
......@@ -1149,7 +1149,7 @@ pub inline fn hasMethod(comptime T: type, comptime name: []const u8) bool {
11491149 };
11501150}
11511151
1152test "hasMethod" {
1152test hasMethod {
11531153 try std.testing.expect(!hasMethod(u32, "foo"));
11541154 try std.testing.expect(!hasMethod([]u32, "len"));
11551155 try std.testing.expect(!hasMethod(struct { u32, u64 }, "len"));
......@@ -1218,7 +1218,7 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
12181218 };
12191219}
12201220
1221test "hasUniqueRepresentation" {
1221test hasUniqueRepresentation {
12221222 const TestStruct1 = struct {
12231223 a: u32,
12241224 b: u32,