DString reverse and an initial BigInt implementation (untested),

This commit is contained in:
Christoffer Lerno
2024-10-01 22:51:48 +02:00
parent 46ae4353e0
commit 9b49d19224
5 changed files with 1173 additions and 0 deletions

View File

@@ -10,6 +10,20 @@ fn void test_replace()
assert(hello.str_view() == "Hello world where are yoooo? Are yoooo here too?");
}
fn void test_reverse()
{
DString a;
a.append("abcd");
a.reverse();
assert(a.str_view() == "dcba");
a.reverse();
assert(a.str_view() == "abcd");
a.append("e");
assert(a.str_view() == "abcde");
a.reverse();
assert(a.str_view() == "edcba");
}
fn void test_delete()
{
{

View 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)));
}