tests.l 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. (def import (fn path (eval (read (recv (open path))))))
  2. (import "/sd/os/lib.l")
  3. (def foo (fn "foo"))
  4. (foo)
  5. (cons 1 2)
  6. (cons "foo" 1)
  7. (cons 1 "foo")
  8. (cons "a" (cons "b" "c"))
  9. (def test (fn tn tx (print (list "test " tn (if tx "OK" "FAIL")))))
  10. (def = eq)
  11. (def not (fn a (if a 0 1)))
  12. (test 1 (= 1 1))
  13. (test 2 (= 2 2))
  14. (test 3 (not (= 1 0)))
  15. (test 4 (not (= 0 1)))
  16. (test 6 (= + +))
  17. (test 7 (= (+ 1 2) (+ 2 1)))
  18. (test 8 (def a 1))
  19. (test 9 (not (= a (def b (+ a 1)))))
  20. (test 10 (= a a))
  21. (test 11 (= b 2))
  22. (test 12 (= 4 (do 1 2 "foo" 4)))
  23. (test 13 (= 3 (size (do 1 2 "foo"))))
  24. (def fib (fn n 0))
  25. (def fib (fn n (if (lt n 3) 1
  26. (+ (fib (- n 1)) (fib (- n 2))) )))
  27. (test 14 (= (fib 10) 55))
  28. (def foo (fn a b (+ a b)))
  29. (test 15 (do (def a 5) (def b 6) (= (foo (+ a 1) (- b 2)) 10)))
  30. (def func-a (fn xx yy (* (+ xx 1) (+ yy 1))))
  31. (def func-b (fn x y (func-a x y)))
  32. (test 16 (= 12 (strlen (concat "hello" "worlden"))))
  33. (test 17 (= (get [65] 0) (get "beef" 1)))
  34. (test 18 (= (get [66] 0) (get "beef" 3)))
  35. (test 19 (lt 4 500))
  36. (test 20 (gt -2 -4))
  37. (test 21 (eq 666 (* -1 -666)))
  38. (test 22 (= (get (substr "hellaz" 1 3) 0) 101))