Skip to main content

module demo::lang::Lisra::Test

rascal-0.40.17

Usage

import demo::lang::Lisra::Test;

Dependencies

import demo::lang::Lisra::Runtime;
import demo::lang::Lisra::Eval;

Tests

test eval01

test bool eval01() = eval("42").val == Integer(42);

test eval02

test bool eval02() = eval("x").val == Atom("x");

test eval03

test bool eval03() = eval("(quote 1)").val == Integer(1);

test eval04

test bool eval04() = eval("(quote 1 2)").val == List([Integer(1), Integer(2)]);

test eval05

test bool eval05() = eval("(+ 1 2)").val == Integer(3);

test eval06

test bool eval06() = eval("(- 5 3)").val == Integer(2);

test eval07

test bool eval07() = eval("(* 5 3)").val == Integer(15);

test eval08

test bool eval08() = eval("(\< 3 4)").val != FALSE;

test eval09

test bool eval09() = eval("(\< 3 2)").val == FALSE;

test eval10

test bool eval10() = eval("(\> 3 2)").val != FALSE;

test eval11

test bool eval11() = eval("(\>3 4)").val == FALSE;

test eval12

test bool eval12() = eval("(equal? 3 3)").val != FALSE;

test eval13

test bool eval13() = eval("(equal? 3 2)").val == FALSE;

test eval14

test bool eval14() = eval("(null? ())").val != FALSE;

test eval15

test bool eval15() = eval("(null? (quote 1 2))").val == FALSE;

test eval16

test bool eval16() = eval("(begin (define swap (lambda (a b) (list b a))) (swap 1 2))").val == 
List([Integer(2), Integer(1)]);

test eval17

test bool eval17() = eval("(begin (define * (lambda (a b) (+ a b))) (* 1 2))"). val == Integer(3);

test eval18

test bool eval18() = eval("(begin (set! x 1) x)").val == Integer(1);

test eval19

test bool eval19() = eval("(if (\> 5 2) 10 20)").val == Integer(10);

test eval20

test bool eval20() = eval("(if (\> 2 5) 10 20)").val == Integer(20);

test eval21

test bool eval21() = eval("(begin (define fac (lambda (n) (if (\> n 1) (* n (fac (- n 1))) 1))) (fac 3))").val == Integer(6);

test eval22

test bool eval22() = eval("(begin (define length (lambda (x) (if(null? x) 0 (+ 1 (length (cdr x)))))) (length (quote (1 2 3))))").val == Integer(3);

test eval23

test bool eval23() = eval("(begin (define rev (lambda (x) (if (null? x) () (append (rev (cdr x)) (car x))))) (rev (quote 1 2 3)))").val == List([Integer(3), Integer(2), Integer(1)]);

test eval24

test bool eval24() = eval("(begin (define F (lambda (x) y)) (set! y 10) (F 1))").val == Integer(10);