commit 97f1ccbe65c361638b09a655691b95f9de2c25cb
parent 74ca29ea90c0f4c97bffc6f07eca74f1224ddb9c
Author: Ed van Bruggen <edvb@uw.edu>
Date: Wed, 4 Sep 2019 02:31:38 -0700
Add int and rounding function tests
Diffstat:
test.c | | | 89 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- |
1 file changed, 61 insertions(+), 28 deletions(-)
diff --git a/test.c b/test.c
@@ -226,41 +226,74 @@ char *tests[][2] = {
{ "(last '(a b c d e f))", "f" },
{ "(last (cons 1 (cons 2 ())))", "2" },
- { "append", NULL },
- { "(append '(1 2 3) '(4 5 6))", "(1 2 3 4 5 6)" },
- { "(append (list (+ 1 2) 4) '(a b c))", "(3 4 a b c)" },
-
- { "assoc", NULL },
- { "(assoc 'baz '((foo 3) (bar 8) (baz 14)))", "(baz 14)" },
- { "(assoc 'a '((a b) (3 2.1) (3.2 4/3) (3.2 3.2)))", "(a b)" },
- { "(assoc 3 '((1 b)))", "()" },
-
- { "member?", NULL },
- { "(member? 'foo '(foo bar baz))", "t" },
- { "(member? 'bar '(foo bar baz))", "t" },
- { "(member? 4 '(12 38 4 8))", "t" },
- { "(member? 3.2 '(4/3 2 8 2 3.14 3.2))", "t" },
- { "(member? \"quux\" (list 4.2 3 'quux))", "()" },
- { "(member? 'qux '(foo bar baz))", "()" },
- { "numerator", NULL },
- { "(numerator 3/2)", "3" },
- { "(numerator 1/2)", "1" },
- { "(numerator -4/2)", "-2" },
- { "(numerator 24)", "24" },
+ { "append", NULL },
+ { "(append '(1 2 3) '(4 5 6))", "(1 2 3 4 5 6)" },
+ { "(append (list (+ 1 2) 4) '(a b c))", "(3 4 a b c)" },
+
+ { "assoc", NULL },
+ { "(assoc 'baz '((foo 3) (bar 8) (baz 14)))", "(baz 14)" },
+ { "(assoc 'a '((a b) (3 2.1) (3.2 4/3) (3.2 3.2)))", "(a b)" },
+ { "(assoc 3 '((1 b)))", "()" },
+
+ { "member?", NULL },
+ { "(member? 'foo '(foo bar baz))", "t" },
+ { "(member? 'bar '(foo bar baz))", "t" },
+ { "(member? 4 '(12 38 4 8))", "t" },
+ { "(member? 3.2 '(4/3 2 8 2 3.14 3.2))", "t" },
+ { "(member? \"quux\" (list 4.2 3 'quux))", "()" },
+ { "(member? 'qux '(foo bar baz))", "()" },
- { "denominator", NULL },
+ { "num/den", NULL },
+ { "(numerator 3/2)", "3" },
+ { "(numerator 1/2)", "1" },
+ { "(numerator -4/2)", "-2" },
+ { "(numerator 24)", "24" },
{ "(denominator 1/4)", "4" },
{ "(denominator 4/3)", "3" },
{ "(denominator 4/2)", "1" },
{ "(denominator 14/8)", "4" },
{ "(denominator -4)", "1" },
- { "dec", NULL },
- { "(dec 1/2)", "0.5" },
- { "(dec 3/-2)", "-1.5" },
- { "(dec 1)", "1.0" },
- { "(dec 3.14)", "3.14" },
+ { "dec/int", NULL },
+ { "(dec 1/2)", "0.5" },
+ { "(dec 3/-2)", "-1.5" },
+ { "(dec 1)", "1.0" },
+ { "(dec 3.14)", "3.14" },
+ { "(int 1/2)", "0" },
+ { "(int 3/-2)", "-1" },
+ { "(int 1)", "1" },
+ { "(int 3.14)", "3" },
+
+ { "round", NULL },
+ { "(round 7/3)", "2" },
+ { "(round -3/4)", "-1" },
+ { "(round 6.3)", "6.0" },
+ { "(round -8.1)", "-8.0" },
+ { "(round 3)", "3" },
+ { "(round -81)", "-81" },
+ { "(round 0)", "0" },
+ { "(floor 5/3)", "1" },
+ { "(floor -9/4)", "-3" },
+ { "(floor 6.3)", "6.0" },
+ { "(floor -8.1)", "-9.0" },
+ { "(floor 3)", "3" },
+ { "(floor -81)", "-81" },
+ { "(floor 0)", "0" },
+ { "(ceil 1/2)", "1" },
+ { "(ceil -8/5)", "-1" },
+ { "(ceil pi)", "4.0" },
+ { "(ceil (- .2))", "-0.0" },
+ { "(ceil 128)", "128" },
+ { "(ceil -2)", "-2" },
+ { "(ceil 0)", "0" },
+ { "(truncate (/ 17 2))", "8" },
+ { "(truncate -12/5)", "-2" },
+ { "(truncate (exp 2.))", "7.0" },
+ { "(truncate 124.1380)", "124.0" },
+ { "(truncate 8)", "8" },
+ { "(truncate -5)", "-5" },
+ { "(truncate 0)", "0" },
{ "add", NULL },
{ "(+ 1 1)", "2" },
@@ -405,7 +438,7 @@ main(void)
{
int correct = 0, total = 0, seccorrect = 0, sectotal = 0, last = 1;
int errors[LEN(tests)] = {0};
- Env env = tisp_env_init(64);
+ Env env = tisp_env_init(1024);
tib_env_math(env);
tisp_eval(env, tisp_parse_file(env, "tibs/lib.tsp"));