Add reduce and filter
This commit is contained in:
@@ -29,8 +29,11 @@ void setUp(void) {
|
||||
ucl_scope_put(scope, "cdr", ucl_builtin_create(ucl_builtin_cdr));
|
||||
ucl_scope_put(scope, "nth", ucl_builtin_create(ucl_builtin_nth));
|
||||
ucl_scope_put(scope, "mapcar", ucl_builtin_create(ucl_builtin_mapcar));
|
||||
ucl_scope_put(scope, "filter", ucl_builtin_create(ucl_builtin_filter));
|
||||
ucl_scope_put(scope, "reduce", ucl_builtin_create(ucl_builtin_reduce));
|
||||
ucl_scope_put(scope, "lambda", ucl_special_create(ucl_special_lambda));
|
||||
ucl_scope_put(scope, "quote", ucl_special_create(ucl_special_quote));
|
||||
ucl_scope_put(scope, "%", ucl_builtin_create(ucl_builtin_mod));
|
||||
}
|
||||
|
||||
void tearDown(void) {
|
||||
@@ -226,6 +229,16 @@ void test_eval_defun_gc(void) {
|
||||
TEST_ASSERT_OBJ_INT_V(response, 25);
|
||||
}
|
||||
|
||||
void test_complex(void) {
|
||||
response = eval("(defun sum (elems) (reduce (quote +) elems 0))");
|
||||
|
||||
TEST_ASSERT_OBJ_SYMBOL_V(response, "sum");
|
||||
|
||||
response = eval("(sum (filter (quote (lambda (x) (% x 2))) (list 1 2 3 4 5)))");
|
||||
|
||||
TEST_ASSERT_OBJ_INT_V(response, 9);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
|
||||
@@ -254,6 +267,7 @@ int main(void) {
|
||||
RUN_TEST(test_nth_1);
|
||||
RUN_TEST(test_nth_oob);
|
||||
RUN_TEST(test_eval_defun_gc);
|
||||
RUN_TEST(test_complex);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user