aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math/big
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2021-05-04 20:47:26 +0300
committerVeikka Tuominen <git@vexu.eu>2021-05-08 15:15:30 +0300
commitfd77f2cfed81f3414c079909e079a812e23071c3 (patch)
treef9facf463ab13791faa0820c347371067ed27a79 /lib/std/math/big
parent59f9253d94331cedd4d0518250c8094a064f6cd2 (diff)
downloadzig-fd77f2cfed81f3414c079909e079a812e23071c3.tar.gz
zig-fd77f2cfed81f3414c079909e079a812e23071c3.zip
std: update usage of std.testing
Diffstat (limited to 'lib/std/math/big')
-rw-r--r--lib/std/math/big/int_test.zig422
-rw-r--r--lib/std/math/big/rational.zig134
2 files changed, 278 insertions, 278 deletions
diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig
index 179e55ff69..93291bf217 100644
--- a/lib/std/math/big/int_test.zig
+++ b/lib/std/math/big/int_test.zig
@@ -30,7 +30,7 @@ test "big.int comptime_int set" {
const result = @as(Limb, s & maxInt(Limb));
s >>= @typeInfo(Limb).Int.bits / 2;
s >>= @typeInfo(Limb).Int.bits / 2;
- testing.expect(a.limbs[i] == result);
+ try testing.expect(a.limbs[i] == result);
}
}
@@ -38,37 +38,37 @@ test "big.int comptime_int set negative" {
var a = try Managed.initSet(testing.allocator, -10);
defer a.deinit();
- testing.expect(a.limbs[0] == 10);
- testing.expect(a.isPositive() == false);
+ try testing.expect(a.limbs[0] == 10);
+ try testing.expect(a.isPositive() == false);
}
test "big.int int set unaligned small" {
var a = try Managed.initSet(testing.allocator, @as(u7, 45));
defer a.deinit();
- testing.expect(a.limbs[0] == 45);
- testing.expect(a.isPositive() == true);
+ try testing.expect(a.limbs[0] == 45);
+ try testing.expect(a.isPositive() == true);
}
test "big.int comptime_int to" {
var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
defer a.deinit();
- testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
+ try testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
}
test "big.int sub-limb to" {
var a = try Managed.initSet(testing.allocator, 10);
defer a.deinit();
- testing.expect((try a.to(u8)) == 10);
+ try testing.expect((try a.to(u8)) == 10);
}
test "big.int to target too small error" {
var a = try Managed.initSet(testing.allocator, 0xffffffff);
defer a.deinit();
- testing.expectError(error.TargetTooSmall, a.to(u8));
+ try testing.expectError(error.TargetTooSmall, a.to(u8));
}
test "big.int normalize" {
@@ -81,22 +81,22 @@ test "big.int normalize" {
a.limbs[2] = 3;
a.limbs[3] = 0;
a.normalize(4);
- testing.expect(a.len() == 3);
+ try testing.expect(a.len() == 3);
a.limbs[0] = 1;
a.limbs[1] = 2;
a.limbs[2] = 3;
a.normalize(3);
- testing.expect(a.len() == 3);
+ try testing.expect(a.len() == 3);
a.limbs[0] = 0;
a.limbs[1] = 0;
a.normalize(2);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
a.limbs[0] = 0;
a.normalize(1);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
}
test "big.int normalize multi" {
@@ -109,24 +109,24 @@ test "big.int normalize multi" {
a.limbs[2] = 0;
a.limbs[3] = 0;
a.normalize(4);
- testing.expect(a.len() == 2);
+ try testing.expect(a.len() == 2);
a.limbs[0] = 1;
a.limbs[1] = 2;
a.limbs[2] = 3;
a.normalize(3);
- testing.expect(a.len() == 3);
+ try testing.expect(a.len() == 3);
a.limbs[0] = 0;
a.limbs[1] = 0;
a.limbs[2] = 0;
a.limbs[3] = 0;
a.normalize(4);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
a.limbs[0] = 0;
a.normalize(1);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
}
test "big.int parity" {
@@ -134,12 +134,12 @@ test "big.int parity" {
defer a.deinit();
try a.set(0);
- testing.expect(a.isEven());
- testing.expect(!a.isOdd());
+ try testing.expect(a.isEven());
+ try testing.expect(!a.isOdd());
try a.set(7);
- testing.expect(!a.isEven());
- testing.expect(a.isOdd());
+ try testing.expect(!a.isEven());
+ try testing.expect(a.isOdd());
}
test "big.int bitcount + sizeInBaseUpperBound" {
@@ -147,27 +147,27 @@ test "big.int bitcount + sizeInBaseUpperBound" {
defer a.deinit();
try a.set(0b100);
- testing.expect(a.bitCountAbs() == 3);
- testing.expect(a.sizeInBaseUpperBound(2) >= 3);
- testing.expect(a.sizeInBaseUpperBound(10) >= 1);
+ try testing.expect(a.bitCountAbs() == 3);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 3);
+ try testing.expect(a.sizeInBaseUpperBound(10) >= 1);
a.negate();
- testing.expect(a.bitCountAbs() == 3);
- testing.expect(a.sizeInBaseUpperBound(2) >= 4);
- testing.expect(a.sizeInBaseUpperBound(10) >= 2);
+ try testing.expect(a.bitCountAbs() == 3);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 4);
+ try testing.expect(a.sizeInBaseUpperBound(10) >= 2);
try a.set(0xffffffff);
- testing.expect(a.bitCountAbs() == 32);
- testing.expect(a.sizeInBaseUpperBound(2) >= 32);
- testing.expect(a.sizeInBaseUpperBound(10) >= 10);
+ try testing.expect(a.bitCountAbs() == 32);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 32);
+ try testing.expect(a.sizeInBaseUpperBound(10) >= 10);
try a.shiftLeft(a, 5000);
- testing.expect(a.bitCountAbs() == 5032);
- testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
+ try testing.expect(a.bitCountAbs() == 5032);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
a.setSign(false);
- testing.expect(a.bitCountAbs() == 5032);
- testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
+ try testing.expect(a.bitCountAbs() == 5032);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
}
test "big.int bitcount/to" {
@@ -175,30 +175,30 @@ test "big.int bitcount/to" {
defer a.deinit();
try a.set(0);
- testing.expect(a.bitCountTwosComp() == 0);
+ try testing.expect(a.bitCountTwosComp() == 0);
- testing.expect((try a.to(u0)) == 0);
- testing.expect((try a.to(i0)) == 0);
+ try testing.expect((try a.to(u0)) == 0);
+ try testing.expect((try a.to(i0)) == 0);
try a.set(-1);
- testing.expect(a.bitCountTwosComp() == 1);
- testing.expect((try a.to(i1)) == -1);
+ try testing.expect(a.bitCountTwosComp() == 1);
+ try testing.expect((try a.to(i1)) == -1);
try a.set(-8);
- testing.expect(a.bitCountTwosComp() == 4);
- testing.expect((try a.to(i4)) == -8);
+ try testing.expect(a.bitCountTwosComp() == 4);
+ try testing.expect((try a.to(i4)) == -8);
try a.set(127);
- testing.expect(a.bitCountTwosComp() == 7);
- testing.expect((try a.to(u7)) == 127);
+ try testing.expect(a.bitCountTwosComp() == 7);
+ try testing.expect((try a.to(u7)) == 127);
try a.set(-128);
- testing.expect(a.bitCountTwosComp() == 8);
- testing.expect((try a.to(i8)) == -128);
+ try testing.expect(a.bitCountTwosComp() == 8);
+ try testing.expect((try a.to(i8)) == -128);
try a.set(-129);
- testing.expect(a.bitCountTwosComp() == 9);
- testing.expect((try a.to(i9)) == -129);
+ try testing.expect(a.bitCountTwosComp() == 9);
+ try testing.expect((try a.to(i9)) == -129);
}
test "big.int fits" {
@@ -206,27 +206,27 @@ test "big.int fits" {
defer a.deinit();
try a.set(0);
- testing.expect(a.fits(u0));
- testing.expect(a.fits(i0));
+ try testing.expect(a.fits(u0));
+ try testing.expect(a.fits(i0));
try a.set(255);
- testing.expect(!a.fits(u0));
- testing.expect(!a.fits(u1));
- testing.expect(!a.fits(i8));
- testing.expect(a.fits(u8));
- testing.expect(a.fits(u9));
- testing.expect(a.fits(i9));
+ try testing.expect(!a.fits(u0));
+ try testing.expect(!a.fits(u1));
+ try testing.expect(!a.fits(i8));
+ try testing.expect(a.fits(u8));
+ try testing.expect(a.fits(u9));
+ try testing.expect(a.fits(i9));
try a.set(-128);
- testing.expect(!a.fits(i7));
- testing.expect(a.fits(i8));
- testing.expect(a.fits(i9));
- testing.expect(!a.fits(u9));
+ try testing.expect(!a.fits(i7));
+ try testing.expect(a.fits(i8));
+ try testing.expect(a.fits(i9));
+ try testing.expect(!a.fits(u9));
try a.set(0x1ffffffffeeeeeeee);
- testing.expect(!a.fits(u32));
- testing.expect(!a.fits(u64));
- testing.expect(a.fits(u65));
+ try testing.expect(!a.fits(u32));
+ try testing.expect(!a.fits(u64));
+ try testing.expect(a.fits(u65));
}
test "big.int string set" {
@@ -234,7 +234,7 @@ test "big.int string set" {
defer a.deinit();
try a.setString(10, "120317241209124781241290847124");
- testing.expect((try a.to(u128)) == 120317241209124781241290847124);
+ try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
}
test "big.int string negative" {
@@ -242,7 +242,7 @@ test "big.int string negative" {
defer a.deinit();
try a.setString(10, "-1023");
- testing.expect((try a.to(i32)) == -1023);
+ try testing.expect((try a.to(i32)) == -1023);
}
test "big.int string set number with underscores" {
@@ -250,7 +250,7 @@ test "big.int string set number with underscores" {
defer a.deinit();
try a.setString(10, "__1_2_0_3_1_7_2_4_1_2_0_____9_1__2__4_7_8_1_2_4_1_2_9_0_8_4_7_1_2_4___");
- testing.expect((try a.to(u128)) == 120317241209124781241290847124);
+ try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
}
test "big.int string set case insensitive number" {
@@ -258,19 +258,19 @@ test "big.int string set case insensitive number" {
defer a.deinit();
try a.setString(16, "aB_cD_eF");
- testing.expect((try a.to(u32)) == 0xabcdef);
+ try testing.expect((try a.to(u32)) == 0xabcdef);
}
test "big.int string set bad char error" {
var a = try Managed.init(testing.allocator);
defer a.deinit();
- testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
+ try testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
}
test "big.int string set bad base error" {
var a = try Managed.init(testing.allocator);
defer a.deinit();
- testing.expectError(error.InvalidBase, a.setString(45, "10"));
+ try testing.expectError(error.InvalidBase, a.setString(45, "10"));
}
test "big.int string to" {
@@ -281,14 +281,14 @@ test "big.int string to" {
defer testing.allocator.free(as);
const es = "120317241209124781241290847124";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int string to base base error" {
var a = try Managed.initSet(testing.allocator, 0xffffffff);
defer a.deinit();
- testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));
+ try testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));
}
test "big.int string to base 2" {
@@ -299,7 +299,7 @@ test "big.int string to base 2" {
defer testing.allocator.free(as);
const es = "-1011";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int string to base 16" {
@@ -310,7 +310,7 @@ test "big.int string to base 16" {
defer testing.allocator.free(as);
const es = "efffffff00000001eeeeeeefaaaaaaab";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int neg string to" {
@@ -321,7 +321,7 @@ test "big.int neg string to" {
defer testing.allocator.free(as);
const es = "-123907434";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int zero string to" {
@@ -332,7 +332,7 @@ test "big.int zero string to" {
defer testing.allocator.free(as);
const es = "0";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int clone" {
@@ -341,12 +341,12 @@ test "big.int clone" {
var b = try a.clone();
defer b.deinit();
- testing.expect((try a.to(u32)) == 1234);
- testing.expect((try b.to(u32)) == 1234);
+ try testing.expect((try a.to(u32)) == 1234);
+ try testing.expect((try b.to(u32)) == 1234);
try a.set(77);
- testing.expect((try a.to(u32)) == 77);
- testing.expect((try b.to(u32)) == 1234);
+ try testing.expect((try a.to(u32)) == 77);
+ try testing.expect((try b.to(u32)) == 1234);
}
test "big.int swap" {
@@ -355,20 +355,20 @@ test "big.int swap" {
var b = try Managed.initSet(testing.allocator, 5678);
defer b.deinit();
- testing.expect((try a.to(u32)) == 1234);
- testing.expect((try b.to(u32)) == 5678);
+ try testing.expect((try a.to(u32)) == 1234);
+ try testing.expect((try b.to(u32)) == 5678);
a.swap(&b);
- testing.expect((try a.to(u32)) == 5678);
- testing.expect((try b.to(u32)) == 1234);
+ try testing.expect((try a.to(u32)) == 5678);
+ try testing.expect((try b.to(u32)) == 1234);
}
test "big.int to negative" {
var a = try Managed.initSet(testing.allocator, -10);
defer a.deinit();
- testing.expect((try a.to(i32)) == -10);
+ try testing.expect((try a.to(i32)) == -10);
}
test "big.int compare" {
@@ -377,8 +377,8 @@ test "big.int compare" {
var b = try Managed.initSet(testing.allocator, 10);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .gt);
- testing.expect(a.order(b) == .lt);
+ try testing.expect(a.orderAbs(b) == .gt);
+ try testing.expect(a.order(b) == .lt);
}
test "big.int compare similar" {
@@ -387,8 +387,8 @@ test "big.int compare similar" {
var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .lt);
- testing.expect(b.orderAbs(a) == .gt);
+ try testing.expect(a.orderAbs(b) == .lt);
+ try testing.expect(b.orderAbs(a) == .gt);
}
test "big.int compare different limb size" {
@@ -397,8 +397,8 @@ test "big.int compare different limb size" {
var b = try Managed.initSet(testing.allocator, 1);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .gt);
- testing.expect(b.orderAbs(a) == .lt);
+ try testing.expect(a.orderAbs(b) == .gt);
+ try testing.expect(b.orderAbs(a) == .lt);
}
test "big.int compare multi-limb" {
@@ -407,8 +407,8 @@ test "big.int compare multi-limb" {
var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .gt);
- testing.expect(a.order(b) == .lt);
+ try testing.expect(a.orderAbs(b) == .gt);
+ try testing.expect(a.order(b) == .lt);
}
test "big.int equality" {
@@ -417,8 +417,8 @@ test "big.int equality" {
var b = try Managed.initSet(testing.allocator, -0xffffffff1);
defer b.deinit();
- testing.expect(a.eqAbs(b));
- testing.expect(!a.eq(b));
+ try testing.expect(a.eqAbs(b));
+ try testing.expect(!a.eq(b));
}
test "big.int abs" {
@@ -426,10 +426,10 @@ test "big.int abs" {
defer a.deinit();
a.abs();
- testing.expect((try a.to(u32)) == 5);
+ try testing.expect((try a.to(u32)) == 5);
a.abs();
- testing.expect((try a.to(u32)) == 5);
+ try testing.expect((try a.to(u32)) == 5);
}
test "big.int negate" {
@@ -437,10 +437,10 @@ test "big.int negate" {
defer a.deinit();
a.negate();
- testing.expect((try a.to(i32)) == -5);
+ try testing.expect((try a.to(i32)) == -5);
a.negate();
- testing.expect((try a.to(i32)) == 5);
+ try testing.expect((try a.to(i32)) == 5);
}
test "big.int add single-single" {
@@ -453,7 +453,7 @@ test "big.int add single-single" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 55);
+ try testing.expect((try c.to(u32)) == 55);
}
test "big.int add multi-single" {
@@ -466,10 +466,10 @@ test "big.int add multi-single" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
+ try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
try c.add(b.toConst(), a.toConst());
- testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
+ try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
}
test "big.int add multi-multi" {
@@ -484,7 +484,7 @@ test "big.int add multi-multi" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(u128)) == op1 + op2);
+ try testing.expect((try c.to(u128)) == op1 + op2);
}
test "big.int add zero-zero" {
@@ -497,7 +497,7 @@ test "big.int add zero-zero" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int add alias multi-limb nonzero-zero" {
@@ -509,7 +509,7 @@ test "big.int add alias multi-limb nonzero-zero" {
try a.add(a.toConst(), b.toConst());
- testing.expect((try a.to(u128)) == op1);
+ try testing.expect((try a.to(u128)) == op1);
}
test "big.int add sign" {
@@ -526,16 +526,16 @@ test "big.int add sign" {
defer neg_two.deinit();
try a.add(one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == 3);
+ try testing.expect((try a.to(i32)) == 3);
try a.add(neg_one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == 1);
+ try testing.expect((try a.to(i32)) == 1);
try a.add(one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == -1);
+ try testing.expect((try a.to(i32)) == -1);
try a.add(neg_one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == -3);
+ try testing.expect((try a.to(i32)) == -3);
}
test "big.int sub single-single" {
@@ -548,7 +548,7 @@ test "big.int sub single-single" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 45);
+ try testing.expect((try c.to(u32)) == 45);
}
test "big.int sub multi-single" {
@@ -561,7 +561,7 @@ test "big.int sub multi-single" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(Limb)) == maxInt(Limb));
+ try testing.expect((try c.to(Limb)) == maxInt(Limb));
}
test "big.int sub multi-multi" {
@@ -577,7 +577,7 @@ test "big.int sub multi-multi" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(u128)) == op1 - op2);
+ try testing.expect((try c.to(u128)) == op1 - op2);
}
test "big.int sub equal" {
@@ -590,7 +590,7 @@ test "big.int sub equal" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int sub sign" {
@@ -607,19 +607,19 @@ test "big.int sub sign" {
defer neg_two.deinit();
try a.sub(one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == -1);
+ try testing.expect((try a.to(i32)) == -1);
try a.sub(neg_one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == -3);
+ try testing.expect((try a.to(i32)) == -3);
try a.sub(one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == 3);
+ try testing.expect((try a.to(i32)) == 3);
try a.sub(neg_one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == 1);
+ try testing.expect((try a.to(i32)) == 1);
try a.sub(neg_two.toConst(), neg_one.toConst());
- testing.expect((try a.to(i32)) == -1);
+ try testing.expect((try a.to(i32)) == -1);
}
test "big.int mul single-single" {
@@ -632,7 +632,7 @@ test "big.int mul single-single" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u64)) == 250);
+ try testing.expect((try c.to(u64)) == 250);
}
test "big.int mul multi-single" {
@@ -645,7 +645,7 @@ test "big.int mul multi-single" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
+ try testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
}
test "big.int mul multi-multi" {
@@ -660,7 +660,7 @@ test "big.int mul multi-multi" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u256)) == op1 * op2);
+ try testing.expect((try c.to(u256)) == op1 * op2);
}
test "big.int mul alias r with a" {
@@ -671,7 +671,7 @@ test "big.int mul alias r with a" {
try a.mul(a.toConst(), b.toConst());
- testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
}
test "big.int mul alias r with b" {
@@ -682,7 +682,7 @@ test "big.int mul alias r with b" {
try a.mul(b.toConst(), a.toConst());
- testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
}
test "big.int mul alias r with a and b" {
@@ -691,7 +691,7 @@ test "big.int mul alias r with a and b" {
try a.mul(a.toConst(), a.toConst());
- testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
}
test "big.int mul a*0" {
@@ -704,7 +704,7 @@ test "big.int mul a*0" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int mul 0*0" {
@@ -717,7 +717,7 @@ test "big.int mul 0*0" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int mul large" {
@@ -738,7 +738,7 @@ test "big.int mul large" {
try b.mul(a.toConst(), a.toConst());
try c.sqr(a.toConst());
- testing.expect(b.eq(c));
+ try testing.expect(b.eq(c));
}
test "big.int div single-single no rem" {
@@ -753,8 +753,8 @@ test "big.int div single-single no rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u32)) == 10);
- testing.expect((try r.to(u32)) == 0);
+ try testing.expect((try q.to(u32)) == 10);
+ try testing.expect((try r.to(u32)) == 0);
}
test "big.int div single-single with rem" {
@@ -769,8 +769,8 @@ test "big.int div single-single with rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u32)) == 9);
- testing.expect((try r.to(u32)) == 4);
+ try testing.expect((try q.to(u32)) == 9);
+ try testing.expect((try r.to(u32)) == 4);
}
test "big.int div multi-single no rem" {
@@ -788,8 +788,8 @@ test "big.int div multi-single no rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == op1 / op2);
- testing.expect((try r.to(u64)) == 0);
+ try testing.expect((try q.to(u64)) == op1 / op2);
+ try testing.expect((try r.to(u64)) == 0);
}
test "big.int div multi-single with rem" {
@@ -807,8 +807,8 @@ test "big.int div multi-single with rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == op1 / op2);
- testing.expect((try r.to(u64)) == 3);
+ try testing.expect((try q.to(u64)) == op1 / op2);
+ try testing.expect((try r.to(u64)) == 3);
}
test "big.int div multi>2-single" {
@@ -826,8 +826,8 @@ test "big.int div multi>2-single" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == op1 / op2);
- testing.expect((try r.to(u32)) == 0x3e4e);
+ try testing.expect((try q.to(u128)) == op1 / op2);
+ try testing.expect((try r.to(u32)) == 0x3e4e);
}
test "big.int div single-single q < r" {
@@ -842,8 +842,8 @@ test "big.int div single-single q < r" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == 0);
- testing.expect((try r.to(u64)) == 0x0078f432);
+ try testing.expect((try q.to(u64)) == 0);
+ try testing.expect((try r.to(u64)) == 0x0078f432);
}
test "big.int div single-single q == r" {
@@ -858,8 +858,8 @@ test "big.int div single-single q == r" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == 1);
- testing.expect((try r.to(u64)) == 0);
+ try testing.expect((try q.to(u64)) == 1);
+ try testing.expect((try r.to(u64)) == 0);
}
test "big.int div q=0 alias" {
@@ -870,8 +870,8 @@ test "big.int div q=0 alias" {
try Managed.divTrunc(&a, &b, a.toConst(), b.toConst());
- testing.expect((try a.to(u64)) == 0);
- testing.expect((try b.to(u64)) == 3);
+ try testing.expect((try a.to(u64)) == 0);
+ try testing.expect((try b.to(u64)) == 3);
}
test "big.int div multi-multi q < r" {
@@ -888,8 +888,8 @@ test "big.int div multi-multi q < r" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0);
- testing.expect((try r.to(u128)) == op1);
+ try testing.expect((try q.to(u128)) == 0);
+ try testing.expect((try r.to(u128)) == op1);
}
test "big.int div trunc single-single +/+" {
@@ -912,8 +912,8 @@ test "big.int div trunc single-single +/+" {
const eq = @divTrunc(u, v);
const er = @mod(u, v);
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div trunc single-single -/+" {
@@ -936,8 +936,8 @@ test "big.int div trunc single-single -/+" {
const eq = -1;
const er = -2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div trunc single-single +/-" {
@@ -960,8 +960,8 @@ test "big.int div trunc single-single +/-" {
const eq = -1;
const er = 2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div trunc single-single -/-" {
@@ -984,8 +984,8 @@ test "big.int div trunc single-single -/-" {
const eq = 1;
const er = -2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single +/+" {
@@ -1008,8 +1008,8 @@ test "big.int div floor single-single +/+" {
const eq = 1;
const er = 2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single -/+" {
@@ -1032,8 +1032,8 @@ test "big.int div floor single-single -/+" {
const eq = -2;
const er = 1;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single +/-" {
@@ -1056,8 +1056,8 @@ test "big.int div floor single-single +/-" {
const eq = -2;
const er = -1;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single -/-" {
@@ -1080,8 +1080,8 @@ test "big.int div floor single-single -/-" {
const eq = 1;
const er = -2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div multi-multi with rem" {
@@ -1096,8 +1096,8 @@ test "big.int div multi-multi with rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
- testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
+ try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
+ try testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
}
test "big.int div multi-multi no rem" {
@@ -1112,8 +1112,8 @@ test "big.int div multi-multi no rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
- testing.expect((try r.to(u128)) == 0);
+ try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
+ try testing.expect((try r.to(u128)) == 0);
}
test "big.int div multi-multi (2 branch)" {
@@ -1128,8 +1128,8 @@ test "big.int div multi-multi (2 branch)" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0x10000000000000000);
- testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
+ try testing.expect((try q.to(u128)) == 0x10000000000000000);
+ try testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
}
test "big.int div multi-multi (3.1/3.3 branch)" {
@@ -1144,8 +1144,8 @@ test "big.int div multi-multi (3.1/3.3 branch)" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
- testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
+ try testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
+ try testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
}
test "big.int div multi-single zero-limb trailing" {
@@ -1162,8 +1162,8 @@ test "big.int div multi-single zero-limb trailing" {
var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000);
defer expected.deinit();
- testing.expect(q.eq(expected));
- testing.expect(r.eqZero());
+ try testing.expect(q.eq(expected));
+ try testing.expect(r.eqZero());
}
test "big.int div multi-multi zero-limb trailing (with rem)" {
@@ -1178,11 +1178,11 @@ test "big.int div multi-multi zero-limb trailing (with rem)" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0x10000000000000000);
+ try testing.expect((try q.to(u128)) == 0x10000000000000000);
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
}
test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" {
@@ -1197,11 +1197,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0x1);
+ try testing.expect((try q.to(u128)) == 0x1);
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
}
test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" {
@@ -1218,11 +1218,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
const qs = try q.toString(testing.allocator, 16, false);
defer testing.allocator.free(qs);
- testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
+ try testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
}
test "big.int div multi-multi fuzz case #1" {
@@ -1242,11 +1242,11 @@ test "big.int div multi-multi fuzz case #1" {
const qs = try q.toString(testing.allocator, 16, false);
defer testing.allocator.free(qs);
- testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
+ try testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
+ try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
}
test "big.int div multi-multi fuzz case #2" {
@@ -1266,11 +1266,11 @@ test "big.int div multi-multi fuzz case #2" {
const qs = try q.toString(testing.allocator, 16, false);
defer testing.allocator.free(qs);
- testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
+ try testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
}
test "big.int shift-right single" {
@@ -1278,7 +1278,7 @@ test "big.int shift-right single" {
defer a.deinit();
try a.shiftRight(a, 16);
- testing.expect((try a.to(u32)) == 0xffff);
+ try testing.expect((try a.to(u32)) == 0xffff);
}
test "big.int shift-right multi" {
@@ -1286,13 +1286,13 @@ test "big.int shift-right multi" {
defer a.deinit();
try a.shiftRight(a, 67);
- testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
+ try testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
try a.set(0xffff0000eeee1111dddd2222cccc3333);
try a.shiftRight(a, 63);
try a.shiftRight(a, 63);
try a.shiftRight(a, 2);
- testing.expect(a.eqZero());
+ try testing.expect(a.eqZero());
}
test "big.int shift-left single" {
@@ -1300,7 +1300,7 @@ test "big.int shift-left single" {
defer a.deinit();
try a.shiftLeft(a, 16);
- testing.expect((try a.to(u64)) == 0xffff0000);
+ try testing.expect((try a.to(u64)) == 0xffff0000);
}
test "big.int shift-left multi" {
@@ -1308,7 +1308,7 @@ test "big.int shift-left multi" {
defer a.deinit();
try a.shiftLeft(a, 67);
- testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
+ try testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
}
test "big.int shift-right negative" {
@@ -1318,12 +1318,12 @@ test "big.int shift-right negative" {
var arg = try Managed.initSet(testing.allocator, -20);
defer arg.deinit();
try a.shiftRight(arg, 2);
- testing.expect((try a.to(i32)) == -20 >> 2);
+ try testing.expect((try a.to(i32)) == -20 >> 2);
var arg2 = try Managed.initSet(testing.allocator, -5);
defer arg2.deinit();
try a.shiftRight(arg2, 10);
- testing.expect((try a.to(i32)) == -5 >> 10);
+ try testing.expect((try a.to(i32)) == -5 >> 10);
}
test "big.int shift-left negative" {
@@ -1333,7 +1333,7 @@ test "big.int shift-left negative" {
var arg = try Managed.initSet(testing.allocator, -10);
defer arg.deinit();
try a.shiftRight(arg, 1232);
- testing.expect((try a.to(i32)) == -10 >> 1232);
+ try testing.expect((try a.to(i32)) == -10 >> 1232);
}
test "big.int bitwise and simple" {
@@ -1344,7 +1344,7 @@ test "big.int bitwise and simple" {
try a.bitAnd(a, b);
- testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
+ try testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
}
test "big.int bitwise and multi-limb" {
@@ -1355,7 +1355,7 @@ test "big.int bitwise and multi-limb" {
try a.bitAnd(a, b);
- testing.expect((try a.to(u128)) == 0);
+ try testing.expect((try a.to(u128)) == 0);
}
test "big.int bitwise xor simple" {
@@ -1366,7 +1366,7 @@ test "big.int bitwise xor simple" {
try a.bitXor(a, b);
- testing.expect((try a.to(u64)) == 0x1111111133333333);
+ try testing.expect((try a.to(u64)) == 0x1111111133333333);
}
test "big.int bitwise xor multi-limb" {
@@ -1377,7 +1377,7 @@ test "big.int bitwise xor multi-limb" {
try a.bitXor(a, b);
- testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
}
test "big.int bitwise or simple" {
@@ -1388,7 +1388,7 @@ test "big.int bitwise or simple" {
try a.bitOr(a, b);
- testing.expect((try a.to(u64)) == 0xffffffff33333333);
+ try testing.expect((try a.to(u64)) == 0xffffffff33333333);
}
test "big.int bitwise or multi-limb" {
@@ -1400,7 +1400,7 @@ test "big.int bitwise or multi-limb" {
try a.bitOr(a, b);
// TODO: big.int.cpp or is wrong on multi-limb.
- testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
}
test "big.int var args" {
@@ -1410,15 +1410,15 @@ test "big.int var args" {
var b = try Managed.initSet(testing.allocator, 6);
defer b.deinit();
try a.add(a.toConst(), b.toConst());
- testing.expect((try a.to(u64)) == 11);
+ try testing.expect((try a.to(u64)) == 11);
var c = try Managed.initSet(testing.allocator, 11);
defer c.deinit();
- testing.expect(a.order(c) == .eq);
+ try testing.expect(a.order(c) == .eq);
var d = try Managed.initSet(testing.allocator, 14);
defer d.deinit();
- testing.expect(a.order(d) != .gt);
+ try testing.expect(a.order(d) != .gt);
}
test "big.int gcd non-one small" {
@@ -1431,7 +1431,7 @@ test "big.int gcd non-one small" {
try r.gcd(a, b);
- testing.expect((try r.to(u32)) == 1);
+ try testing.expect((try r.to(u32)) == 1);
}
test "big.int gcd non-one small" {
@@ -1444,7 +1444,7 @@ test "big.int gcd non-one small" {
try r.gcd(a, b);
- testing.expect((try r.to(u32)) == 38);
+ try testing.expect((try r.to(u32)) == 38);
}
test "big.int gcd non-one large" {
@@ -1457,7 +1457,7 @@ test "big.int gcd non-one large" {
try r.gcd(a, b);
- testing.expect((try r.to(u32)) == 4369);
+ try testing.expect((try r.to(u32)) == 4369);
}
test "big.int gcd large multi-limb result" {
@@ -1471,7 +1471,7 @@ test "big.int gcd large multi-limb result" {
try r.gcd(a, b);
const answer = (try r.to(u256));
- testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
+ try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
}
test "big.int gcd one large" {
@@ -1484,7 +1484,7 @@ test "big.int gcd one large" {
try r.gcd(a, b);
- testing.expect((try r.to(u64)) == 1);
+ try testing.expect((try r.to(u64)) == 1);
}
test "big.int mutable to managed" {
@@ -1495,7 +1495,7 @@ test "big.int mutable to managed" {
var a = Mutable.init(limbs_buf, 0xdeadbeef);
var a_managed = a.toManaged(allocator);
- testing.expect(a.toConst().eq(a_managed.toConst()));
+ try testing.expect(a.toConst().eq(a_managed.toConst()));
}
test "big.int const to managed" {
@@ -1505,7 +1505,7 @@ test "big.int const to managed" {
var b = try a.toConst().toManaged(testing.allocator);
defer b.deinit();
- testing.expect(a.toConst().eq(b.toConst()));
+ try testing.expect(a.toConst().eq(b.toConst()));
}
test "big.int pow" {
@@ -1514,10 +1514,10 @@ test "big.int pow" {
defer a.deinit();
try a.pow(a.toConst(), 3);
- testing.expectEqual(@as(i32, -27), try a.to(i32));
+ try testing.expectEqual(@as(i32, -27), try a.to(i32));
try a.pow(a.toConst(), 4);
- testing.expectEqual(@as(i32, 531441), try a.to(i32));
+ try testing.expectEqual(@as(i32, 531441), try a.to(i32));
}
{
var a = try Managed.initSet(testing.allocator, 10);
@@ -1531,11 +1531,11 @@ test "big.int pow" {
// y and a are aliased
try a.pow(a.toConst(), 123);
- testing.expect(a.eq(y));
+ try testing.expect(a.eq(y));
const ys = try y.toString(testing.allocator, 16, false);
defer testing.allocator.free(ys);
- testing.expectEqualSlices(
+ try testing.expectEqualSlices(
u8,
"183425a5f872f126e00a5ad62c839075cd6846c6fb0230887c7ad7a9dc530fcb" ++
"4933f60e8000000000000000000000000000000",
@@ -1548,17 +1548,17 @@ test "big.int pow" {
defer a.deinit();
try a.pow(a.toConst(), 100);
- testing.expectEqual(@as(i32, 0), try a.to(i32));
+ try testing.expectEqual(@as(i32, 0), try a.to(i32));
try a.set(1);
try a.pow(a.toConst(), 0);
- testing.expectEqual(@as(i32, 1), try a.to(i32));
+ try testing.expectEqual(@as(i32, 1), try a.to(i32));
try a.pow(a.toConst(), 100);
- testing.expectEqual(@as(i32, 1), try a.to(i32));
+ try testing.expectEqual(@as(i32, 1), try a.to(i32));
try a.set(-1);
try a.pow(a.toConst(), 15);
- testing.expectEqual(@as(i32, -1), try a.to(i32));
+ try testing.expectEqual(@as(i32, -1), try a.to(i32));
try a.pow(a.toConst(), 16);
- testing.expectEqual(@as(i32, 1), try a.to(i32));
+ try testing.expectEqual(@as(i32, 1), try a.to(i32));
}
}
diff --git a/lib/std/math/big/rational.zig b/lib/std/math/big/rational.zig
index 2299205e7b..987889feca 100644
--- a/lib/std/math/big/rational.zig
+++ b/lib/std/math/big/rational.zig
@@ -473,7 +473,7 @@ pub const Rational = struct {
};
fn extractLowBits(a: Int, comptime T: type) T {
- testing.expect(@typeInfo(T) == .Int);
+ debug.assert(@typeInfo(T) == .Int);
const t_bits = @typeInfo(T).Int.bits;
const limb_bits = @typeInfo(Limb).Int.bits;
@@ -498,19 +498,19 @@ test "big.rational extractLowBits" {
defer a.deinit();
const a1 = extractLowBits(a, u8);
- testing.expect(a1 == 0x21);
+ try testing.expect(a1 == 0x21);
const a2 = extractLowBits(a, u16);
- testing.expect(a2 == 0x4321);
+ try testing.expect(a2 == 0x4321);
const a3 = extractLowBits(a, u32);
- testing.expect(a3 == 0x87654321);
+ try testing.expect(a3 == 0x87654321);
const a4 = extractLowBits(a, u64);
- testing.expect(a4 == 0x1234567887654321);
+ try testing.expect(a4 == 0x1234567887654321);
const a5 = extractLowBits(a, u128);
- testing.expect(a5 == 0x11112222333344441234567887654321);
+ try testing.expect(a5 == 0x11112222333344441234567887654321);
}
test "big.rational set" {
@@ -518,28 +518,28 @@ test "big.rational set" {
defer a.deinit();
try a.setInt(5);
- testing.expect((try a.p.to(u32)) == 5);
- testing.expect((try a.q.to(u32)) == 1);
+ try testing.expect((try a.p.to(u32)) == 5);
+ try testing.expect((try a.q.to(u32)) == 1);
try a.setRatio(7, 3);
- testing.expect((try a.p.to(u32)) == 7);
- testing.expect((try a.q.to(u32)) == 3);
+ try testing.expect((try a.p.to(u32)) == 7);
+ try testing.expect((try a.q.to(u32)) == 3);
try a.setRatio(9, 3);
- testing.expect((try a.p.to(i32)) == 3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 3);
+ try testing.expect((try a.q.to(i32)) == 1);
try a.setRatio(-9, 3);
- testing.expect((try a.p.to(i32)) == -3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -3);
+ try testing.expect((try a.q.to(i32)) == 1);
try a.setRatio(9, -3);
- testing.expect((try a.p.to(i32)) == -3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -3);
+ try testing.expect((try a.q.to(i32)) == 1);
try a.setRatio(-9, -3);
- testing.expect((try a.p.to(i32)) == 3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 3);
+ try testing.expect((try a.q.to(i32)) == 1);
}
test "big.rational setFloat" {
@@ -547,24 +547,24 @@ test "big.rational setFloat" {
defer a.deinit();
try a.setFloat(f64, 2.5);
- testing.expect((try a.p.to(i32)) == 5);
- testing.expect((try a.q.to(i32)) == 2);
+ try testing.expect((try a.p.to(i32)) == 5);
+ try testing.expect((try a.q.to(i32)) == 2);
try a.setFloat(f32, -2.5);
- testing.expect((try a.p.to(i32)) == -5);
- testing.expect((try a.q.to(i32)) == 2);
+ try testing.expect((try a.p.to(i32)) == -5);
+ try testing.expect((try a.q.to(i32)) == 2);
try a.setFloat(f32, 3.141593);
// = 3.14159297943115234375
- testing.expect((try a.p.to(u32)) == 3294199);
- testing.expect((try a.q.to(u32)) == 1048576);
+ try testing.expect((try a.p.to(u32)) == 3294199);
+ try testing.expect((try a.q.to(u32)) == 1048576);
try a.setFloat(f64, 72.141593120712409172417410926841290461290467124);
// = 72.1415931207124145885245525278151035308837890625
- testing.expect((try a.p.to(u128)) == 5076513310880537);
- testing.expect((try a.q.to(u128)) == 70368744177664);
+ try testing.expect((try a.p.to(u128)) == 5076513310880537);
+ try testing.expect((try a.q.to(u128)) == 70368744177664);
}
test "big.rational setFloatString" {
@@ -574,8 +574,8 @@ test "big.rational setFloatString" {
try a.setFloatString("72.14159312071241458852455252781510353");
// = 72.1415931207124145885245525278151035308837890625
- testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
- testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
+ try testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
+ try testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
}
test "big.rational toFloat" {
@@ -584,11 +584,11 @@ test "big.rational toFloat" {
// = 3.14159297943115234375
try a.setRatio(3294199, 1048576);
- testing.expect((try a.toFloat(f64)) == 3.14159297943115234375);
+ try testing.expect((try a.toFloat(f64)) == 3.14159297943115234375);
// = 72.1415931207124145885245525278151035308837890625
try a.setRatio(5076513310880537, 70368744177664);
- testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
+ try testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
}
test "big.rational set/to Float round-trip" {
@@ -599,7 +599,7 @@ test "big.rational set/to Float round-trip" {
while (i < 512) : (i += 1) {
const r = prng.random.float(f64);
try a.setFloat(f64, r);
- testing.expect((try a.toFloat(f64)) == r);
+ try testing.expect((try a.toFloat(f64)) == r);
}
}
@@ -611,8 +611,8 @@ test "big.rational copy" {
defer b.deinit();
try a.copyInt(b);
- testing.expect((try a.p.to(u32)) == 5);
- testing.expect((try a.q.to(u32)) == 1);
+ try testing.expect((try a.p.to(u32)) == 5);
+ try testing.expect((try a.q.to(u32)) == 1);
var c = try Int.initSet(testing.allocator, 7);
defer c.deinit();
@@ -620,8 +620,8 @@ test "big.rational copy" {
defer d.deinit();
try a.copyRatio(c, d);
- testing.expect((try a.p.to(u32)) == 7);
- testing.expect((try a.q.to(u32)) == 3);
+ try testing.expect((try a.p.to(u32)) == 7);
+ try testing.expect((try a.q.to(u32)) == 3);
var e = try Int.initSet(testing.allocator, 9);
defer e.deinit();
@@ -629,8 +629,8 @@ test "big.rational copy" {
defer f.deinit();
try a.copyRatio(e, f);
- testing.expect((try a.p.to(u32)) == 3);
- testing.expect((try a.q.to(u32)) == 1);
+ try testing.expect((try a.p.to(u32)) == 3);
+ try testing.expect((try a.q.to(u32)) == 1);
}
test "big.rational negate" {
@@ -638,16 +638,16 @@ test "big.rational negate" {
defer a.deinit();
try a.setInt(-50);
- testing.expect((try a.p.to(i32)) == -50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.negate();
- testing.expect((try a.p.to(i32)) == 50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.negate();
- testing.expect((try a.p.to(i32)) == -50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -50);
+ try testing.expect((try a.q.to(i32)) == 1);
}
test "big.rational abs" {
@@ -655,16 +655,16 @@ test "big.rational abs" {
defer a.deinit();
try a.setInt(-50);
- testing.expect((try a.p.to(i32)) == -50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.abs();
- testing.expect((try a.p.to(i32)) == 50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.abs();
- testing.expect((try a.p.to(i32)) == 50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 50);
+ try testing.expect((try a.q.to(i32)) == 1);
}
test "big.rational swap" {
@@ -676,19 +676,19 @@ test "big.rational swap" {
try a.setRatio(50, 23);
try b.setRatio(17, 3);
- testing.expect((try a.p.to(u32)) == 50);
- testing.expect((try a.q.to(u32)) == 23);
+ try testing.expect((try a.p.to(u32)) == 50);
+ try testing.expect((try a.q.to(u32)) == 23);
- testing.expect((try b.p.to(u32)) == 17);
- testing.expect((try b.q.to(u32)) == 3);
+ try testing.expect((try b.p.to(u32)) == 17);
+ try testing.expect((try b.q.to(u32)) == 3);
a.swap(&b);
- testing.expect((try a.p.to(u32)) == 17);
- testing.expect((try a.q.to(u32)) == 3);
+ try testing.expect((try a.p.to(u32)) == 17);
+ try testing.expect((try a.q.to(u32)) == 3);
- testing.expect((try b.p.to(u32)) == 50);
- testing.expect((try b.q.to(u32)) == 23);
+ try testing.expect((try b.p.to(u32)) == 50);
+ try testing.expect((try b.q.to(u32)) == 23);
}
test "big.rational order" {
@@ -699,11 +699,11 @@ test "big.rational order" {
try a.setRatio(500, 231);
try b.setRatio(18903, 8584);
- testing.expect((try a.order(b)) == .lt);
+ try testing.expect((try a.order(b)) == .lt);
try a.setRatio(890, 10);
try b.setRatio(89, 1);
- testing.expect((try a.order(b)) == .eq);
+ try testing.expect((try a.order(b)) == .eq);
}
test "big.rational add single-limb" {
@@ -714,11 +714,11 @@ test "big.rational add single-limb" {
try a.setRatio(500, 231);
try b.setRatio(18903, 8584);
- testing.expect((try a.order(b)) == .lt);
+ try testing.expect((try a.order(b)) == .lt);
try a.setRatio(890, 10);
try b.setRatio(89, 1);
- testing.expect((try a.order(b)) == .eq);
+ try testing.expect((try a.order(b)) == .eq);
}
test "big.rational add" {
@@ -734,7 +734,7 @@ test "big.rational add" {
try a.add(a, b);
try r.setRatio(984786924199, 290395044174);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational sub" {
@@ -750,7 +750,7 @@ test "big.rational sub" {
try a.sub(a, b);
try r.setRatio(979040510045, 290395044174);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational mul" {
@@ -766,7 +766,7 @@ test "big.rational mul" {
try a.mul(a, b);
try r.setRatio(571481443, 17082061422);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational div" {
@@ -782,7 +782,7 @@ test "big.rational div" {
try a.div(a, b);
try r.setRatio(75531824394, 221015929);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational div" {
@@ -795,11 +795,11 @@ test "big.rational div" {
a.invert();
try r.setRatio(23341, 78923);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
try a.setRatio(-78923, 23341);
a.invert();
try r.setRatio(-23341, 78923);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}