mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
First 0.7 update, removing all deprecated features.
This commit is contained in:
committed by
Christoffer Lerno
parent
cff6697818
commit
2a895ec7be
@@ -1,100 +1,100 @@
|
||||
module sort_test @test;
|
||||
import std::math;
|
||||
import std::sort;
|
||||
import sort::check;
|
||||
import std::collections::list;
|
||||
import std::math;
|
||||
import std::sort;
|
||||
import sort::check;
|
||||
import std::collections::list;
|
||||
|
||||
fn void countingsort()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
fn void countingsort()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
|
||||
fn void countingsort_with_ref()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
fn void countingsort_with_ref()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, &sort::key_int_ref);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, &sort::key_int_ref);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
|
||||
fn void countingsort_with_value()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
fn void countingsort_with_value()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
|
||||
fn void countingsort_with_lambda()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
fn void countingsort_with_lambda()
|
||||
{
|
||||
int[][] tcases =
|
||||
{
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, fn uint(int a) => ((uint)(a + int.min)));
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, fn uint(int a) => ((uint)(a + int.min)));
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
|
||||
def CountingSortTestList = List(<int>);
|
||||
def CountingSortTestList = List{int};
|
||||
|
||||
fn void countingsort_list()
|
||||
{
|
||||
CountingSortTestList list;
|
||||
list.tinit();
|
||||
list.add_array({ 2, 1, 3});
|
||||
sort::countingsort(list, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(list.array_view()));
|
||||
}
|
||||
fn void countingsort_list()
|
||||
{
|
||||
CountingSortTestList list;
|
||||
list.add_array({ 2, 1, 3});
|
||||
sort::countingsort(list, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(list.array_view()));
|
||||
}
|
||||
|
||||
fn void countingsort_random_large_list()
|
||||
{
|
||||
Lcg128Random random;
|
||||
random::seed_entropy(&random);
|
||||
fn void countingsort_random_large_list()
|
||||
{
|
||||
Lcg128Random random;
|
||||
random::seed_entropy(&random);
|
||||
|
||||
CountingSortTestList list;
|
||||
for (usz i = 0; i < 2048; i++) {
|
||||
list.push(random.next_int());
|
||||
}
|
||||
|
||||
sort::countingsort(list, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(list.array_view()));
|
||||
list.free();
|
||||
CountingSortTestList list;
|
||||
for (usz i = 0; i < 2048; i++)
|
||||
{
|
||||
list.push(random.next_int());
|
||||
}
|
||||
|
||||
sort::countingsort(list, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(list.array_view()));
|
||||
list.free();
|
||||
}
|
||||
@@ -78,12 +78,11 @@ fn void insertionsort_with_lambda()
|
||||
}
|
||||
}
|
||||
|
||||
def InsertionSortTestList = List(<int>);
|
||||
def InsertionSortTestList = List{int};
|
||||
|
||||
fn void insertionsort_list()
|
||||
{
|
||||
InsertionSortTestList list;
|
||||
list.tinit();
|
||||
list.add_array({ 2, 1, 3});
|
||||
sort::insertionsort(list, &sort::cmp_int_value);
|
||||
assert(check::int_ascending_sort(list.array_view()));
|
||||
|
||||
@@ -78,12 +78,11 @@ fn void quicksort_with_lambda()
|
||||
}
|
||||
}
|
||||
|
||||
def List = List(<int>);
|
||||
def List = List{int};
|
||||
|
||||
fn void quicksort_list()
|
||||
{
|
||||
List list;
|
||||
list.tinit();
|
||||
list.add_array({ 2, 1, 3});
|
||||
sort::quicksort(list, &sort::cmp_int_value);
|
||||
assert(check::int_sort(list.array_view()));
|
||||
|
||||
@@ -66,13 +66,13 @@ fn void sorted()
|
||||
tc.input, got, tc.want);
|
||||
|
||||
// with list
|
||||
List(<int>) list;
|
||||
List{int} list;
|
||||
list.tinit();
|
||||
list.add_array(tc.input);
|
||||
|
||||
got = is_sorted(list);
|
||||
assert(got == tc.want, "list: %s, got: %s, want: %s",
|
||||
list.to_tstring(), got, tc.want);
|
||||
list, got, tc.want);
|
||||
|
||||
// with lambda
|
||||
got = is_sorted(tc.input, fn int(int a, int b) => a - b);
|
||||
|
||||
Reference in New Issue
Block a user