You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.9 KiB
78 lines
1.9 KiB
#include "ptlisp-test.h" |
|
#include "../src/lisp.h" |
|
|
|
START_TEST(table_create_test) { |
|
Pointer tbl = table(3); |
|
ck_assert_uint_eq(TABLE(tbl).length, 0); |
|
ck_assert_uint_eq(TABLE(tbl).size, 4); |
|
} |
|
END_TEST |
|
|
|
START_TEST(table_get_existent_test) { |
|
Pointer tbl = table(3); |
|
tbl = table_set(tbl, 1, 2); |
|
ck_assert_uint_eq(table_get(tbl, 1), 2); |
|
} |
|
END_TEST |
|
|
|
START_TEST(table_get_unexistent_test) { |
|
ck_assert_uint_eq(table_get(table(3), 1), UNDEFINED); |
|
} |
|
END_TEST |
|
|
|
START_TEST(table_set_existent_test) { |
|
Pointer tbl = table(3); |
|
tbl = table_set(tbl, 1, 2); |
|
tbl = table_set(tbl, 1, 69); |
|
ck_assert_uint_eq(table_get(tbl, 1), 69); |
|
ck_assert_uint_eq(TABLE(tbl).length, 1); |
|
} |
|
END_TEST |
|
|
|
START_TEST(table_set_unexistent_test) { |
|
Pointer tbl = table(3); |
|
tbl = table_set(tbl, 1, 2); |
|
ck_assert_uint_eq(table_get(tbl, 1), 2); |
|
ck_assert_uint_eq(TABLE(tbl).length, 1); |
|
} |
|
END_TEST |
|
|
|
START_TEST(table_set_many_test) { |
|
Pointer tbl = table(8); |
|
tbl = table_set(tbl, 1, 1); |
|
tbl = table_set(tbl, 2, 2); |
|
tbl = table_set(tbl, 3, 3); |
|
tbl = table_set(tbl, 4, 4); |
|
tbl = table_set(tbl, 5, 5); |
|
ck_assert_uint_eq(table_get(tbl, 1), 1); |
|
ck_assert_uint_eq(table_get(tbl, 2), 2); |
|
ck_assert_uint_eq(table_get(tbl, 3), 3); |
|
ck_assert_uint_eq(table_get(tbl, 4), 4); |
|
ck_assert_uint_eq(table_get(tbl, 5), 5); |
|
ck_assert_uint_eq(TABLE(tbl).length, 5); |
|
} |
|
END_TEST |
|
|
|
static void setup(void) { |
|
memory_init(16); |
|
} |
|
|
|
static void teardown(void) { |
|
memory_free(); |
|
} |
|
|
|
Suite* make_table_test_suite(void) { |
|
Suite *s1 = suite_create("Table"); |
|
TCase *tc1_1 = tcase_create("Table"); |
|
suite_add_tcase(s1, tc1_1); |
|
|
|
tcase_add_checked_fixture(tc1_1, setup, teardown); |
|
tcase_add_test(tc1_1, table_create_test); |
|
tcase_add_test(tc1_1, table_get_existent_test); |
|
tcase_add_test(tc1_1, table_get_unexistent_test); |
|
tcase_add_test(tc1_1, table_set_existent_test); |
|
tcase_add_test(tc1_1, table_set_unexistent_test); |
|
tcase_add_test(tc1_1, table_set_many_test); |
|
|
|
return s1; |
|
}
|
|
|