Add initial stuff
This commit is contained in:
1 parent
2d8bda0fe0
commit
8e9d20ba1a
45 files changed
+8901
No files matched your search
@@ -0,0 +1,77 @@
|
||||
#include "m-list.h"
|
||||
#include "m-array.h"
|
||||
#include "m-string.h"
|
||||
#include "m-algo.h"
|
||||
|
||||
ARRAY_DEF(int, int)
|
||||
|
||||
ALGO_DEF(algo_array, ARRAY_OPLIST(int))
|
||||
|
||||
LIST_DEF(int, int)
|
||||
|
||||
ALGO_DEF(algo_list, LIST_OPLIST(int))
|
||||
|
||||
LIST_DEF(string, string_t, STRING_OPLIST)
|
||||
|
||||
ALGO_DEF(algo_string, LIST_OPLIST(string, STRING_OPLIST))
|
||||
|
||||
static void test_list(void)
|
||||
{
|
||||
list_int_t l;
|
||||
list_int_init(l);
|
||||
for(int i = 0; i < 100; i++)
|
||||
list_int_push_back (l, i);
|
||||
assert( algo_list_contains(l, 62) == true);
|
||||
assert( algo_list_contains(l, -1) == false);
|
||||
|
||||
assert( algo_list_count(l, 1) == 1);
|
||||
list_int_push_back (l, 17);
|
||||
assert( algo_list_count(l, 17) == 2);
|
||||
assert( algo_list_count(l, -1) == 0);
|
||||
|
||||
list_int_clear(l);
|
||||
}
|
||||
|
||||
static void test_array(void)
|
||||
{
|
||||
array_int_t l;
|
||||
array_int_init(l);
|
||||
for(int i = 0; i < 100; i++)
|
||||
array_int_push_back (l, i);
|
||||
assert( algo_array_contains(l, 62) == true);
|
||||
assert( algo_array_contains(l, -1) == false);
|
||||
|
||||
assert( algo_array_count(l, 1) == 1);
|
||||
array_int_push_back (l, 17);
|
||||
assert( algo_array_count(l, 17) == 2);
|
||||
assert( algo_array_count(l, -1) == 0);
|
||||
|
||||
array_int_clear(l);
|
||||
}
|
||||
|
||||
static void test_string(void)
|
||||
{
|
||||
list_string_t l;
|
||||
list_string_init(l);
|
||||
string_t s;
|
||||
string_init_set_str(s, "Hello, World, John");
|
||||
algo_string_split(l, s, ',');
|
||||
list_string_pop_back (&s, l);
|
||||
assert (string_equal_str_p(s, "Hello"));
|
||||
list_string_pop_back (&s, l);
|
||||
assert (string_equal_str_p(s, " World"));
|
||||
list_string_pop_back (&s, l);
|
||||
assert (string_equal_str_p(s, " John"));
|
||||
assert (list_string_empty_p(l));
|
||||
string_clear(s);
|
||||
|
||||
list_string_clear(l);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_list();
|
||||
test_array();
|
||||
test_string();
|
||||
exit(0);
|
||||
}
|
||||
Reference in new issue
Block a user