Create a unit7 for all unit tests.

This commit is contained in:
Christoffer Lerno
2025-02-24 01:05:45 +01:00
parent 70029cc4b8
commit 87725a3a9e
128 changed files with 9311 additions and 103 deletions

View File

@@ -0,0 +1,32 @@
module arraytests @test;
fn void find()
{
int[3] a = { 1, 2, 3 };
assert(array::index_of(a, 2)!! == 1);
assert(array::index_of(a, 1)!! == 0);
assert(array::index_of(a, 3)!! == 2);
assert(@catch(array::index_of(a, 4)) == SearchResult.MISSING);
}
fn void find_subarray()
{
int[] a = { 1, 2, 3 };
assert(array::index_of(a, 2)!! == 1);
assert(array::index_of(a, 1)!! == 0);
assert(array::index_of(a, 3)!! == 2);
assert(@catch(array::index_of(a, 4)) == SearchResult.MISSING);
}
fn void concat()
{
int[3] a = { 1, 2, 3 };
free(array::concat_new(a, a));
free(array::concat_new(a[..], a[..]));
free(array::concat_new(a[:0], a[:0]));
free(array::concat_new((int[2]) { 1, 2 }, a[:0]));
free(array::concat_new(a[:0], (int[2]) { 1, 2 }));
int[] c = array::concat_new(a[1..2], a);
defer free(c);
assert (c == (int[]){ 2, 3, 1, 2, 3 });
}