mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
DString reverse and an initial BigInt implementation (untested),
This commit is contained in:
34
test/unit/stdlib/math/bigint.c3
Normal file
34
test/unit/stdlib/math/bigint.c3
Normal file
@@ -0,0 +1,34 @@
|
||||
module std::math::bigint @test;
|
||||
|
||||
fn void test_plus()
|
||||
{
|
||||
BigInt a = bigint::from_int(123);
|
||||
BigInt b = bigint::from_int(234);
|
||||
assert(a.add(b).equals(bigint::from_int(234 + 123)));
|
||||
|
||||
a = bigint::from_int(12323400012311213314141414i128);
|
||||
b = bigint::from_int(23400012311213314141414i128);
|
||||
assert(a.add(b).equals(bigint::from_int(12323400012311213314141414i128 + 23400012311213314141414i128)));
|
||||
}
|
||||
|
||||
fn void test_minus()
|
||||
{
|
||||
BigInt a = bigint::from_int(123);
|
||||
BigInt b = bigint::from_int(234);
|
||||
assert(a.sub(b).equals(bigint::from_int(123 - 234)));
|
||||
|
||||
a = bigint::from_int(12323400012311213314141414i128);
|
||||
b = bigint::from_int(23400012311213314141414i128);
|
||||
assert(a.sub(b).equals(bigint::from_int(12323400012311213314141414i128 - 23400012311213314141414i128)));
|
||||
}
|
||||
|
||||
fn void test_init_string_radix()
|
||||
{
|
||||
BigInt a;
|
||||
a.init_string_radix("123", 10)!!;
|
||||
assert(a.equals(bigint::from_int(123)));
|
||||
a.init_string_radix("123", 8)!!;
|
||||
assert(a.equals(bigint::from_int(0o123)));
|
||||
a.init_string_radix("123", 16)!!;
|
||||
assert(a.equals(bigint::from_int(0x123)));
|
||||
}
|
||||
Reference in New Issue
Block a user