authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-11 22:47:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-11 22:47:45-07:00
log98c950827f9e57ab4736140eede61eac6858157f
treef84582fc9078ff765a130dc7d30a6d5980437651
parent0f3e8497195f383b9f2eb8cddd84f4966502f521

std.math: remove redundant namespace in test names

related: #7923

1 files changed, 29 insertions(+), 29 deletions(-)

lib/std/math.zig+29-29
...@@ -366,7 +366,7 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {...@@ -366,7 +366,7 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {
366 }366 }
367}367}
368368
369test "math.min" {369test "min" {
370 try testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);370 try testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
371 {371 {
372 var a: u16 = 999;372 var a: u16 = 999;
...@@ -403,7 +403,7 @@ pub fn min3(x: anytype, y: anytype, z: anytype) @TypeOf(x, y, z) {...@@ -403,7 +403,7 @@ pub fn min3(x: anytype, y: anytype, z: anytype) @TypeOf(x, y, z) {
403 return min(x, min(y, z));403 return min(x, min(y, z));
404}404}
405405
406test "math.min3" {406test "min3" {
407 try testing.expect(min3(@as(i32, 0), @as(i32, 1), @as(i32, 2)) == 0);407 try testing.expect(min3(@as(i32, 0), @as(i32, 1), @as(i32, 2)) == 0);
408 try testing.expect(min3(@as(i32, 0), @as(i32, 2), @as(i32, 1)) == 0);408 try testing.expect(min3(@as(i32, 0), @as(i32, 2), @as(i32, 1)) == 0);
409 try testing.expect(min3(@as(i32, 1), @as(i32, 0), @as(i32, 2)) == 0);409 try testing.expect(min3(@as(i32, 1), @as(i32, 0), @as(i32, 2)) == 0);
...@@ -418,7 +418,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {...@@ -418,7 +418,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {
418 return if (x > y) x else y;418 return if (x > y) x else y;
419}419}
420420
421test "math.max" {421test "max" {
422 try testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);422 try testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
423 try testing.expect(max(@as(i32, 2), @as(i32, -1)) == 2);423 try testing.expect(max(@as(i32, 2), @as(i32, -1)) == 2);
424}424}
...@@ -428,7 +428,7 @@ pub fn max3(x: anytype, y: anytype, z: anytype) @TypeOf(x, y, z) {...@@ -428,7 +428,7 @@ pub fn max3(x: anytype, y: anytype, z: anytype) @TypeOf(x, y, z) {
428 return max(x, max(y, z));428 return max(x, max(y, z));
429}429}
430430
431test "math.max3" {431test "max3" {
432 try testing.expect(max3(@as(i32, 0), @as(i32, 1), @as(i32, 2)) == 2);432 try testing.expect(max3(@as(i32, 0), @as(i32, 1), @as(i32, 2)) == 2);
433 try testing.expect(max3(@as(i32, 0), @as(i32, 2), @as(i32, 1)) == 2);433 try testing.expect(max3(@as(i32, 0), @as(i32, 2), @as(i32, 1)) == 2);
434 try testing.expect(max3(@as(i32, 1), @as(i32, 0), @as(i32, 2)) == 2);434 try testing.expect(max3(@as(i32, 1), @as(i32, 0), @as(i32, 2)) == 2);
...@@ -442,7 +442,7 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u...@@ -442,7 +442,7 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u
442 assert(lower <= upper);442 assert(lower <= upper);
443 return max(lower, min(val, upper));443 return max(lower, min(val, upper));
444}444}
445test "math.clamp" {445test "clamp" {
446 // Within range446 // Within range
447 try testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);447 try testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);
448 // Below448 // Below
...@@ -515,7 +515,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {...@@ -515,7 +515,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
515 return a << casted_shift_amt;515 return a << casted_shift_amt;
516}516}
517517
518test "math.shl" {518test "shl" {
519 try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);519 try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
520 try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);520 try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
521 try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);521 try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
...@@ -555,7 +555,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {...@@ -555,7 +555,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
555 return a >> casted_shift_amt;555 return a >> casted_shift_amt;
556}556}
557557
558test "math.shr" {558test "shr" {
559 try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);559 try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
560 try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);560 try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
561 try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);561 try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
...@@ -587,7 +587,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {...@@ -587,7 +587,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
587 }587 }
588}588}
589589
590test "math.rotr" {590test "rotr" {
591 try testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);591 try testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
592 try testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);592 try testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
593 try testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);593 try testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
...@@ -615,7 +615,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {...@@ -615,7 +615,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
615 }615 }
616}616}
617617
618test "math.rotl" {618test "rotl" {
619 try testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);619 try testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
620 try testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);620 try testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
621 try testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);621 try testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
...@@ -667,7 +667,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t...@@ -667,7 +667,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
667 return std.meta.Int(sign, magnitude_bits);667 return std.meta.Int(sign, magnitude_bits);
668}668}
669669
670test "math.IntFittingRange" {670test "IntFittingRange" {
671 try testing.expect(IntFittingRange(0, 0) == u0);671 try testing.expect(IntFittingRange(0, 0) == u0);
672 try testing.expect(IntFittingRange(0, 1) == u1);672 try testing.expect(IntFittingRange(0, 1) == u1);
673 try testing.expect(IntFittingRange(0, 2) == u2);673 try testing.expect(IntFittingRange(0, 2) == u2);
...@@ -714,7 +714,7 @@ test "math.IntFittingRange" {...@@ -714,7 +714,7 @@ test "math.IntFittingRange" {
714 try testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);714 try testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
715}715}
716716
717test "math overflow functions" {717test "overflow functions" {
718 try testOverflow();718 try testOverflow();
719 comptime try testOverflow();719 comptime try testOverflow();
720}720}
...@@ -741,7 +741,7 @@ pub fn absInt(x: anytype) !@TypeOf(x) {...@@ -741,7 +741,7 @@ pub fn absInt(x: anytype) !@TypeOf(x) {
741 }741 }
742}742}
743743
744test "math.absInt" {744test "absInt" {
745 try testAbsInt();745 try testAbsInt();
746 comptime try testAbsInt();746 comptime try testAbsInt();
747}747}
...@@ -752,7 +752,7 @@ fn testAbsInt() !void {...@@ -752,7 +752,7 @@ fn testAbsInt() !void {
752752
753pub const absFloat = fabs;753pub const absFloat = fabs;
754754
755test "math.absFloat" {755test "absFloat" {
756 try testAbsFloat();756 try testAbsFloat();
757 comptime try testAbsFloat();757 comptime try testAbsFloat();
758}758}
...@@ -770,7 +770,7 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {...@@ -770,7 +770,7 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
770 return @divTrunc(numerator, denominator);770 return @divTrunc(numerator, denominator);
771}771}
772772
773test "math.divTrunc" {773test "divTrunc" {
774 try testDivTrunc();774 try testDivTrunc();
775 comptime try testDivTrunc();775 comptime try testDivTrunc();
776}776}
...@@ -794,7 +794,7 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {...@@ -794,7 +794,7 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
794 return @divFloor(numerator, denominator);794 return @divFloor(numerator, denominator);
795}795}
796796
797test "math.divFloor" {797test "divFloor" {
798 try testDivFloor();798 try testDivFloor();
799 comptime try testDivFloor();799 comptime try testDivFloor();
800}800}
...@@ -831,7 +831,7 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {...@@ -831,7 +831,7 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
831 }831 }
832}832}
833833
834test "math.divCeil" {834test "divCeil" {
835 try testDivCeil();835 try testDivCeil();
836 comptime try testDivCeil();836 comptime try testDivCeil();
837}837}
...@@ -875,7 +875,7 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {...@@ -875,7 +875,7 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
875 return result;875 return result;
876}876}
877877
878test "math.divExact" {878test "divExact" {
879 try testDivExact();879 try testDivExact();
880 comptime try testDivExact();880 comptime try testDivExact();
881}881}
...@@ -901,7 +901,7 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T {...@@ -901,7 +901,7 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
901 return @mod(numerator, denominator);901 return @mod(numerator, denominator);
902}902}
903903
904test "math.mod" {904test "mod" {
905 try testMod();905 try testMod();
906 comptime try testMod();906 comptime try testMod();
907}907}
...@@ -927,7 +927,7 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T {...@@ -927,7 +927,7 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
927 return @rem(numerator, denominator);927 return @rem(numerator, denominator);
928}928}
929929
930test "math.rem" {930test "rem" {
931 try testRem();931 try testRem();
932 comptime try testRem();932 comptime try testRem();
933}933}
...@@ -971,7 +971,7 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {...@@ -971,7 +971,7 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
971 }971 }
972}972}
973973
974test "math.absCast" {974test "absCast" {
975 try testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));975 try testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
976 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));976 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
977 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));977 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
...@@ -992,7 +992,7 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x...@@ -992,7 +992,7 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x
992 return -@intCast(int, x);992 return -@intCast(int, x);
993}993}
994994
995test "math.negateCast" {995test "negateCast" {
996 try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);996 try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
997 try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);997 try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
998998
...@@ -1017,7 +1017,7 @@ pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) {...@@ -1017,7 +1017,7 @@ pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) {
1017 }1017 }
1018}1018}
10191019
1020test "math.cast" {1020test "cast" {
1021 try testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));1021 try testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
1022 try testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));1022 try testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
1023 try testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));1023 try testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
...@@ -1051,7 +1051,7 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {...@@ -1051,7 +1051,7 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {
1051 return @as(T, 1) << log2_int(uT, @intCast(uT, value));1051 return @as(T, 1) << log2_int(uT, @intCast(uT, value));
1052}1052}
10531053
1054test "math.floorPowerOfTwo" {1054test "floorPowerOfTwo" {
1055 try testFloorPowerOfTwo();1055 try testFloorPowerOfTwo();
1056 comptime try testFloorPowerOfTwo();1056 comptime try testFloorPowerOfTwo();
1057}1057}
...@@ -1106,7 +1106,7 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T {...@@ -1106,7 +1106,7 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T {
1106 return ceilPowerOfTwo(T, value) catch unreachable;1106 return ceilPowerOfTwo(T, value) catch unreachable;
1107}1107}
11081108
1109test "math.ceilPowerOfTwoPromote" {1109test "ceilPowerOfTwoPromote" {
1110 try testCeilPowerOfTwoPromote();1110 try testCeilPowerOfTwoPromote();
1111 comptime try testCeilPowerOfTwoPromote();1111 comptime try testCeilPowerOfTwoPromote();
1112}1112}
...@@ -1123,7 +1123,7 @@ fn testCeilPowerOfTwoPromote() !void {...@@ -1123,7 +1123,7 @@ fn testCeilPowerOfTwoPromote() !void {
1123 try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));1123 try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
1124}1124}
11251125
1126test "math.ceilPowerOfTwo" {1126test "ceilPowerOfTwo" {
1127 try testCeilPowerOfTwo();1127 try testCeilPowerOfTwo();
1128 comptime try testCeilPowerOfTwo();1128 comptime try testCeilPowerOfTwo();
1129}1129}
...@@ -1214,13 +1214,13 @@ pub fn lossyCast(comptime T: type, value: anytype) T {...@@ -1214,13 +1214,13 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
1214 }1214 }
1215}1215}
12161216
1217test "math.lossyCast" {1217test "lossyCast" {
1218 try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));1218 try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
1219 try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));1219 try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
1220 try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));1220 try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
1221}1221}
12221222
1223test "math.f64_min" {1223test "f64_min" {
1224 const f64_min_u64 = 0x0010000000000000;1224 const f64_min_u64 = 0x0010000000000000;
1225 const fmin: f64 = f64_min;1225 const fmin: f64 = f64_min;
1226 try testing.expect(@bitCast(u64, fmin) == f64_min_u64);1226 try testing.expect(@bitCast(u64, fmin) == f64_min_u64);
...@@ -1298,7 +1298,7 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(...@@ -1298,7 +1298,7 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(
1298 return @as(ResultInt, a) * @as(ResultInt, b);1298 return @as(ResultInt, a) * @as(ResultInt, b);
1299}1299}
13001300
1301test "math.mulWide" {1301test "mulWide" {
1302 try testing.expect(mulWide(u8, 5, 5) == 25);1302 try testing.expect(mulWide(u8, 5, 5) == 25);
1303 try testing.expect(mulWide(i8, 5, -5) == -25);1303 try testing.expect(mulWide(i8, 5, -5) == -25);
1304 try testing.expect(mulWide(u8, 100, 100) == 10000);1304 try testing.expect(mulWide(u8, 100, 100) == 10000);
...@@ -1439,7 +1439,7 @@ test "order.compare" {...@@ -1439,7 +1439,7 @@ test "order.compare" {
1439 try testing.expect(order(1, 0).compare(.neq));1439 try testing.expect(order(1, 0).compare(.neq));
1440}1440}
14411441
1442test "math.comptime" {1442test "comptime sin and ln" {
1443 const v = comptime (sin(@as(f32, 1)) + ln(@as(f32, 5)));1443 const v = comptime (sin(@as(f32, 1)) + ln(@as(f32, 5)));
1444 try testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));1444 try testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));
1445}1445}