mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added += and related as overloads. Updated tests and docs. Slice2 extracted to its own file.
This commit is contained in:
@@ -4,10 +4,62 @@ import std::collections::growablebitset;
|
||||
import std::collections::list;
|
||||
import std::io;
|
||||
|
||||
alias List = List{usz};
|
||||
alias List = List {usz};
|
||||
|
||||
alias BitSet = BitSet{2048};
|
||||
alias BitSet = BitSet {2048};
|
||||
|
||||
fn void bit_ops_assign()
|
||||
{
|
||||
BitSet bs;
|
||||
BitSet bs2;
|
||||
bs.set(4);
|
||||
bs.set(6);
|
||||
bs2.set(4);
|
||||
bs2.set(8);
|
||||
BitSet bs3 = bs;
|
||||
bs3 ^= bs2;
|
||||
assert(!bs3.get(4));
|
||||
assert(!bs3.get(5));
|
||||
assert(bs3.get(6));
|
||||
assert(bs3.get(8));
|
||||
BitSet bs4 = bs;
|
||||
bs4 |= bs2;
|
||||
assert(bs4.get(4));
|
||||
assert(!bs4.get(5));
|
||||
assert(bs4.get(6));
|
||||
assert(bs4.get(8));
|
||||
BitSet bs5 = bs;
|
||||
bs5 &= bs2;
|
||||
assert(bs5.get(4));
|
||||
assert(!bs5.get(5));
|
||||
assert(!bs5.get(6));
|
||||
assert(!bs5.get(8));
|
||||
}
|
||||
|
||||
fn void bit_ops()
|
||||
{
|
||||
BitSet bs;
|
||||
BitSet bs2;
|
||||
bs.set(4);
|
||||
bs.set(6);
|
||||
bs2.set(4);
|
||||
bs2.set(8);
|
||||
BitSet bs3 = bs ^ bs2;
|
||||
assert(!bs3.get(4));
|
||||
assert(!bs3.get(5));
|
||||
assert(bs3.get(6));
|
||||
assert(bs3.get(8));
|
||||
BitSet bs4 = bs | bs2;
|
||||
assert(bs4.get(4));
|
||||
assert(!bs4.get(5));
|
||||
assert(bs4.get(6));
|
||||
assert(bs4.get(8));
|
||||
BitSet bs5 = bs & bs2;
|
||||
assert(bs5.get(4));
|
||||
assert(!bs5.get(5));
|
||||
assert(!bs5.get(6));
|
||||
assert(!bs5.get(8));
|
||||
}
|
||||
fn void set_get()
|
||||
{
|
||||
BitSet bs;
|
||||
|
||||
19
test/unit/stdlib/core/slice2d.c3
Normal file
19
test/unit/stdlib/core/slice2d.c3
Normal file
@@ -0,0 +1,19 @@
|
||||
module test_slice @test;
|
||||
|
||||
fn void slice2d()
|
||||
{
|
||||
int[3][2] x = { { 1, 2, 3 }, { 4, 5, 6 }};
|
||||
Slice2d {int} s = array::slice2d(&x);
|
||||
assert(s.len() == 2);
|
||||
assert(s.count() == 6);
|
||||
assert(s.get_xy(1, 1) == 5);
|
||||
assert(s.get_coord({1, 1}) == 5);
|
||||
s.set_coord({ 0, 1 }, 100);
|
||||
assert(x[1][0] == 100);
|
||||
s.set_xy(0, 1, 101);
|
||||
assert(x[1][0] == 101);
|
||||
Slice2d {int} s2 = s.slice(1, 2, 0, 2);
|
||||
assert(s2[0] == { 2, 3 });
|
||||
assert(s2.count() == 4);
|
||||
|
||||
}
|
||||
19
test/unit/stdlib/mem/arena_allocator.c3
Normal file
19
test/unit/stdlib/mem/arena_allocator.c3
Normal file
@@ -0,0 +1,19 @@
|
||||
module allocator_test @test;
|
||||
import std::core::mem;
|
||||
|
||||
|
||||
fn void test_arena_allocator_err()
|
||||
{
|
||||
char[40] data;
|
||||
char[40] empty;
|
||||
ArenaAllocator* foo = allocator::wrap(&data);
|
||||
char* alloc = allocator::malloc(foo, 5);
|
||||
alloc[0] = 3;
|
||||
assert(alloc >= &data[0] && alloc <= &data[^1]);
|
||||
assert(foo.used >= 5);
|
||||
assert(data != empty);
|
||||
test::@error(allocator::malloc_try(foo, 50), mem::INVALID_ALLOC_SIZE);
|
||||
test::@error(allocator::malloc_try(foo, 30), mem::OUT_OF_MEMORY);
|
||||
foo.clear();
|
||||
(void)allocator::malloc(foo, 20);
|
||||
}
|
||||
Reference in New Issue
Block a user