2 (set 'start-of-qa (time-of-day))
4 ;; General test suite testing functioning of all built in primitives.
6 ;; use from inside the newlisp-x.x.x/ directory
10 ;; or for countries and configurations with decimal
12 ;; ./newlisp qa-comma (for countries and configurations with decimal , )
15 (set (sym "test-:" 'QA) (lambda () true))
16 (context 'Lex) ; predeclare/create context for bayes-train
19 ;; changed for a locale where the comma ',' is the decimal separator
20 ;; instead of the decimal point, i.e. Germany
23 ;; set a locale which uses the decimal comma
28 (set 'unicodelist '(913 914 915 916 937 945 946 947 948 969 32
29 1040 1041 1042 1043 1044 1072 1073 1074 1075 1076 13 10))
31 (set 'utf8str (join (map char unicodelist)))
33 (if (not (= (length (char 937)) 2)) (QA:failed "UTF-8 char: failed"))
36 (= (map char (explode (chop utf8str))) (chop unicodelist))
37 (= (map char (explode (chop utf8str 3))) (chop unicodelist 3))
38 (= (map char (explode (chop utf8str 5))) (chop unicodelist 5)))) (QA:failed "UTF-8 chop: failed"))
40 (if (not (= (map char (explode utf8str)) unicodelist)) (QA:failed "UTF-8 explode: failed"))
42 (if (not (= (map char (explode (upper-case utf8str)))
43 '(913 914 915 916 937 913 914 915 916 937 32 1040 1041 1042 1043 1044 1040 1041 1042 1043 1044 13 10)))
44 (QA:failed "UTF-8 upper-case: failed"))
46 (if (not (= (map char (explode (lower-case utf8str)))
47 '(945 946 947 948 969 945 946 947 948 969 32 1072 1073 1074 1075 1076 1072 1073 1074 1075 1076 13 10)))
48 (QA:failed "UTF-8 lower-case: failed"))
50 (if (not (= (map char (explode (first utf8str))) '(913))) (QA:failed "UTF-8 first: failed"))
52 (if (not (= (map char (explode (last utf8str))) '(10))) (QA:failed "UTF-8 last: failed"))
54 (if (not (= (map char (explode (rest utf8str)))
55 '(914 915 916 937 945 946 947 948 969 32 1040 1041 1042 1043 1044 1072 1073 1074 1075 1076 13 10)))
56 (QA:failed "UTF-8 rest: failed"))
58 (if (not (= (map char (explode (first (rest utf8str)))) '(914))) (QA:failed "UTF-8 first, rest: failed"))
61 (and (= (map char (explode (select utf8str 1 2 3))) '(914 915 916))
62 (= (map char (explode (select utf8str -1 -2 -3))) '(10 13 1076))
63 (= (map char (explode (select utf8str 2 4 6))) '(915 937 946))))
64 (QA:failed "UTF-8 select: failed"))
67 (if (not (= (map char (explode (select utf8str '(1 2 3)))) '(914 915 916))) (QA:failed "UTF-8 select: failed"))
70 (= (map char (explode (nth 1 utf8str))) '(914))
71 (= (map char (explode (nth -5 utf8str))) '(1074))))
72 (QA:failed "UTF-8 nth: failed"))
74 (if (not (= (map char (explode (nth-set 2 utf8str (char 937)))) '(915))) (QA:failed "UTF-8 nth-set: failed"))
76 (if (not (= (map char (explode (set-nth 2 utf8str (char 937))))
77 '(913 914 937 916 937 945 946 947 948 969 32 1040 1041 1042 1043 1044 1072 1073 1074 1075 1076 13 10)))
78 (QA:failed "UTF-8 set-nth: failed"))
83 (global 'global-myvar)
84 (set 'global-myvar 123)
86 ; testing the default functor
88 (define (double:double x) (+ x x))
90 (define (test-default-functor)
92 (= (map double '(1 2 3 4 5)) '(2 4 6 8 10))
93 (= (map 'double '(1 2 3 4 5)) '(2 4 6 8 10))
94 (set 'dflt:dflt '(a b c d e f g))
95 (= (map dflt '(1 2 6)) '(b c g))
101 (sort (eval (default ctx)) >)
102 (= dflt:dflt '(g f e d c b a))
108 ;; get operating system
109 (set 'opsys (& (last (sys-info)) 0xf))
113 (delete-file "junk2"))
115 (set 'failed-messages '())
117 (define (check-case x)
123 (define (check-cond x)
130 (dolist (p (symbols 'MAIN))
131 (if (primitive? (eval p))
133 (set 'sm (sym (append "test-" (string p))))
134 (if (not (lambda? (eval sm)))
137 (define-macro (do-args p)
138 (= (args) '(2 "3 4" 5 (x y)))
143 (push msg failed-messages))
145 (define (file-copy from-file to-file)
146 (set 'in-file (open from-file "read"))
147 (set 'out-file (open to-file "write"))
148 (while (set 'chr (read-char in-file))
150 (write-char out-file chr)))
154 (define (line-count file)
155 (device (open file "read"))
161 (define (myappend x y)
164 (true (cons (first x) (myappend (rest x) y)))))
168 (dolist (sm (symbols 'MAIN))
170 (if (and (primitive? (eval sm)) (< sm 'zzzz))
172 (inc 'sm-cnt (+ (length (name sm)) 1))
177 (print (name sm) " ")
178 (set 'func (eval (sym (append "test-" (string sm)))) )
179 (and (catch (apply func) 'result) result))
181 (failed (string ">>>> " sm " failed " result) )))
184 (define (test-$) (find "a|b" "xtzabc" 0) (= ($ 0) $0))
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; test-functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
192 (and (not (!= -9223372036854775808 (& -9223372036854775808 -1))) (!= "abc" "ABC")
204 (not (catch (%) 'result))))
207 (= -9223372036854775808 (& -9223372036854775808 -1)))
210 (= (* (* 123456789 123456789)) 15241578750190521))
213 (= (+ 999999999999999999 1) 1000000000000000000)
214 (= (+ 9223372036854775807 -9223372036854775808) -1)
215 (= (+ -9223372036854775808 -1) 9223372036854775807)) ; wraps around
218 (= (- 100000000 1) 99999999))
221 (= (/ 15241578750190521 123456789) 123456789)
226 (< -9223372036854775808 9223372036854775807)
227 (< "abcdefg" "abcdefgh")
231 (< '(a b) '(b c) '(c d))
232 (not (< '(a b) '(b d) '(b c)))
233 (< '(((a b))) '(((b c))))
234 (< '(a (b c)) '(a (b d)) '(a (b (d))))
242 (= (<< 1 63) -9223372036854775808))
245 (and (<= -2147483648 2147483647) (<= 1 1,00000001)))
248 (and (= 1,23456789 1,23456789)
249 (= 123456789 123456789)
250 (= '(1 2 3 (4 5) (a b ("CDEFG" "HIJK") 'u 'v 'w))
251 '(1 2 3 (4 5) (a b ("CDEFG" "HIJK") 'u 'v 'w)))
252 (= "éâäáíóúñÑöò" "éâäáíóúñÑöò")
263 (and (> 2147483647 -2147483648) (> "abcdefgh" "abcdefg") (> 1,000000001
279 (and (>= 1 0) (>= 1,00000001 1)))
282 (= (>> 1073741824 30) 1))
285 (and (NaN? (sqrt -1))
289 (NaN? (add 1 (sqrt -1)))
290 (NaN? (abs (sqrt -1)))))
293 (= (^ 1431655765 -1431655766) -1))
296 (and (= (abs -1) 1) (= (abs -9,9) 9,9)))
299 (= 0 (acos (cos (acos (cos 0))))))
302 (= (cosh (acosh 1)) 1))
304 (define (test-add , l)
307 (= 4950 (apply add l)))
309 (define (test-address, s)
311 (= (address s) (last (dump s))))
315 (or (= x 1) (= x 2)))
318 (and (and true true true) (not (and true true nil))))
320 (define (test-append )
322 (= '(1 2 3 4) (append '(1 2) '(3 4)))
323 (= '(1 2 3 4 5) (append '(1 2) '(3) '(4 5)))
324 (= '(1 2 3 4) (append '(1 2) '(3 4) '()))
325 (= '(1 2 3 4 5) (append '(1 2) '(3 4) '() '(5)))
326 (= '(1 2 3 4 5) (append '() '(1 2) '(3 4) '() '(5)))
327 (= '() (append '()) (append '() '()) (append))
328 (= "abcdefg" (append "" "a" "bcd" "" "ef" "g" ""))
330 (set 'A (array 3 2 (sequence 1 6)))
331 (set 'B (array 2 2 (sequence 7 10)))
332 (= (array 5 2 (sequence 1 10)) (append A B))
333 (lambda? (append '(lambda)))
336 (define (test-append-file)
337 (append-file "junk" "ABC")
338 (append-file "junk" "DEF")
339 (= (read-file "junk") "ABCDEF")
343 (define (test-apply )
344 (and (= (apply + '(1 2)) 3)
345 (= (apply append '("a" "b" "c")) "abc")
346 (= (apply (fn (x y) (+ x y)) '(3 4)) 7)
350 (do-args 1 2 "3 4" 5 (x y)))
354 (= (array-list (array 3 2 (sequence 1 6))) '((1 2) (3 4) (5 6)))
355 (set 'A (array 3 2 (sequence 1 6)))
356 (= (array-list (nth 0 A)) '(1 2))
360 (not (catch (nth 10 10 A) 'result))
361 (not (catch (nth -10 -10 A) 'result))
362 (= (nth 0 A) (array 2 '(1 2)))
363 (= (array-list (nth 0 A)) '(1 2))
364 (< (nth 0 A) (nth 1 A))
365 (> (nth 2 A) (nth 1 A))
368 (= (nth-set 1 1 A 1) 4)
369 (< (nth 1 A) (nth 0 A))
372 (define (test-array-list)
373 (set 'a (array 3 4 (sequence 1 12)))
374 (and (array? a) (list? (array-list a))))
376 (define (test-array?) (test-array-list))
379 (= (round (asin (sin (asin (sin 1)))) -9) 1))
382 (= (sinh (asinh 1)) 1))
384 (define (test-assoc )
385 (= (assoc 'b '((a 1) (b 2))) '(b 2)))
387 (define (test-assoc-set)
389 (set 'A '((a 1) (b 2) (c 3)))
390 (= (assoc-set (A 'b) '(b 3)) '(b 2))
391 (= A '((a 1) (b 3) (c 3)))
395 (< (sub 1 (atan (tan (atan (tan 1))))) 1e-15))
397 ; old test broke after Mac OS X update to 10.5.2
398 ; (= 1 (atan (tan (atan (tan 1)))))
401 (< (sub (tanh (atanh 0,5)) 0,5) 0,0000000001))
403 (define (test-atan2 )
404 (= (div (acos 0) (atan 1 1)) 2))
406 (define (test-atom? )
407 (and (atom? 1) (atom? 1,23) (atom? "hello") (atom? 'x) (atom? nil) (atom? true)))
409 (define (test-base64-enc)
411 (= "" (base64-dec (base64-enc "")))
412 (= "1" (base64-dec (base64-enc "1")))
413 (= "12" (base64-dec (base64-enc "12")))
414 (= "123" (base64-dec (base64-enc "123")))
415 (= "1234" (base64-dec (base64-enc "1234")))
418 (define (test-base64-dec)
421 ;; context Lex was previously created
423 (define (test-bayes-train)
425 (= (bayes-train '(F F F B B) '(F B B B B) 'Lex) '(5 5))
426 (> 0,001 (apply add (map sub (bayes-query '(F) Lex) '(0,75 0,25))))
427 (> 0,001 (apply add (map sub (bayes-query '(F) Lex true) '(0,75 0,25))))
428 (> 0,001 (apply add (map sub (bayes-query '(F F) Lex) '(0,8251777681 0,1748222319))))
429 (> 0,001 (apply add (map sub (bayes-query '(F F) Lex true) '(0,9 0,1))))
433 (define (test-bayes-query)
436 (set 'Lex:total '(0 0))
439 (define (test-begin )
447 (< (abs (sub (beta 1 2) 0,5)) 1e-05))
449 (define (test-betai )
450 (< (abs (sub (betai 0,5 5 10) 0,910217)) 1e-05))
453 (bind '((a 1) (b "hello") (c (3 4))))
460 (define (test-binomial )
461 (< (sub (binomial 2 1 0,5) 0,5) 1e-09))
463 (define (test-break )
469 (and (= (check-case 1) "one") (= (check-case 2) "two") (= (check-case
472 (define (test-callback) true)
474 (define (test-catch )
476 (catch (+ 3 4) 'result)
478 (= (catch (+ 3 4)) 7)
479 (= (catch (dotimes (x 100) (if (= x 7) (throw x)))) 7)
485 (define (test-change-dir )
493 (= (format "%c" (char "a" 0)) "a")
494 (= (char "A") 65) (= (char 65) "A")
495 (= (map char (sequence 65 67)) '("A" "B" "C"))
496 (= (char 0) "\000")))
500 (= (chop "newlisp") "newlis")
501 (= (chop "newlisp" 4) "new"))
502 (= (chop "abc" 5) "")
503 (= (chop "abc" -5) "")
504 (= (chop '(a b (c d) e)) '(a b (c d)))
505 (= (chop '(a b (c d) e) 2) '(a b)))
507 (define (test-clean )
509 (= (clean integer? '(1 1,1 2 2,2 3 3,3)) '(1,1 2,2 3,3))
510 (= (clean true? '(a nil b nil c nil)) '(nil nil nil))))
512 (define (test-close , fno)
514 (set 'fno (open "qa-comma" "read"))
518 (= (crc32 "abcdefghijklmnopqrstuvwxyz") 1277644989))
520 (define (test-select-collect )
522 (set 'l '(0 1 2 3 4 5 6 7 8 9))
523 (= (select l '()) '())
524 (= (select l 0 9 9 0 1 8 8 1) '(0 9 9 0 1 8 8 1))
525 (= (select "2001-09-20" 5 6 8 9 0 1 2 3) "09202001")
527 (= (select '(w x y z) a b c) '(w x y))
528 (= (select '(w x y z) (inc 'a) (inc 'b) (inc 'c)) '(x y z))
531 (define (test-command-line )
532 (and (not (command-line nil)) (command-line true)))
538 (not (check-cond 99))
539 (= (cond ((+ 3 4))) 7)
540 (= (cond (nil 1) ('())) '())
541 (= (cond (nil 1) (nil)) nil)
542 (= (cond (nil 1) (true nil)) nil)
544 (= (cond (nil 1) ('() 2)) '())
548 (= (myappend '(1 2 3) '(4 5 6)) '(1 2 3 4 5 6))
549 (= (cons 'c '(a b) -1) '(a b c))
552 (define (test-constant )
555 (define (trick z) (constant 'z 999))
562 (define (test-context )
563 (and (context 'TEST) (context 'QA)))
565 (define (test-context? )
566 (and (context? MAIN) (context? QA)))
568 (define (test-copy-file )
569 (and (copy-file "qa-comma" "junk") (delete-file "junk")))
572 (= 1 (cos (acos (cos (acos 1))))))
575 (= (cosh 1) (div (add (exp 1) (exp -1)) 2)))
577 (define (test-count )
578 (and (= (count '(1 2) '(2 1 2 1)) '(2 2))
579 (= (count '(a b) '(a a b c a b b)) '(3 3))
580 (= (count '(a b c) '()) '(0 0 0))
584 (define (test-cpymem)
587 (cpymem (address from) (address to) 5)
590 (define (test-crit-chi2 )
591 (< (abs (sub (crit-chi2 0,559506 10) 9,999991)) 1e-05))
593 (define (test-crit-z )
594 (< (abs (sub (crit-z 0,999) 3,090232)) 1e-05))
596 (define (test-current-line , handle)
598 (set 'handle (open "qa-comma" "r"))
599 (= (read-line handle) "#!/usr/bin/newlisp")
600 (= (current-line) "#!/usr/bin/newlisp")
605 (= (set 'f (curry + 10)) (lambda (_x) (+ 10 _x)))
606 (= (filter (curry match '(a *)) '((a 10) (b 5) (a 3) (c 8) (a 9)))
607 '((a 10) (a 3) (a 9)))
608 (= (clean (curry match '(a *)) '((a 10) (b 5) (a 3) (c 8) (a 9)))
610 (= (map (curry list 'x) (sequence 1 5))
611 '((x 1) (x 2) (x 3) (x 4) (x 5)))
615 (= (date) (date (date-value)) (date (apply date-value (now)))))
617 (define (test-date-value )
618 (= 0 (date-value 1970 1 1 0 0 0)))
620 (define (test-debug )
621 (= (debug (+ 3 4)) 7))
623 (define (test-dec , x)
625 (and (= 19 (dec 'x)) (= 17 (dec 'x 2)) (= 16,5 (dec 'x 0,5))))
627 (define (test-define , foo)
629 (lambda? (define (foo (x 1) (y 2)) (list x y)))
633 (define (foo (x 10) (y (div x 2))) (list x y))
635 (= (foo 20) '(20 10))
639 (define (test-def-new)
644 (set 'barctx:bar 999)
645 (def-new 'barctx:bar)
647 (def-new 'barctx:bar 'foobar)
649 (def-new 'barctx:bar 'foofoo:foo)
654 (define (test-define-macro , foo)
656 (macro? (define-macro (foo (x 1) (y 2)) (list x y)))
660 (define-macro (foo (x 10) (y (div x 2))) (list x y))
662 (= (foo 20) '(20 10))
666 (define (test-default)
667 (MAIN:test-default-functor))
669 (define (test-delete )
672 (define (test-delete-file )
673 (and (copy-file "qa-comma" "junk") (delete-file "junk")))
675 (define (test-delete-url )
676 (= "ERR: bad formed URL" (delete-url "")))
678 (define (test-destroy)
679 (if (or (< opsys 5)(= opsys 9))
680 (set 'pid (fork (dotimes (t 100) (sleep 100))))
681 (set 'pid (process "newlisp")) )
685 (set 'A '((-1 1 1) (1 4 -5) (1 -2 0)))
686 (< (sub (det A) -1) 2e-10))
688 (define (test-device , fno)
689 (set 'fno (open "junk" "write"))
694 (define (test-difference )
696 (= (difference '(2 5 6 0 3 0 2 5) '(1 2 3 3 2 1)) '(5 6 0))
697 (= (difference '(1 5 2 3 2 2 4 5 3 4 5 1) '(3 4) true) '(1 5 2 2 2 5 5 1))
698 (= (difference '(nil nil nil) '()) '(nil))
699 (= (difference '(nil nil nil) '() true) '(nil nil nil))
703 (define (test-directory )
704 (or (find "qa-comma" (directory)) (find "QA" (directory))))
706 (define (test-directory? )
710 (and (= 0,1 (div 100000000 1000000000))
711 (= (div 1 3) 0,3333333333333333)
712 (= (div 3) 0,3333333333333333)
717 (doargs (i) (push i lst))
720 (define (test-doargs)
721 (= (testdoargs 3 2 1) '(1 2 3)))
723 (define (test-dolist , rList)
725 (dolist (x '(1 2 3 4 5 6 7 8 9))
727 (= rList '(9 8 7 6 5 4 3 2 1))
730 (dolist (x '(1 2 3 4 5 6 7 8 9) (> x 5))
732 (= rList '(5 4 3 2 1))
733 (= (local (l) (dolist (e '(1 2 3)) (push $idx l)) l) '(2 1 0))
734 (= (dolist (x '(a b c d e f g)) x) 'g)
737 (define (test-dostring)
739 (dostring (i "newlisp" (= i 108)) (push i r))
741 (= (dostring (c "newlisp") c) 112)
745 (define (test-dotimes , aList)
751 (= '(1 0 1 0 1 0 1 0) aList)
752 (not (dotimes (x 0) x))
753 (= (dotimes (x 1) x) 0)
755 ; dotimes returns nil when ever executed since 8.9.7
756 (not (= (dotimes (x -1) x) 0))
757 (not (= (dotimes (x -1,8) x) 0))
759 (= (dotimes (x 1,8) x) 0)
761 (dotimes (x 10 (> x 5)) (inc 'cnt))
766 (define (test-dotree )
769 (= (last (symbols MAIN)) (dotree (p MAIN) p))
772 (= (length (symbols 'MAIN)) (length aList))
776 ( = "hello" (get-string (last (dump "hello")))))
778 (define (test-dump-symbol )
779 (= (length (dump nil) 4)))
785 (= (dup "A" 10) "AAAAAAAAAA")
786 (= (dup "AB" 5) "ABABABABAB")
787 (= (dup 'x 5) '(x x x x x))
789 (= (dup '(1) -1) '())
791 (= (dup 1 5) '(1 1 1 1 1))))
793 (define (test-empty? , aList)
794 (set 'aList '(1 2 3 4 5 6 7 8 9 0))
797 (and (empty? aList) (empty? "")))
799 (define (test-encrypt )
800 (= (encrypt (encrypt "newlisp" "123") "123") "newlisp"))
802 (define (test-ends-with )
804 (ends-with "newlisp" "lisp")
805 (ends-with "newlisp" "LISP" nil)
806 (ends-with "abc.def.ghi" "def|ghi" 1)
807 (ends-with "12345" "4|5" 1)
808 (ends-with (explode "newlisp") "p")))
814 (= (env "key") "value")
815 (env "key" "") ; remove key
816 (if (= ostype "Solaris")
822 (< (abs (sub 0,5204998778 (erf 0,5))) 0,000001))
824 (define (alarm) (println "ring..."))
829 (define (test-title-case)
830 (= (title-case "heLLo") "HeLLo")
831 (= (title-case "heLLo" true) "Hello"))
833 (define (test-throw-error)
835 (not (catch (throw-error "message text") 'result))
836 (starts-with result "user error :")) )
838 (define (test-error-event )
839 (= 'nil (error-event)))
841 (define (test-error-number )
842 (integer? (error-number)))
844 (define (test-error-text )
845 (= (error-text 24) "invalid function"))
847 (define (test-eval , x y)
851 (and (= 123 (eval y)) (= 123 (eval 'x)) (= 123 (eval (eval z)))))
853 (define (test-eval-string )
854 (eval-string "(set 'x 123)")
855 (eval-string "(set 'y x)")
856 (and (= 123 (eval-string "y")))
857 (= 123 (eval-string "(blah-blah)" 123))
859 (= 99999 (eval-string "xyz" nil 'Foo))
863 (and (sub-read-exec) (sub-write-exec)))
865 (define (sub-read-exec )
866 (write-file "exectest" {(println "hello") (exit)})
868 (set 'result (if (and (> opsys 5) (< opsys 9))
869 (exec "newlisp exectest") (exec "./newlisp exectest")))
870 (or (= '("hello") result) (= '("" "hello") result))
871 (delete-file "exectest")))
873 (define (sub-write-exec )
875 (write-file "testexec" {(write-file "exectest" (read-line))})
876 (if (> opsys 5) (exec "newlisp testexec" "HELLO") (exec "./newlisp testexec" "HELLO"))
877 (= "HELLO" (read-file "exectest"))
878 (delete-file "testexec")
879 (delete-file "exectest")))
883 (or (primitive? exit) (lambda? exit)))
885 (define (test-exists)
887 (= (exists string? '(2 3 4 6 "hello" 7)) "hello")
888 (not (exists string? '(3 4 2 -7 3 0)) )
889 (= (exists zero? '(3 4 2 -7 3 0)) 0)
890 (= (exists < '(3 4 2 -7 3 0)) -7)
891 (= (exists (fn (x) (> x 3)) '(3 4 2 -7 3 0)) 4)
892 (not (exists (fn (x) (= x 10)) '(3 4 2 -7 3 0)))
896 (= 1 (exp (log (exp (log (exp (log 1))))))))
898 (define (test-expand)
901 (= (expand '(a x b) 'x) '(a 2 b))
902 (= (expand '(x b) 'x) '(2 b))
903 (= (expand '(a x) 'x) '(a 2))
904 (= (expand '(a (x) b) 'x) '(a (2) b))
905 (= (expand '(a ((x)) b) 'x) '(a ((2)) b))
907 (= (expand '(a b c) 'b 'a 'c ) '(1 2 3))
908 ;; prolog mode with uppercase vars
910 (= (expand '(a ((X)) b)) '(a ((2)) b))
911 ;; env list as parameter
912 (set 'a "a" 'B "B" 'c "c" 'd "d")
913 (= (expand '(a (B (c) (d a B))) '((a 1) (B 2) (c 3) (d 4)))
914 '(1 (2 (3) (4 1 2))))
915 (= a "a") (= B "B") (= c "c") (= d "d")
919 (define (test-explode )
921 (= (explode "kakak" -1) '())
922 (= (explode "ABC" 4) '("ABC"))
923 (= (explode '(a b c d e f) -1) '())
924 (= (explode "new") '("n" "e" "w"))
925 (= (explode "newlisp" 3) '("new" "lis" "p"))
926 (= (explode "newlisp" 3 true) '("new" "lis"))
927 (= (explode "newlisp" 7 true) '("newlisp"))
928 (= (explode "newlisp" 8 true) '())
929 (= (explode '(a b c d e)) '((a) (b) (c) (d) (e)))
930 (= (explode '(a b c d e) 2) '((a b) (c d) (e)))
931 (= (explode '(a b c d e)) '((a) (b) (c) (d) (e)))
932 (= (explode '(a b c d e) 2) '((a b) (c d) (e)))
933 (= (explode '(n e w l i s p)) '((n) (e) (w) (l) (i) (s) (p)))
934 (= (explode '(n e w l i s p) 3) '((n e w) (l i s) (p)))
935 (= (explode '(n e w l i s p) 7 true) '((n e w l i s p)))
936 (= (explode '(n e w l i s p) 8 true) '())
939 (define (test-factor)
940 (= (apply * (factor 0x7FFFFFFFFFFFFFFF)) 0x7FFFFFFFFFFFFFFF))
943 (= '((1 2) (3 4)) (ifft (fft '((1 2) (3 4))))))
945 (define (test-file-info )
946 (list? (file-info "qa-comma")))
948 (define (test-file? )
951 (define (test-filter )
953 (= (filter integer? '(1 1,1 2 2,2 3 3,3)) '(1 2 3))
954 (= (filter true? '(a nil b nil c nil)) '(a b c))))
958 (= 3 (find '(3 4) '(0 1 2 (3 4) 5 6 7 8)))
959 (= nil (find 9 '(1 2 3)))
960 (= 2 (find "W" "newlisp" 1))
962 (= (find "newlisp" '("Perl" "Python" "newLISP") 1) 2)
963 ; use a comparison functor
964 (= (find '(1 2) '((1 4) 5 6 (1 2) (8 9))) 3)
965 (= (find 3 '(8 4 3 7 2 6) >) 4)
966 (= (find 5 '((l 3) (k 5) (a 10) (z 22)) (fn (x y) (= x (last y)))) 1)
967 (= (find '(a ?) '((l 3) (k 5) (a 10) (z 22)) match) 2)
968 (= (find '(X X) '((a b) (c d) (e e) (f g)) unify) 2)
969 (define (has-it-as-last x y) (= x (last y)))
970 (= (find 22 '((l 3) (k 5) (a 10) (z 22)) has-it-as-last) 3)
971 (= (find "newlisp" '("Perl" "Python" "newLISP") (fn (x y) (regex x y 1))) 2)
974 (define (test-find-all)
976 (= (find-all {\d+} "asdf2kjh44hgfhgf890") '("2" "44" "890"))
977 (= (find-all {(new)(lisp)} "newLISPisNEWLISP" (append $2 $1) 1) '("LISPnew" "LISPNEW"))
980 (define (test-first )
981 (= 1 (first '(1 2 3 4)))
982 (= "n" (first "ewLISP"))
983 (= (array 2 '(1 2)) (first (array 3 2 (sequence 1 6))))
987 (set 'lst '(a (b (c d))))
988 (= (map (fn (x) (ref x lst)) (flat lst)) '((0) (1 0) (1 1 0) (1 1 1))))
990 (define (test-float )
991 (float? (float "1,234")))
994 (= (flt 1,23) 1067282596))
996 (define (test-float? )
999 (define (test-floor )
1002 (define (test-for , x lst1 lst2)
1007 (for (x 10 0 3 (< x 7))
1010 (= lst1 '(1 4 7 10))
1014 (define (test-for-all)
1016 (for-all number? '(2 3 4 6 7))
1017 (not (for-all number? '(2 3 4 6 "hello" 7)) )
1018 (for-all (fn (x) (= x 10)) '(10 10 10 10 10))
1021 (define (test-fork) (integer? (fork (exit))))
1023 (define (test-format )
1025 (= (format "%d" 1,23) "1")
1026 (= (format "%5.2f" 10) "10,00")
1027 (= (format "%c %s %d %g" 65 "hello" 123 1,23) "A hello 123 1,23")
1028 (= (format "%5.2s" "hello") " he")
1029 ; args passed in a list
1030 (= (format "%d" '(1,23)) "1")
1031 (= (format "%5.2f" '(10)) "10,00")
1032 (= (format "%c %s %d %g" '(65 "hello" 123 1,23)) "A hello 123 1,23")
1033 (= (format "%5.2s" '("hello")) " he")
1034 (set 'data '((1 "a001" "g") (2 "a101" "c") (3 "c220" "g")))
1035 (set 'result (map (fn (x) (format "%3.2f %5s %2s" (nth 0 x) (nth 1 x) (nth 2 x))) data))
1036 (set 'result (map (fn (x) (format "%3.2f %5s %2s" (x 0) (x 1) (x 2))) data))
1037 (= result '("1,00 a001 g" "2,00 a101 c" "3,00 c220 g"))
1038 (not (catch (format "%%" 1) 'result))
1039 (not (catch (format "%10.2lf" 123) 'result))
1041 (if (and (> opsys 5) (< opsys 9) (!= opsys 7)) ;; Win32
1044 (= (format "%I64d" 0x7fffffffffffffff) "9223372036854775807")
1045 (= (format "%I64x" 0x7fffffffffffffff) "7fffffffffffffff")
1046 (= (format "%I64u" 0x7fffffffffffffff) "9223372036854775807")
1047 (= (format "%I64d" 0x8000000000000000) "-9223372036854775808")
1048 (= (format "%I64x" 0x8000000000000000) "8000000000000000")
1049 (= (format "%I64u" 0x8000000000000000) "9223372036854775808")
1050 (= (format "%I64d" 0xFFFFFFFFFFFFFFFF) "-1")
1051 (= (format "%I64x" 0xFFFFFFFFFFFFFFFF) "ffffffffffffffff")
1052 (= (format "%I64u" 0xFFFFFFFFFFFFFFFF) "18446744073709551615"))
1054 (begin ;; UNIX like OS
1055 (if (= opsys 9) ;TRU64
1058 (= (format "%d" 0x7fffffff) "2147483647")
1059 (= (format "%d" 0xffffffff) "-1")
1060 (= (format "%u" 0xffffffff) "4294967295")
1061 (= (format "%i" 0x7fffffff) "2147483647")
1064 (= (format "%d" 0x7fffffffffffffff) "-1")
1065 (= (format "%u" 0x7fffffffffffffff) "4294967295")
1066 (= (format "%x" 0x7fffffffffffffff) "ffffffff")
1067 (= (format "%X" 0x7fffffffffffffff) "FFFFFFFF")
1069 (= (format "%ld" 0x7fffffffffffffff) "9223372036854775807")
1070 (= (format "%lu" 0xffffffffffffffff) "18446744073709551615")
1071 (= (format "%li" 0x7fffffffffffffff) "9223372036854775807")
1072 (= (format "%lx" 0x7fffffffffffffff) "7fffffffffffffff")
1073 (= (format "%ld" 0x8000000000000000) "-9223372036854775808")
1074 (= (format "%lx" 0x8000000000000000) "8000000000000000")
1075 (= (format "%lu" 0x8000000000000000) "9223372036854775808")
1076 (= (format "%ld" 0xFFFFFFFFFFFFFFFF) "-1")
1077 (= (format "%lx" 0xFFFFFFFFFFFFFFFF) "ffffffffffffffff")
1078 (= (format "%lu" 0xFFFFFFFFFFFFFFFF) "18446744073709551615"))
1082 (= (format "%d" 0x7fffffff) "2147483647")
1083 (= (format "%d" 0xffffffff) "-1")
1084 (= (format "%u" 0xffffffff) "4294967295")
1087 (= (format "%d" 0x7fffffffffffffff) "-1")
1088 (= (format "%u" 0x7fffffffffffffff) "4294967295")
1089 (= (format "%x" 0x7fffffffffffffff) "ffffffff")
1090 (= (format "%X" 0x7fffffffffffffff) "FFFFFFFF")
1092 (= (format "%lld" 0x7fffffffffffffff) "9223372036854775807")
1093 (= (format "%llx" 0x7fffffffffffffff) "7fffffffffffffff")
1094 (= (format "%llu" 0x7fffffffffffffff) "9223372036854775807")
1095 (= (format "%lld" 0x8000000000000000) "-9223372036854775808")
1096 (= (format "%llx" 0x8000000000000000) "8000000000000000")
1097 (= (format "%llu" 0x8000000000000000) "9223372036854775808")
1098 (= (format "%lld" 0xFFFFFFFFFFFFFFFF) "-1")
1099 (= (format "%llx" 0xFFFFFFFFFFFFFFFF) "ffffffffffffffff")
1100 (= (format "%llu" 0xFFFFFFFFFFFFFFFF) "18446744073709551615"))
1106 (< (sub (fv 0,1 10 1000 0 0) -15937,4246) 1e-05))
1108 (define (test-gammai )
1109 (< (abs (sub (gammai 4 5) 0,734974)) 1e-05))
1111 (define (test-gammaln )
1112 (< (abs (sub 120 (exp (gammaln 6)))) 1e-05))
1120 (= (gcd 12 36 6 3) 3)
1123 (define (test-get-char )
1124 (= 65 (get-char (address "A"))))
1126 (define (test-get-float )
1127 (= 1,234 (get-float (pack "lf" 1,234))))
1129 (define (test-get-int )
1131 (= 123456789 (get-int (pack "ld" 123456789)))
1132 (set 'adr (pack "ldld" 0xaabbccdd 0xccddeeff))
1133 (= (format "%x" (get-int adr)) "aabbccdd")
1134 (= (format "%x" (get-int (address adr))) "aabbccdd")
1135 (= (format "%x" (get-int (+ (address adr) 0))) "aabbccdd")
1136 (= (format "%x" (get-int (+ (address adr) 4))) "ccddeeff")
1137 (set 'adr (pack "> ldld" 0xaabbccdd 0xccddeeff))
1138 (= adr "\170\187\204\221\204\221\238\255")
1139 (set 'adr (pack "< ldld" 0xaabbccdd 0xccddeeff))
1140 (= adr "\221\204\187\170\255\238\221\204")
1141 (set 'buff (pack "lulululululululu" 1 2 3 4))
1142 (apply and (map (fn (i) (= (+ i 1) (get-int (+ (* i 4) (address buff))))) '(0 1 2 3)))
1145 (define (test-get-long)
1146 (set 'adr (pack "Ld" -1))
1147 (= -1 (get-long adr)))
1149 (define (test-get-string )
1150 (= "hello" (get-string (address "hello"))))
1152 (define (test-get-url )
1153 (= "ERR: bad formed URL" (get-url "")))
1156 (define (test-global)
1157 (= global-myvar 123))
1159 (define (test-global?)
1161 (global? 'global-myvar)
1172 (= (if nil 1 '() 2) '())
1173 (= (if nil '() '()) '())
1174 (= (if true '() '()) '())
1175 (= (if nil 1 nil 2 nil 3 true 4 3) 4)
1176 (= (if nil 1 nil 2 nil 3 nil 4 3) 3)
1179 (define (test-ifft )
1180 (= '((1 2) (3 4)) (ifft (fft '((1 2) (3 4))))))
1182 (define (test-import )
1183 (primitive? import))
1185 (define (test-inc , x)
1187 (and (= 2 (inc 'x)) (= 2,1 (inc 'x 0,1))))
1189 (define (test-index )
1190 (= '(1 3) (index (lambda (x) (> x 3)) '(1 5 2 6 2 0))))
1192 (define (test-integer )
1194 (integer? (int "12345"))
1195 (= (int " 12345") 12345)
1196 (= (int "9223372036854775807") 9223372036854775807)
1197 (= (int "-9223372036854775808") -9223372036854775808)
1199 (= (int 1e30) 9223372036854775807)
1200 (= (int -1e30) -9223372036854775808)
1201 (= (int 0x8000000000000000) (int "0x8000000000000000"))
1204 (define (test-int) (test-integer))
1206 (define (test-integer? )
1209 (integer? 9223372036854775807)
1210 (integer? -9223372036854775808)
1211 (integer? 0x7FFFFFFFFFFFFFFF)
1212 (integer? 0xFFFFFFFFFFFFFFFF)
1215 (define (test-intersect )
1216 (= (intersect '(3 0 2 4 1) '(1 4 2 5)) '(2 4 1)))
1218 (define (test-invert )
1219 (set 'A '((-1 1 1) (1 4 -5) (1 -2 0)))
1220 (set 'I (multiply A (invert A)))
1221 (set 'J (multiply (array 3 3 (flat A)) (invert (array 3 3 (flat A)))))
1222 (and (< (sub 1 (nth 0 (nth 0 I))) 1e-06)
1223 (< (sub 1 (nth 1 (nth 1 I))) 1e-06)
1224 (< (sub 1 (nth 2 (nth 2 I))) 1e-06)
1225 (= I (array-list J))
1226 (not (invert '((0 1 0) (1 0 1) (0 0 0))) )
1230 (< (abs (sub (irr '(-1000 500 400 300 200 100)) 0,20272)) 0,0001))
1232 (define (test-join )
1234 (= "this is a sentence" (join '("this" "is" "a" "sentence") " "))
1235 (= "this_is_a_sentence" (join '("this_" "is_" "a_" "sentence")))
1237 (= (join '("A" "B" "C") "-") "A-B-C")
1238 (= (join '("A" "B" "C") "-" true) "A-B-C-")
1241 (define (test-lambda? )
1244 (define (test-last )
1245 (= 'f (last '(a b c d e f)))
1246 (= "p" (last "newlisp"))
1247 (= (array 2 '(5 6)) (last (array 3 2 (sequence 1 6))))
1250 (define (test-legal?)
1253 (not (legal? "a b c"))
1254 (set 'greek (pack "cccccccccccccccccc" 206 160 206 181 206 187 206 181 206 185 206
1255 172 206 180 206 181 207 137))
1259 (define (test-length )
1260 (> (length (symbols)) 100)
1261 (- 7 (length "newlisp")))
1279 (define (test-letex)
1281 (= (letex (x '* y 3 z 4) (x y z)) 12)
1282 (= (letex (x 1 y 2 z 3) (quote (x y z))) '(1 2 3))
1283 (= (letex (x 1 y 2 z 3) '(x y z)) '(1 2 3))
1284 (= (letex (x 1 y 2 z 3) '('x (quote y) z)) '('1 (quote 2) 3))
1285 (= (letex (x 1) 'x) 1)
1289 (set 'x 0 'y 0 'z 0)
1291 (= (letn ((x 1) (y (+ x 1)) (z (+ y 1))) (list x y z)) '(1 2 3))
1295 (define (test-list )
1296 (and (list? (list 1 2 3 4 5)) (= '(1) (list 1)) (= '(1 nil) (list
1299 (define (test-list? )
1300 (and (list? '(1 2 3 4 5)) (list? '())))
1302 (define (test-load )
1303 (write-file "junk" "(+ 3 4)")
1306 (define (test-local)
1309 (= (local (a b) (set 'a 1 'b 2) (+ a b)) 3)
1313 (define (test-set-locale)
1314 (string? (set-locale)))
1319 (= 1 (log (exp 1) (exp 1)))
1323 (define (test-lookup )
1324 (and (= 3 (lookup 1 '((2 3 4) (1 2 3)))) (= 2 (lookup 1 '((2 3
1328 (define (test-lower-case )
1330 (= "abcdefgq" (lower-case "ABCDEFGQ"))
1331 (= "abcdefgh" (lower-case "ABCDEFGH"))))
1333 (define (test-macro? )
1335 (define-macro (foo-macro))))
1337 (define (test-main-args )
1341 (= $main-args (main-args))
1342 (= ($main-args 0) ((main-args) 0) (main-args 0))
1343 (= ($main-args -1) ((main-args) -1))
1344 (= ($main-args -1) (main-args -1))
1348 (define (test-make-dir )
1349 (and (make-dir "foodir") (remove-dir "foodir")))
1352 (and (= '(11 22 33) (map + '(10 20 30) '(1 2 3)))
1353 (= '(2 4 6) (map (lambda (x) (+ x x)) '(1 2 3)))
1357 (set 'A '((1 2 3) (4 5 6)))
1360 (= (mat + A B) '((2 4 6) (8 10 12)))
1361 (= (mat - A B) '((0 0 0) (0 0 0)))
1362 (= (mat * A B) '((1 4 9) (16 25 36)))
1363 (= (mat / A B) '((1 1 1) (1 1 1)))
1364 (= (mat + A 2) '((3 4 5) (6 7 8)))
1365 (= (mat - A 2) '((-1 0 1) (2 3 4)))
1366 (= (mat * A 2) '((2 4 6) (8 10 12)))
1367 (= (mat / A 2) '((0,5 1 1,5) (2 2,5 3)))
1369 (= (mat + A 5) '((6 7 8) (9 10 11)))
1370 (= (mat - A 2) '((-1 0 1) (2 3 4)))
1371 (= (mat * A 3) '((3 6 9) (12 15 18)))
1372 (= (mat / A 10) '((,1 ,2 ,3) (,4 ,5 ,6)))
1375 (= (mat op A B) '((2 4 6) (8 10 12)))
1377 (= (mat op A B) '((2 4 6) (8 10 12)))
1381 (define (test-match)
1383 (= (match '(a (b ?) d e *) '(a (b c) d e f g) true) '(a (b c) d e (f g)) )
1384 (= (match '(a (b ?) d e *) '(a (b c) d e f g) ) '(c (f g)) )
1386 (= (match '(a * b x) '(a b c d b x e f b x) true) '(a (b c d b x e f) b x) )
1387 (= (match '(a * b x) '(a b c d b x e f b x) ) '((b c d b x e f)) )
1390 (= (match '(? (?) x * ? (? e)) '(a (b) x y c (d e)) true) '(a (b) x (y) c (d e)) )
1391 (= (match '(? (?) x * ? (? e)) '(a (b) x y c (d e))) '(a b (y) c d) )
1393 (= (match '(a * b) '(a x b) true) '(a (x) b) )
1394 (= (match '(a * b) '(a x b)) '((x)) )
1397 (= (match '(a * b) '(a b) true) '(a () b) )
1398 (= (match '(a * b) '(a b)) '(()) )
1400 (= (match '( (? ?) * ) '( (x y) ) true) '((x y) ()) )
1401 (= (match '( (? ?) * ) '( (x y) )) '(x y ()) )
1404 (not (match '(+) '()))
1409 (and (= 10 (max 3 6 10 8)) (= 1,2 (max 0,7 0,6 1,2))))
1411 (define (test-member )
1412 (= '(3 4) (member 3 '(1 2 3 4)))
1413 (= (member "LISP" "newLISP") "LISP")
1414 (= (member "LI" "newLISP") "LISP")
1415 (= (member "" "newLISP") "newLISP")
1416 (not (member "xyz" "newLISP"))
1417 (not (member "new" "this is NEWLISP" 0))
1418 (= (member "new" "this is NEWLISP" 1) "NEWLISP")
1422 (and (= 3 (min 3 6 10 8)) (= 0,6 (min 0,7 0,6 1,2))))
1425 (and (< (sub (mod 10,5 3,3) 0,6) 0,0001) (< (sub (mod 10 3) 1) 0,0001)))
1428 (= 1e-09 (mul 0,0001 1e-05)))
1430 (define (test-multiply )
1431 (let ((A '((1 2 3) (4 5 6))) (B '((1 2) (1 2) (1 2))))
1433 (= '((6 12) (15 30)) (multiply A B))
1434 (= (array 2 2 (flat '((6 12) (15 30))))
1435 (multiply (array 2 3 (flat A)) (array 3 2 (flat B))))
1439 (define (test-name )
1440 (= "name" (name 'name)))
1442 (define (test-net-accept )
1444 (set 'net-listen-test (set 'listen (net-listen 12345)))
1445 (set 'net-connect-test (set 'connect (net-connect "localhost" 12345)))
1446 (set 'server (net-accept listen))
1447 (set 'net-send-test (= (net-send server "hello") 5))
1448 (set 'net-select-test (net-select connect "r" 100000))
1449 (set 'net-peek-test (= (net-peek connect) 5))
1450 (set 'net-receive-test (net-receive connect 'buff 20))
1452 (set 'net-sessions-test (and
1453 (find listen (net-sessions))
1454 (find connect (net-sessions))
1455 (find server (net-sessions))))
1456 (set 'net-local-test (= (net-local server) (net-peer connect)))
1457 (set 'net-peer-test (= (net-local connect) (net-peer server)))
1458 (set 'net-close-test (net-close connect))
1459 (set 'net-close-test (net-close server))
1460 (set 'net-close-test (net-close listen))
1464 (define (test-net-close ) net-close-test)
1466 (define (test-net-connect ) net-connect-test)
1468 (define (test-net-error )
1470 (not (net-close 12345))
1471 (list? (net-error))))
1473 (define (test-net-eval) true) ;; see special test prog
1475 (define (test-net-listen ) net-listen-test)
1477 (define (test-net-local ) net-local-test)
1479 (define (test-net-lookup )
1481 (or (= "127.0.0.1" (net-lookup "localhost")) (= "::1" (net-lookup "localhost")))
1482 (or (= "localhost" (net-lookup "127.0.0.1")) (= "localhost" (net-lookup "::1")))
1486 (define (test-net-peek ) net-peek-test)
1488 (define (test-net-peer ) net-peer-test)
1490 (define (test-net-ping) true) ; test manually on UNIX as root
1492 (define (test-net-receive ) net-receive-test)
1494 (define (test-net-receive-from)
1496 (set 'sock (net-listen 1234 "localhost" "udp"))
1497 (set 'net-send-to-test (net-send-to "localhost" 1234 "hello" sock))
1498 (set 'net-select-test (net-select sock "r" 1000000) )
1499 (= "hello" (first (net-receive-from sock 10)))
1503 (define (test-net-receive-udp)
1504 (write-file "udptest.lsp"
1506 (map set '(in out sid) (map int (slice (main-args) 2)))
1507 (semaphore sid 1) ; signal parent to start
1508 (set 'msg (net-receive-udp in 20 2000000))
1510 (if (not msg) (exit))
1511 (net-send-udp "localhost" out (upper-case (first msg)))
1516 (set 'sid (semaphore))
1518 (process (string "newlisp udptest.lsp " 10001 " " 10002 " " sid))
1519 (process (string "./newlisp udptest.lsp " 10001 " " 10002 " " sid)))
1520 (println "---------- testing UDP Win32 and OS/2 -------------")
1521 (println "waiting ...");
1522 (semaphore sid -1) ; wait for child process
1524 (println "sending ...")
1525 (net-send-udp "localhost" 10001 "hello")
1526 (println "receiving ...")
1527 (set 'msg (net-receive-udp 10002 20 3000000))
1528 (println "msg:" msg)
1529 (or (delete-file "udptest.lsp") true)
1530 (println "deleting semaphore:" (semaphore sid 0)) ; delete semaphore
1531 (println "------------------------------------------")
1532 (if msg (set 'net-send-udp-test (= "HELLO" (first msg)) ) )))
1536 (define (test-net-receive-udp)
1537 (fork (begin (sleep 500) (net-send-udp "localhost" 10001 "hello")))
1538 (set 'net-send-udp-test (= "hello" (first (net-receive-udp 10001 10)))))
1542 (define (test-net-select ) net-select-test)
1544 (define (test-net-send ) net-send-test)
1546 (define (test-net-send-to ) net-send-to-test)
1548 (define (test-net-send-udp ) net-send-udp-test)
1550 (define (test-net-service ) (= 21 (net-service "ftp" "tcp")))
1552 (define (test-net-sessions ) net-sessions-test)
1559 ;test symbol-nil = logic-nil in order compare of count
1560 (= (count '(nil true) (map (curry < 3) '(1 2 4 5))) '(2 2))
1561 (= nil (not (nil? nil)))
1562 (= '(nil true) (map nil? '(a nil)))))
1564 (define (test-null?)
1565 (= (map null? '(1 0 2 0,0 "hello" "" (a b c) () nil true))
1566 '(nil true nil true nil true nil true true nil)))
1568 (define (test-normal )
1569 (and (float? (normal)) (float? (normal 10 3)) (list? (normal 10
1573 (and (not (not (not '()))) (not (not (not (not (not nil))))) (not
1574 (not (not (not true))))
1575 (= '(true true true) (map not '(nil nil nil)))
1576 (= '(nil nil nil) (map not '(true true true)))))
1579 (= (length (now)) 11))
1581 (define (test-nper )
1582 (< (sub (nper 0,1 1000 100000 0 0) -25,15885793) 1e-08))
1585 (< (sub (npv 0,1 '(-10000 3000 4200 6800)) 1188,443412) 1e-06))
1587 (define (test-nth , l) ;; see set-nth for more comprehensive testing
1589 (and (= 0 (nth 0 l))
1593 (= (nth 0 "lisp") "l")
1594 (= (nth 1 "lisp") "i")
1595 (= (nth 3 "lisp") "p")
1596 (= (nth -4 "lisp") "l")
1601 (set 'l '(a b (c d) (e f)))
1609 (set 'myarray (array 3 2 (sequence 1 6)))
1610 (= (array 2 '(3 4)) (myarray 1))
1611 (= 6 (myarray -1 -1))
1613 (= (array 2 '(3 4)) (myarray '(1)))
1614 (= 6 (myarray '(-1 -1)))
1616 (= "L" ("newLISP" 3))
1618 (constant 'constL '((1 2 3) (a b c)))
1621 (= (nth 1 2 constL) 'c)
1622 (= (nth (constL 1 2)) 'c)
1623 (= (nth (constL (- 2 1) (+ 1 1))) 'c)
1624 (= (nth (constL '(1 2))) 'c)
1625 (= (nth (constL aref)) 'c)
1626 (= (nth 0 (+ 1 1) constL) 3)
1631 (define (test-number?)
1636 (not (number? "abc"))
1637 (not (number? '(a b c)))
1642 (define (test-open )
1644 (set 'fle (open "qa-comma" "read"))
1648 (and (or (or (= 1 2) nil nil) (or nil nil nil true)) (not (or nil
1652 (define (test-pack )
1654 (= (pack "c c c" 65 66 67) "ABC")
1655 (= (unpack "c c c" "ABC") '(65 66 67))
1656 (set 's (pack "c d u" 10 12345 56789))
1657 (= (unpack "c d u" s) '(10 12345 56789))
1658 (set 's (pack "s10 f" "result" 1,23))
1659 (= (first (unpack "s10 f" s)) "result\000\000\000\000")
1660 (< (- (last (unpack "s10 f" s)) 1,23) 0,00001)
1661 (set 's (pack "s3 lf" "result" 1,23))
1662 (= (first (unpack "s3 f" s)) "res")
1664 (= (pack "ccc" 65 66 67) "ABC")
1665 (= (unpack "ccc" "ABC") '(65 66 67))
1666 (set 's (pack "cdu" 10 12345 56789))
1667 (= (unpack "cdu" s) '(10 12345 56789))
1668 (set 's (pack "s10f" "result" 1,23))
1669 (= (first (unpack "s10f" s)) "result\000\000\000\000")
1670 (< (- (last (unpack "s10f" s)) 1,23) 0,00001)
1671 (set 's (pack "s3lf" "result" 1,23))
1672 (= (first (unpack "s3f" s)) "res")
1674 (= "\001\000" (pack "<d" 1))
1675 (= "\000\001" (pack ">d" 1))
1676 (= "\001\000\000\000" (pack "<ld" 1))
1677 (= "\000\000\000\001" (pack ">ld" 1))
1678 (= '(12345678) (unpack "ld" (pack "ld" 12345678)))
1679 (= '(12345678) (unpack "<ld" (pack "<ld" 12345678)))
1680 (= '(12345678) (unpack ">ld" (pack ">ld" 12345678)))
1681 (= (unpack "bbbbbbbb" (pack "<lf" 1,234)) '(88 57 180 200 118 190 243 63))
1682 (= (unpack "bbbbbbbb" (pack ">lf" 1,234)) '(63 243 190 118 200 180 57 88))
1683 (= (format "%20.2f" (first (unpack "lf" (pack "lf" 1234567890123456)))) " 1234567890123456,00")
1686 (define (test-parse )
1688 (= 3 (length (parse "hello hi there")))
1689 (= (parse "abcbdbe" "b") '("a" "c" "d" "e"))
1690 (= (parse "," ",") '("" ""))
1691 (= (parse "hello regular expression 1, 2, 3" {,\s*|\s+} 0)
1692 '("hello" "regular" "expression" "1" "2" "3"))))
1694 (define (test-parse-date)
1696 (= (parse-date "2007.1.3" "%Y.%m.%d") 1167782400)
1697 ; note that the month name here is in German
1698 (= (parse-date "Januar 10, 07" "%B %d, %y") 1168387200)
1702 (set 'fle (open "qa-comma" "r"))
1703 (= (peek fle) (first (file-info "qa-comma")))
1707 (write-file "pipe-child.lsp"
1709 (set 'msg (read-line (int (nth 2 (main-args)))))
1710 (write-line (upper-case msg) (int (nth 3 (main-args))))
1714 (set 'channel (pipe))
1715 (set 'in (first channel))
1716 (set 'out (last channel))
1717 (if (and (> opsys 5) (< opsys 9))
1718 (process (string "newlisp pipe-child.lsp " in " " out))
1719 (process (string "./newlisp pipe-child.lsp " in " " out)))
1721 (write-line "hello there" out)
1723 (= (read-line in) "HELLO THERE")
1724 (delete-file "pipe-child.lsp"))
1728 (set 'channel (pipe))
1729 (set 'in (first channel))
1730 (set 'out (last channel))
1731 (fork (write-line (upper-case (read-line in)) out))
1732 (write-line "hello there" out)
1734 (= (read-line in) "HELLO THERE")
1740 (< (sub (pmt 0,1 10 100000 0 0) -16274,53949) 1e-05))
1742 (define (test-pop , r l)
1744 (set 'l '(1 2 3 4 5 6 7 8 9 0))
1747 (and (= r '(0 9 8 7 6 5 4 3 2 1))
1748 (set 'l '(a b (c d (x) e)))
1749 (= 'x (pop l '(2 2 0)))
1750 (set 'lst '(1 2 3 (4 5)()))
1752 (= lst '(1 2 3 (4 5) (x)))
1754 (= lst '(1 2 3 (4 5) (y x)))
1756 (= lst '(1 2 3 (4 5) (y z x)))
1758 (= lst '(1 2 3 (4 5) p (y z x)))
1760 (= lst '(1 2 3 (4 5) p q (y z x)))
1762 (= lst '(1 2 3 (a 4 5) p q (y z x)))
1763 (= (pop lst 3 -3) 'a)
1766 (= (pop lst -1 1) 'z)
1767 (= (pop lst -1 0) 'y)
1768 (= (pop lst -1 -1) 'x)
1769 (= lst '(1 2 3 (4 5)()))
1778 (= (pop s -2 2) "IS")
1780 (= (pop s -2 10) "ew")
1782 (set 's "123456789")
1786 (set 's "123456789")
1787 (= (pop s 5 5) "6789")
1796 (define (test-pop-assoc)
1798 (set 'L '((a (b 1) (c (d 2)))))
1799 (= (pop-assoc (L 'a)) '(a (b 1) (c (d 2))))
1801 (set 'L '((a (b 1) (c (d 2)))))
1802 ( = (pop-assoc (L 'a 'b)) '(b 1))
1803 (= L '((a (c (d 2)))))
1804 (set 'L '((a (b 1) (c (d 2)))))
1805 (= (pop-assoc (L 'a 'c)) '(c (d 2)))
1807 (set 'L '((a (b 1) (c (d 2)))))
1808 (= (pop-assoc (L 'a 'c 'd)) '(d 2))
1809 (= L '((a (b 1) (c))))
1810 (= (pop-assoc (L 'a 'c)) '(c))
1812 (= (pop-assoc (L 'a 'b)) '(b 1))
1814 (= (pop-assoc (L 'a)) '(a))
1820 (define (test-post-url )
1821 (= "ERR: bad formed URL" (post-url "" "abc" "def")))
1829 (define (test-pretty-print)
1830 (= (pretty-print) '(80 " ")))
1832 (define (test-primitive? )
1833 (primitive? primitive?))
1835 (define (test-print )
1836 (device (open "testprint" "w"))
1839 (and (= "hello" (read-file "testprint"))
1840 (delete-file "testprint")))
1842 (define (test-println )
1843 (device (open "testprintln" "w"))
1847 (= "hello" (slice (read-file "testprintln") 0 5))
1848 (delete-file "testprintln")))
1850 (define (test-prob-chi2 )
1851 (< (abs (sub (prob-chi2 10 10) 0,440493)) 1e-05))
1853 (define (test-prob-z )
1854 (< (abs (sub (prob-z 0) 0,5)) 1e-05))
1856 (define (test-process )
1857 (write-file "processtest" {(write-file "testprocess" "hello") (exit)})
1858 (if (> opsys 5) (process "newlisp processtest") (process "./newlisp processtest"))
1859 (until (file? "testprocess") (sleep 500))
1861 (= "hello" (read-file "testprocess"))
1862 (delete-file "processtest")
1863 (delete-file "testprocess")))
1865 (define (test-protected?)
1867 (protected? 'println)
1868 (constant 'cval 123)
1873 (define (test-push , l)
1877 (= l '(0 1 2 3 4 5 6 7 8 9))
1878 (set 'l '(a b (c d () e)))
1879 (push 'x l '(2 2 0))
1880 (= (ref 'x l) '(2 2 0))
1881 (set 'lst '(1 2 3 (4 5)()))
1883 (= lst '(1 2 3 (4 5) (x)))
1885 (= lst '(1 2 3 (4 5) (y x)))
1887 (= lst '(1 2 3 (4 5) (y z x)))
1889 (= lst '(1 2 3 (4 5) p (y z x)))
1891 (= lst '(1 2 3 (4 5) p q (y z x)))
1893 (= lst '(1 2 3 (a 4 5) p q (y z x)))
1894 (= (pop lst 3 -3) 'a)
1897 (= (pop lst -1 1) 'z)
1898 (= (pop lst -1 0) 'y)
1899 (= (pop lst -1 -1) 'x)
1900 (= lst '(1 2 3 (4 5)()))
1902 (test-push-optimization-bug)
1905 (= (push "#" s) "#")
1907 (= (push "#" s 1) "#")
1909 (= (push "#" s 3) "#")
1911 (= (push "#" s -1) "#")
1913 (= (push "#" s -3) "#")
1914 (= s "##n#ewLIS#P#")
1915 (= (push "xy" s) "xy")
1916 (= s "xy##n#ewLIS#P#")
1917 (= (push "xy" s -1) "xy")
1918 (= s "xy##n#ewLIS#P#xy")
1923 (= (push "" s -1) "")
1937 (define (test-push-pop)
1938 (set 'lst (sequence 1 1000))
1939 (dotimes (x 1000) (push (pop lst) lst -1))
1940 (= lst (sequence 1 1000)))
1942 (define (test-push-optimization-bug) ; fixed in 8.7.1
1950 (define (test-put-url )
1951 (= "ERR: bad formed URL" (put-url "" "abc")))
1954 (< (sub (pv 0,1 10 1000 100000 0 0) -44696,89605) 1e-05))
1956 (define (test-quote )
1959 (define (test-quote? )
1962 (define (test-rand , sum)
1965 (inc 'sum (rand 2)))
1966 (and (< sum 600) (> sum 400) (list? (rand 10 100))))
1968 (define (test-random )
1969 (and (float? (random)) (= (length (random 0 1 10)) 10)))
1971 (define (test-randomize)
1973 (!= '(a b c d e f g) (randomize '(a b c d e f g)))
1974 (= (difference '(a b c d e f g) (randomize '(a b c d e f g))) '())
1978 (define (test-read-expr)
1979 (set 'code "; a statement\n(+ 3 4)\n(define (double x) (+ x x))")
1980 (read-expr code (fn (x) (push x clist)) (context))
1981 (= clist '((define (double x) (+ x x)) (+ 3 4)))
1984 (define (test-read-buffer )
1986 (set 'file (open "qa-comma" "read"))
1987 (read-buffer file 'buff (nth 0 (file-info "qa-comma")))
1989 (set 'file (open "junk" "write"))
1990 (write-buffer file 'buff (nth 0 (file-info "qa-comma")))
1993 (define (test-read-char )
1995 (file-copy "qa-comma" "junk")
1996 (delete-file "junk")))
1998 (define (test-read-file )
1999 (read-file "qa-comma"))
2001 (define (test-read-key) true)
2003 (define (test-read-line )
2004 (line-count "qa-comma"))
2007 (define (test-real-path)
2009 (string? (real-path))
2010 (string? (real-path "."))
2016 (set 'pList '(a b (c d () e)))
2017 (push 'x pList 2 2 0)
2018 (= (ref 'x pList) '(2 2 0))
2019 (= (ref '(x) pList) '(2 2))
2020 (set 'v (ref '(x) pList))
2022 (= (ref 'foo pList) '())
2023 ; comparison functor
2024 (= (ref 'e '(a b (c d (e) f)) =) '(2 2 0))
2025 (= (ref 'e '(a b (c d (e) f)) >) '(0))
2026 (= (ref 'e '(a b (c d (e) f)) <) '(2))
2027 (= (ref 'e '(a b (c d (e) f)) (fn (x y) (or (= x y) (= y 'd)))) '(2 1))
2028 (define (is-it-or-d x y) (or (= x y) (= y 'd)))
2029 (= (ref 'e '(a b (c d (e) f)) is-it-or-d) '(2 1))
2030 ; comparison with match and unify
2031 (= (ref '(a ?) '((l 3) (a 12) (k 5) (a 10) (z 22)) match) '(1))
2032 (= (ref '(X X) '( ((a b) (c d)) ((e e) (f g)) ) unify) '(1 0))
2033 (= (ref '(X g) '( ((a b) (c d)) ((e e) (f g)) ) unify) '(1 1))
2036 (define (test-ref-all)
2038 (set 'L '(a b c (d a f (a h a)) (k a (m n a) (x))))
2039 (= (ref-all 'a L) '((0) (3 1) (3 3 0) (3 3 2) (4 1) (4 2 2)))
2041 (= (map 'L (ref-all 'a L)) '(a a a a a a))
2042 (= (ref-all 'a '(1 2 3 4 5 6)) '())
2043 ; with comparison functor
2044 (set 'L '(a b c (d f (h l a)) (k a (m n) (x))))
2045 (= (ref-all 'c L =) '((2)))
2046 (= (ref-all 'c L >) '((0) (1) (3 2 2) (4 1)))
2047 (= (ref-all 'a L (fn (x y) (or (= x y) (= y 'k)))) ' ((0) (3 2 2) (4 0) (4 1)))
2048 (define (is-long? x y) (> (length y) 2))
2049 (= (ref-all nil L is-long?) '((3) (3 2) (4)))
2050 (define (is-it-or-d x y) (or (= x y) (= y 'd)))
2051 (= (ref-all 'e '(a b (c d (e) f)) is-it-or-d) '((2 1) (2 2 0)))
2052 (= (ref-all 'b '(a b (c d (e) f)) is-it-or-d) '((1) (2 1)))
2053 (= (ref-all nil '(((()))) (fn (x y) (> (length y) 0))) '((0) (0 0)))
2054 ; test comparison with match and unify
2055 (= (ref-all '(a ?) '((l 3) (a 12) (k 5) (a 10) (z 22)) match) '((1) (3)))
2056 (= (ref-all '(X X) '( ((a b) (c d)) ((e e) (f g)) ((z) (z))) unify) '((1 0) (2)))
2057 (= (ref-all '(X g) '( ((x y z) g) ((a b) (c d)) ((e e) (f g))) unify) '((0) (2 1)))
2061 (define (test-regex )
2063 (= (regex "http://(.*):(.*)" "http://nuevatec.com:80")
2064 '("http://nuevatec.com:80" 0 22 "nuevatec.com" 7 12 "80" 20 2))
2065 (= $0 "http://nuevatec.com:80")
2066 (= $1 "nuevatec.com")
2068 (= (regex "b+" "AAAABBBAAAA" 1) '("BBB" 4 3))))
2070 (define (test-remove-dir )
2071 (and (make-dir "junk") (remove-dir "junk")))
2073 (define (test-rename-file )
2074 (copy-file "qa-comma" "junk")
2075 (rename-file "junk" "junk2"))
2077 ;; this can run only once than must be reloaded
2078 ;; because some replace's are in place with a constant
2079 (define (test-replace )
2081 (not (catch (replace "a" "akakak") 'result))
2082 (not (catch (replace "a") 'result))
2083 (not (catch (replace) 'result))
2084 (catch (replace "a" '("x" "a" "y")) 'result)
2085 (= (replace "a" "ababab" "b") "bbbbbb")
2087 (= (replace 'a '(a a b a b a a a b a) 'b) '(b b b b b b b b b b))
2088 (= (replace 'a '(a a b a b a a a b a)) '(b b b))
2089 (= (replace 'a '(a)) '())
2090 ;; with regular expressions option
2091 (= (replace "" "abc" "x" 0) "xaxbxcx")
2092 (= (replace "$" "abc" "x" 0) "abcx")
2093 (= (replace "^" "abc" "x" 0) "xabc")
2094 (= (replace "\\b" "abc" "x" 0) "xabcx")
2095 (= (replace "(?<=[0-9])(?=(?:[0-9]{3})+(?![0-9]))" "1234567" "," 0) "1,234,567")
2096 (= (replace "a" "ababab" (upper-case $0) 0) "AbAbAb")
2098 (set 'str2 "abaBab")
2099 (= (replace "b|B" str2 "z" 0) "azazaz")
2101 (replace-once "aaa")
2102 (= (replace "%([0-9A-F][0-9A-F])" "%41123%42456%43" (char (int (append "0x" $1))) 1) "A123B456C")
2103 ; replace with comparison functor
2104 (set 'L '(1 4 22 5 6 89 2 3 24))
2105 (= (replace 10 L 10 <) '(1 4 10 5 6 10 2 3 10))
2106 (set 'L '(1 4 22 5 6 89 2 3 24))
2107 (= (replace 10 L 10 (fn (x y) (< x y))) '(1 4 10 5 6 10 2 3 10))
2109 (set 'AL '((john 5 6 4) (mary 3 4 7) (bob 4 2 7 9) (jane 3)))
2110 (= (replace '(mary *) AL (list 'mary (apply + (rest $0))) match)
2111 '((john 5 6 4) (mary 14) (bob 4 2 7 9) (jane 3)))
2112 (set 'AL '((john 5 6 4) (mary 3 4 7) (bob 4 2 7 9) (jane 3)))
2113 (= (replace '(*) AL (list ($0 0) (apply + (rest $0))) match)
2114 '((john 15) (mary 14) (bob 22) (jane 3)))
2115 (set 'AL '((john 5 6 4) ("mary" 3 4 7) (bob 4 2 7 9) ("jane" 3)))
2116 (= (replace nil AL (cons (sym ($0 0)) (rest $0)) (fn (x y) (string? (y 0))))
2117 '((john 5 6 4) (mary 3 4 7) (bob 4 2 7 9) (jane 3)))
2120 (define (replace-once str)
2121 (= (replace "a" str (upper-case $0) 0x8000) "Aaa") ;; custom option replace once
2124 (define (test-replace-assoc )
2125 (set 'aList '((a 1 2 3) (b 4 5 6) (c 7 8 9)))
2126 (set 'bList '((a 1) (b 2) (c 3)))
2127 (replace-assoc 'b aList '(b 4 5 99))
2128 (replace-assoc 'c aList '(x "this works too"))
2130 (= aList '((a 1 2 3) (b 4 5 99) (x "this works too")))
2131 (set 'lst '((a 1)(b 2)(c 3)))
2132 (= (replace-assoc 'b lst (list 'b (+ 1 (last $0))))
2134 (= (replace-assoc 'b bList) '((a 1) (c 3)))
2135 (= (replace-assoc 'a bList) '((c 3)))
2136 (= (replace-assoc 'c bList) '())
2141 (define (test-reset )
2144 (define (test-rest , l)
2145 (set 'l '(a b c d e f g))
2146 (and (= (cons (first l) (rest l)) l)
2147 (= (rest "newlisp") "ewlisp")
2149 (= (1 l) '(b c d e f g))
2152 (= (-3 '(a b c d e f g)) '(e f g))
2153 (= (-3 "abcdefg") "efg")
2156 (= (array 2 2 (sequence 3 6)) (rest (array 3 2 (sequence 1 6))))
2159 (define (test-reverse )
2161 (= (reverse '(1 2 3)) '(3 2 1))
2162 (= (reverse "newLISP") "PSILwen")))
2164 (define (test-rotate )
2166 (= '(8 9 0 1 2 3 4 5 6 7) (rotate '(0 1 2 3 4 5 6 7 8 9) 2))
2167 (= '() (rotate '()))
2168 (= (rotate '(1) -1) '(1))
2170 (= (rotate "x" -1) "x")
2171 (set 'str "abcdefg")
2172 (= (rotate str) "gabcdef")
2173 (= (rotate str 3) "defgabc")
2174 (= (rotate str -4) "abcdefg")
2177 (define (test-round)
2179 (= (round 1,25) (round 1,25 0) 1)
2180 (= (round 3,89) (round 3,89 0) 4)
2181 (= (round 123,49 2) 100)
2182 (= (round 123,49 1) 120)
2183 (= (round 123,49 0) 123)
2184 (= (round 123,49 -1) 123,5)
2185 (= (round 123,49 -2) 123,49)
2186 (= (round 123,49 -3) 123,49)
2187 (!= (round 123,49 -2) 123,49000000000001)
2188 (= (round 123,49 3) 0)))
2190 (define (test-save )
2191 (and (save "all") (save "save.lsp" 'test-save) (delete-file "all")
2192 (delete-file "save.lsp")))
2194 (define (test-search , file)
2196 (set 'file (open "qa-comma" "read"))
2197 (search file "define")
2200 (define (test-seed )
2207 (define (test-seek , file chr)
2208 (set 'file (open "junk" "write"))
2210 (write-char file x))
2212 (set 'file (open "junk" "read"))
2214 (set 'chr (read-char file))
2216 (delete-file "junk")
2219 (define (test-select )
2220 (set 'l '(0 1 2 3 4 5 6 7 8 9))
2222 (test-select-collect)
2223 (= (select l '(0 9 9 0 1 8 8 1)) '(0 9 9 0 1 8 8 1))
2224 (= (select "2001-09-20" '(5 6 8 9 0 1 2 3)) "09202001")))
2226 ;; for testing semaphores accross processes/threads see test-share
2227 (define (test-semaphore)
2229 (set 'sid (semaphore))
2230 (if (< opsys 5) (= (semaphore sid) 0) true) ;; no semaphore status on Win32
2232 (if (< opsys 5) (= (semaphore sid) 1) true) ;; no semaphore status on Win32
2235 (define (test-sequence )
2236 (= (sequence 1 10 3) '(1 4 7 10)))
2238 (define (test-series )
2240 (= (series 2 2 5) '(2 4 8 16 32))
2241 (= (series 2 2 0) '())
2242 (= (series 1 2 -10) '())
2243 (= (series 1 1 5) '(1 1 1 1 1))
2246 (define (test-set , x y z)
2247 (set 'x (set 'y (set 'z 123)))
2250 (define (test-setq , x y z)
2252 (and (= x 1) (= y 2) (= z 3)))
2254 (define (test-set-assoc)
2256 (set 'L '((a 1) (b (c (d 2) (e 3) (e 4))) ("a" 5) ((a) 6)))
2257 (= (assoc 'a L) '(a 1))
2258 (= (assoc 'b L) '(b (c (d 2) (e 3) (e 4))))
2259 (= (assoc "a" L) '("a" 5))
2260 (= (assoc '(a) L) '((a) 6))
2262 (= (assoc (L 'a)) '(a 1))
2263 (= (assoc (L 'b)) '(b (c (d 2) (e 3) (e 4))))
2264 (= (assoc (L "a")) '("a" 5))
2265 (= (assoc (L '(a))) '((a) 6))
2267 (= (assoc (L 'b 'c)) '(c (d 2) (e 3) (e 4)))
2268 (= (assoc (L 'b 'c 'd)) '(d 2))
2269 (= (assoc (L 'b 'c 'e)) '(e 3))
2271 (= (set-assoc (L 'a) '(a 11))
2272 '((a 11) (b (c (d 2) (e 3) (e 4))) ("a" 5) ((a) 6)))
2274 (= (set-assoc (L 'b) '(B (C (d 2) (e 3) (e 4))))
2275 '((a 11) (B (C (d 2) (e 3) (e 4))) ("a" 5) ((a) 6)))
2277 (= (set-assoc (L "a") '("A" 5))
2278 '((a 11) (B (C (d 2) (e 3) (e 4))) ("A" 5) ((a) 6)))
2280 (= (set-assoc (L '(a)) '((A) 6))
2281 '((a 11) (B (C (d 2) (e 3) (e 4))) ("A" 5) ((A) 6)))
2283 (= (set-assoc (L 'B 'C) '(c (d 2) (e 3) (e 4)))
2284 '((a 11) (B (c (d 2) (e 3) (e 4))) ("A" 5) ((A) 6)))
2286 (= (set-assoc (L 'B 'c 'd) '(d 22))
2287 '((a 11) (B (c (d 22) (e 3) (e 4))) ("A" 5) ((A) 6)))
2289 (= (set-assoc (L 'B 'c 'e) '(e 33))
2290 '((a 11) (B (c (d 22) (e 33) (e 4))) ("A" 5) ((A) 6)))
2292 (= (length (set 'L (dup '(a 1) 1000))) 1000)
2293 (= (push '(x 9) L -1) '(x 9))
2294 (= (ref '(x *) L match) '(1000))
2295 (= (assoc 'x L) '(x 9))
2296 (= (assoc-set (L 'x) $0) '(x 9))
2299 (define (test-set-nth-implicit)
2301 (= (set-nth ("abcd" 0) "z") "zbcd")
2302 (= (set-nth ("abcd" -1) "z") "abcz")
2303 (= (set-nth ("abcd" 3) "z") "abcz")
2304 (= (set-nth ("abcd" -4) "z") "zbcd")
2305 (= (set-nth ("abcd" 0) "xyz") "xyzbcd")
2306 (= (set-nth ("abcd" -1) "xyz") "abcxyz")
2307 (= (set-nth ("abcd" 3) "xyz") "abcxyz")
2308 (= (set-nth ("abcd" -4) "xyz") "xyzbcd")
2309 (= (set-nth ("abcd" 1) (append $0 $0)) "abbcd")
2310 (set 'l '(1 (2 3) 4))
2311 (= (set-nth (l 0) 'new) '(new (2 3) 4))
2313 (set 'l '(1 (2 3) 4))
2314 (= (set-nth (l 1) 'new) '(1 new 4))
2316 (set 'l '(1 (2 3) 4))
2317 (= (set-nth (l 2) 'new) '(1 (2 3) new))
2319 (set 'l '(1 (2 3) 4))
2320 (= (set-nth (l 0 0) 'new) '(new (2 3) 4))
2321 (= (nth 0 0 l) 'new)
2322 (set 'l '(1 (2 3) 4))
2323 (= (set-nth (l 1 0) 'new) '(1 (new 3) 4))
2324 (= (nth 1 0 l) 'new)
2325 (set 'l '(1 (2 3) 4))
2326 (= (set-nth (l 1 1) 'new) '(1 (2 new) 4))
2327 (= (nth 1 1 l) 'new)
2329 (= (set-nth (l 0 0) 'new) '((new 3) 4))
2330 (= (nth 0 0 l) 'new)
2331 (set 'l '((2 (3 4))(5 6)))
2332 (= (set-nth (l 0 0 0) 'new) '((new (3 4)) (5 6)))
2333 (= (nth 0 0 0 l) 'new)
2334 (set 'l '((2 (3 4))(5 6)))
2335 (= (set-nth (l 0 0 1) 'new) '((new (3 4)) (5 6)))
2336 (= (nth 0 0 1 l) 'new)
2337 (set 'l '((2 (3 4))(5 6)))
2338 (= (set-nth (l 0 1 1) 'new) '((2 (3 new)) (5 6)))
2339 (= (nth 0 1 1 l) 'new)
2340 (set 'l '((2 (3 4))(5 6)))
2341 (= (set-nth (l 0 1) 'new) '((2 new) (5 6)))
2342 (= (nth 0 1 l) 'new)
2343 (set 'L '(1 2 3 4 5))
2344 (= (set-nth (L 3) (+ $0 1)) '(1 2 3 5 5))
2345 (set 'L '(a b c (d e f)))
2346 (= (set-nth (L 3) (set-nth (L 3) 99)) '(a b c (a b c 99)))
2348 (= (set-nth (L -1) 99) '(99))
2349 (set 'L '((1 2 3) (a b c)))
2350 (= (set 'aref (ref 'c L)) '(1 2))
2351 (= (set-nth (L aref) 99) '((1 2 3) (a b 99)))
2352 (set 'L '((1 2 3) (a b c)))
2353 (= (set-nth 1 (+ 1 1) L 99) '((1 2 3) (a b 99)))
2354 (= (set-nth (L 1 (+ 1 1)) 999) '((1 2 3) (a b 999)))
2355 (= (set-nth (L (sequence 1 10000)) '@) '((1 2 3) (a b @)))
2358 (define (test-set-nth)
2360 (= (set-nth 0 "abcd" "z") "zbcd")
2361 (= (set-nth -1 "abcd" "z") "abcz")
2362 (= (set-nth 3 "abcd" "z") "abcz")
2363 (= (set-nth -4 "abcd" "z") "zbcd")
2364 (= (set-nth 0 "abcd" "xyz") "xyzbcd")
2365 (= (set-nth -1 "abcd" "xyz") "abcxyz")
2366 (= (set-nth (+ 1 2) "abcd" "xyz") "abcxyz")
2367 (= (set-nth -4 "abcd" "xyz") "xyzbcd")
2368 (= (set-nth 1 "abcd" (append $0 $0)) "abbcd")
2369 (set 'l '(1 (2 3) 4))
2370 (= (set-nth 0 l 'new) '(new (2 3) 4))
2372 (set 'l '(1 (2 3) 4))
2373 (= (set-nth 1 l 'new) '(1 new 4))
2375 (set 'l '(1 (2 3) 4))
2376 (= (set-nth 2 l 'new) '(1 (2 3) new))
2378 (set 'l '(1 (2 3) 4))
2379 (= (set-nth 0 0 l 'new) '(new (2 3) 4))
2380 (= (nth 0 0 l) 'new)
2381 (set 'l '(1 (2 3) 4)) ;;;;
2382 (= (set-nth 1 0 l 'new) '(1 (new 3) 4))
2383 (= (nth 1 0 l) 'new)
2384 (set 'l '(1 (2 3) 4))
2385 (= (set-nth 1 1 l 'new) '(1 (2 new) 4))
2386 (= (nth 1 1 l) 'new)
2388 (= (set-nth 0 0 l 'new) '((new 3) 4))
2389 (= (nth 0 0 l) 'new)
2390 (set 'l '((2 (3 4))(5 6)))
2391 (= (set-nth 0 0 0 l 'new) '((new (3 4)) (5 6)))
2392 (= (nth 0 0 0 l) 'new)
2393 (set 'l '((2 (3 4))(5 6)))
2394 (= (set-nth 0 0 1 l 'new) '((new (3 4)) (5 6)))
2395 (= (nth 0 0 1 l) 'new)
2396 (set 'l '((2 (3 4))(5 6)))
2397 (= (set-nth 0 1 1 l 'new) '((2 (3 new)) (5 6)))
2398 (= (nth 0 1 1 l) 'new)
2399 (set 'l '((2 (3 4))(5 6)))
2400 (= (set-nth 0 1 l 'new) '((2 new) (5 6)))
2401 (= (nth 0 1 l) 'new)
2402 (set 'L '(1 2 3 4 5))
2403 (= (set-nth 3 L (+ $0 1)) '(1 2 3 5 5))
2404 (set 'L '(a b c (d e f)))
2405 (= (set-nth 3 L (set-nth 3 L 99)) '(a b c (a b c 99)))
2406 (test-set-nth-implicit)
2409 (define (test-nth-set-implicit)
2411 (= (nth-set ("abcd" 0) "z") "a")
2412 (= (nth-set ("abcd" -1) "z") "d")
2413 (= (nth-set ("abcd" 3) "z") "d")
2414 (= (nth-set ("abcd" -4)"z") "a")
2415 (= (nth-set ("abcd" 0) "xyz") "a")
2416 (= (nth-set ("abcd" -1)"xyz") "d")
2417 (= (nth-set ("abcd" 3) "xyz") "d")
2418 (= (nth-set ("abcd" -4) "xyz") "a")
2419 (= (nth-set ("abcd" 1) (append $0 $0)) "b")
2420 (set 'l '(1 (2 3) 4))
2421 (= (nth-set (l 0) 'new) 1)
2423 (set 'l '(1 (2 3) 4))
2424 (= (nth-set (l 1) 'new) '(2 3))
2426 (set 'l '(1 (2 3) 4))
2427 (= (nth-set (l 2) 'new) 4)
2429 (set 'l '(1 (2 3) 4))
2430 (= (nth-set (l 3) 'new) 4)
2432 (set 'l '(1 (2 3) 4))
2433 (= (nth-set (l 0 0) 'new) 1)
2434 (= (nth 0 0 l) 'new)
2435 (set 'l '(1 (2 3) 4))
2436 (= (nth-set (l 1 0) 'new) 2)
2437 (= (nth 1 0 l) 'new)
2438 (set 'l '(1 (2 3) 4))
2439 (= (nth-set (l 1 1) 'new) 3)
2440 (= (nth 1 1 l) 'new)
2442 (= (nth-set (l 0 0) 'new) 2)
2443 (= (nth 0 0 l) 'new)
2445 (= (nth-set (l 1 1) 'new) 3)
2446 (= (nth 1 1 l) 'new)
2448 (= (nth-set (l 2 3) 'new) 3)
2449 (= (nth 2 3 l) 'new)
2450 (set 'l '((2 (3 4))(5 6)))
2451 (= (nth-set (l 0 0 0) 'new) 2)
2452 (= (nth 0 0 0 l) 'new)
2453 (set 'l '((2 (3 4))(5 6)))
2454 (= (nth-set (l 0 0 1) 'new) 2)
2455 (= (nth 0 0 1 l) 'new) ;;;
2456 (set 'l '((2 (3 4))(5 6)))
2457 (= (nth-set (l 0 1 1) 'new) 4)
2458 (= (nth 0 1 1 l) 'new)
2459 (set 'l '((2 (3 4))(5 6)))
2460 (= (nth-set (l 0 1) 'new) '(3 4))
2461 (= (nth 0 1 l) 'new)
2462 (set 'L '(a b c (d e f)))
2463 (nth-set (L 3) (nth-set (L 3) 99))
2464 (= L '(a b c (d e f)))
2465 (set 'L '((1 2 3) (a b c)))
2466 (= (set 'aref (ref 'c L)) '(1 2))
2467 (= (nth-set (L aref) 99) 'c)
2471 (define (test-nth-set)
2473 (= (nth-set 0 "abcd" "z") "a")
2474 (= (nth-set -1 "abcd" "z") "d")
2475 (= (nth-set (+ 1 2) "abcd" "z") "d")
2476 (= (nth-set -4 "abcd" "z") "a")
2477 (= (nth-set 0 "abcd" "xyz") "a")
2478 (= (nth-set -1 "abcd" "xyz") "d")
2479 (= (nth-set 3 "abcd" "xyz") "d")
2480 (= (nth-set -4 "abcd" "xyz") "a")
2481 (= (nth-set 1 "abcd" (append $0 $0)) "b")
2482 (set 'l '(1 (2 3) 4))
2483 (= (nth-set 0 l 'new) 1)
2485 (set 'l '(1 (2 3) 4))
2486 (= (nth-set 1 l 'new) '(2 3))
2488 (set 'l '(1 (2 3) 4))
2489 (= (nth-set 2 l 'new) 4)
2491 (set 'l '(1 (2 3) 4))
2492 (= (nth-set 2 l 'new) 4)
2494 (set 'l '(1 (2 3) 4))
2495 (= (nth-set 0 0 l 'new) 1)
2496 (= (nth 0 0 l) 'new)
2497 (set 'l '(1 (2 3) 4))
2498 (= (nth-set 1 0 l 'new) 2)
2499 (= (nth 1 0 l) 'new)
2500 (set 'l '(1 (2 3) 4))
2501 (= (nth-set 1 1 l 'new) 3)
2502 (= (nth 1 1 l) 'new)
2504 (= (nth-set 0 0 l 'new) 2)
2505 (= (nth 0 0 l) 'new)
2507 (= (nth-set 0 1 l 'new) 3)
2508 (= (nth 0 1 l) 'new)
2510 (set 'l '((2 (3 4))(5 6)))
2511 (= (nth-set 0 0 0 l 'new) 2)
2512 (= (nth 0 0 0 l) 'new)
2513 (set 'l '((2 (3 4))(5 6)))
2514 (= (nth-set 0 0 1 l 'new) 2)
2515 (= (nth 0 0 1 l) 'new)
2516 (set 'l '((2 (3 4))(5 6)))
2517 (= (nth-set 0 1 1 l 'new) 4)
2518 (= (nth 0 1 1 l) 'new)
2519 (set 'l '((2 (3 4))(5 6)))
2520 (= (nth-set 0 1 l 'new) '(3 4))
2521 (= (nth 0 1 l) 'new)
2522 (set 'L '(a b c (d e f)))
2523 (nth-set 3 L (nth-set 3 L 99))
2524 (= L '(a b c (d e f)))
2528 (define (test-set-ref)
2530 (set 'L '(z a b (z) (d (c c (c)) e f c)))
2531 (= (set-ref (L 'c) 'z) '(z a b (z) (d (z c (c)) e f c)))
2532 (set 'L '((a 1) (b 2) (a 3) (b 4)))
2533 (= (set-ref (L '(a *)) '(z 99) match) '((z 99) (b 2) (a 3) (b 4)))
2534 (= (set-ref (L '(a *)) '(z 99) match) '((z 99) (b 2) (z 99) (b 4)))
2535 (set 'Ct:Ct '(a b c d e f g))
2536 (= (set-ref (Ct 'c) 'z) '(a b z d e f g))
2541 (define (test-set-ref-all)
2543 (set 'L '(z a b (c) (d (c c (c)) e f c)))
2544 (= (set-ref-all (L 'c) 'z) '(z a b (z) (d (z z (z)) e f z)))
2545 (set 'L '((a 1) (b 2) (a 3) (b 4)))
2546 (= (set-ref-all (L '(a *)) '(z 99) match) '((z 99) (b 2) (z 99) (b 4)))
2550 (define (test-ref-set)
2552 (set 'L '(a b (c) d e f g))
2553 (= (ref-set (L 'c) 'z) 'c)
2554 (set 'L '(a b (c) d e f g))
2555 (= (ref-set (L 'c) 'z) 'c)
2559 (define (test-share)
2566 (= (share mvar) 123)
2567 (share mvar 123,456)
2568 (= (share mvar) 123,456)
2569 (share mvar "hello")
2570 (= (share mvar) "hello")))
2573 (define (win32-test-share)
2574 (write-file "sharetest.lsp"
2576 (map set '(sid mm) (map int (slice (main-args) 2)))
2577 (if (= (share mm) "hello") (share mm "HELLO"))
2578 (semaphore sid 1) ; signale parent to read
2583 (set 'sid (semaphore))
2587 (process (string "newlisp sharetest.lsp " sid " " mm))
2588 (process (string "./newlisp sharetest.lsp " sid " " mm)))
2589 (semaphore sid -1) ; wait for child process
2590 (semaphore sid 0) ;; delete semaphore
2591 (= (share mm) "HELLO")
2592 (or (delete-file "sharetest.lsp") true)))
2595 (define (unix-test-share)
2600 (wait-pid (fork (begin
2601 (if (= (share mm) "hello")
2605 (= (share mm) "HELLO")
2606 (share nil mm) ; unmap share
2615 (define (test-signal)
2616 (primitive? signal))
2619 (define (test-silent )
2620 (primitive? silent))
2623 (= 1 (sin (asin (sin (asin 1))))))
2626 (< (abs (sub (tanh 1) (div (sinh 1) (cosh 1)))) 0,0000000001)
2629 (define (test-sleep )
2630 (set 'start (time-of-day))
2632 (set 'start (time-of-day))
2634 (set 'duration (- (time-of-day) start))
2635 (and (> duration 500) (< duration 1500)))
2637 (define (test-slice )
2639 (set 'str "0123456789")
2640 (= (slice str 0 1) "0")
2641 (= (slice str 0 3) "012")
2642 (= (slice str 8 2) "89")
2643 (= (slice str 8 10) "89")
2644 (= (slice str 20 10) "")
2645 (= (slice str 2 -2) "234567")
2646 (= (slice str 2 -5) "234")
2647 (= (slice str 2 -7) "2")
2648 (= (slice str 2 -8) "")
2649 (= (slice str 2 -9) "")
2650 (= (slice '(a b c d e f g) 3 1) '(d))
2651 (= (slice '(a b c d e f g) 3 0) '())
2652 (= (slice '(a b c d e f g) 0 0) '())
2653 (= (slice '(a b c d e f g) 10 10) '())
2654 (= (slice '(a b c d e f g) 3 2) '(d e))
2655 (= (slice '(a b c d e f g) 5) '(f g))
2656 (= (slice '(a b c d e f g) -5 2) '(c d))
2657 (= (slice '(a b c d e f g) -1 -2) '())
2658 (= (slice '(a b c d e f g) 1 -2) '(b c d e))
2659 (= (slice '(a b c d e f g) 4 -2) '(e))
2660 (= (slice '(a b c d e f g) 4 -3) '())
2661 (= (slice '(a b c d e f g) 4 -4) '())
2662 (= (slice '(a b c d e f g) -6 -3) '(b c d))
2664 (= (1 3 '(a b c d e f g)) '(b c d))
2665 (= (-4 2 '(a b c d e f g)) '(d e))
2666 (= (1 3 "abcdefg") "bcd")
2667 (= (-4 2 "abcdefg") "de")
2668 (= (1 -3 "abcdefg") "bcd")
2669 (= (1 -5 "abcdefg") "b")
2670 (= (1 -7 "abcdefg") "")
2672 (= (x y '(a b c d e f g)) '(b c))
2673 (= (x y "abcdefg") "bc")
2674 (= (1 -2 '(a b c d e f g)) '(b c d e))
2675 (= (4 -2 '(a b c d e f g)) '(e))
2676 (= (4 -3 '(a b c d e f g)) '())
2677 (= (4 -4 '(a b c d e f g)) '())
2678 (= (-6 -3 '(a b c d e f g)) '(b c d))
2681 (define (test-sort )
2683 (= '(1 2 3 4 5 6 7 8 9) (sort '(9 1 8 2 7 3 6 4 5)))
2684 (= '(1 2 3 4 5 6 7 8 9) (sort '(9 1 8 2 7 3 6 4 5)))
2685 (= '(1 2 3 4 5 6 7 8 9) (sort '(9 1 8 2 7 3 6 4 5) <))
2686 (= '(9 8 7 6 5 4 3 2 1) (sort '(9 1 8 2 7 3 6 4 5) >))
2687 (= '(1 2 3 4 5 6 7 8 9) (sort '(9 1 8 2 7 3 6 4 5) (fn (x y) (< x y))))
2688 (= '(9 8 7 6 5 4 3 2 1) (sort '(9 1 8 2 7 3 6 4 5) (fn (x y) (> x y))))
2693 (define (test-source)
2694 (= (replace "\r|\n" (source 'test-sin) "" 0)
2695 "(define (test-sin ) (= 1 (sin (asin (sin (asin 1))))))"))
2697 (define (test-sqrt )
2698 (and (= 10 (sqrt 100)) (= 1,2 (sqrt 1,44))))
2700 (define (test-starts-with )
2701 (and (starts-with "newlisp" "new") (starts-with "newlisp" "NEW"
2704 (define (test-string )
2705 (and (string? (string 12345)) (= (string 12345) "12345") (string?
2707 (= (string 'test-string) "test-string")
2708 (string? (string test-string))
2709 (= (string "a" "b" "c") (append "a" "b" "c") "abc")
2710 (= (string "a" 123 "b") "a123b")))
2712 (define (test-string? )
2713 (and (string? "1234") (not (string? 1234))))
2716 (= 0 (sub 0,99999999 0,99999999))
2719 (define (test-swap )
2720 (set 'lst '(1 2 3 4))
2722 (= (swap 1 2 lst) '(1 3 2 4))
2724 (let (a 1 b 2) (and (= (swap a b) 1) (= a 2) (= b 1)))
2729 (and (= (sym "test-sym") 'test-sym)
2730 (= (sym "test-sym" 'QA) 'test-sym)))
2732 (define (test-symbol? )
2734 (symbol? (sym "test-sym"))
2735 (symbol? (sym "a b"))
2739 (define (test-symbols )
2740 (and (list? (symbols)) (> (length (symbols)) 0)))
2742 (define (test-sys-error)
2743 (integer? (sys-error 0) ))
2745 (define (test-sys-info )
2746 (and (list? (sys-info)) (= (length (sys-info)) 8)))
2749 (> 1 (tan (atan (tan (atan 1))))))
2752 (< (abs (sub (sinh 1) (div (sub (exp 1) (exp -1)) 2))) 0,0000000001)
2755 (define (test-throw )
2756 (and (catch (throw (+ 3 4)) 'msg) (= msg 7)))
2758 (define (test-time )
2761 (define (test-time-of-day )
2762 (integer? (time-of-day)))
2764 (define (test-trace )
2768 (define (test-trace-highlight )
2769 (trace-highlight "#" "#"))
2771 (define (test-transpose )
2772 (= '((1) (2) (3)) (transpose '((1 2 3))))
2773 (= '((a b) (c d) (e f)) (transpose '((a c e) (b d f))))
2774 (= '((a d f) (b e g) (c nil nil)) (transpose '((a b c) (d e) (f g))))
2775 (= '((a c f) (b d g)) (transpose '((a b) (c d e) (f g)))))
2777 (define (test-trim )
2779 (= (trim " hello ") "hello")
2780 (= (trim "----hello----" "-") "hello")
2781 (= (trim "----hello====" "-" "=") "hello")
2782 (= (trim "000012345" "0" "") "12345")))
2784 (define (test-true?)
2785 (= (map true? '(x nil 1 nil "hi" ())) '(true nil true nil true nil)))
2788 (define (test-unique )
2789 (= (unique '(2 3 4 4 6 7 8 7)) '(2 3 4 6 7 8)))
2791 (define (test-unify)
2793 (= (unify 'A 'A) '())
2794 (= (unify 'X 123) '((X 123)))
2795 (= (unify '(Int Flt Str Sym Lst) '(123 4,56 "Hello" s '(a b c)))
2796 '((Int 123) (Flt 4,56) (Str "Hello") (Sym s) (Lst '(a b c))))
2797 (= (unify '(A B "hello") '("hi" A Z)) '((A "hi") (B "hi") (Z "hello")))
2798 (= (unify '(A B) '(B abc)) '((A abc) (B abc)))
2799 (= (unify '(B A) '(abc B)) '((B abc) (A abc)))
2800 (= (unify '(A A C D) '(B C 1 C)) '((B 1) (A 1) (C 1) (D 1)))
2801 (= (unify '(D C A A) '(C 1 C B)) '((D 1) (C 1) (B 1) (A 1)))
2802 (= (unify '(f A) '(f (a b c))) '((A (a b c))))
2803 (= (unify '(A f) '((a b c) f)) '((A (a b c))))
2804 (= (unify '(f (g A)) '(f B)) '((B (g A))))
2805 (= (unify '(p X Y a) '(p Y X X)) '((Y a) (X a)))
2806 (= (unify '(p X Y) '(p Y X)) '((Y X)))
2807 (= (unify '(q (p X Y) (p Y X)) '(q Z Z)) '((Y X) (Z (p X X))))
2808 (= (unify '(f (g A) A) '(f B xyz)) '((B (g xyz)) (A xyz)))
2809 (= (unify '(A (g abc)) '(B A)) '((B (g abc)) (A (g abc))))
2810 ;; with additional environment list
2811 (= (unify '(A (B) X) '(A (A) Z) '((A 1) (Z 4)))
2812 ' ((A 1) (Z 4) (B 1) (X 4)))
2815 (define (test-unicode)
2816 (= (utf8 (unicode "newLISP")) "newLISP"))
2818 (define (test-utf8len)
2819 (= 23 (utf8len MAIN:utf8str)))
2821 (define (test-unless )
2825 (define (test-unpack )
2826 (= (pack "c c c" 65 66 67) "ABC")
2827 (= (unpack "c c c" "ABC") '(65 66 67)))
2829 (define (test-until , x)
2831 (= 10 (until (= x 10) (inc 'x)) x))
2833 (define (test-do-until , x)
2836 (= 10 (do-until (= x 10) (inc 'x)) x)
2837 (= 11 (do-until (> x 0) (inc 'x)) x)
2840 (define (test-upper-case )
2842 (= "ABCDEFGQ" (upper-case "abcdefgq"))
2843 (= "ABCDEFGH" (upper-case "abcdefgh"))))
2847 (= (utf8 (unicode "newLISP")) "newLISP")
2851 (= 36 (length (uuid))))
2853 (define (test-wait-pid)
2854 (set 'pid (fork (begin (sleep 200)(exit))))
2859 (= (when true (set 'x 1) (set 'y 2) (set 'z 3)) 3)
2860 (= x 1) (= y 2) (= z 3)
2865 (define (test-while , x)
2868 (= 1000 (while (< x 1000) (inc 'x)) x)
2871 (define (test-do-while, x)
2874 (= 100 (do-while (< x 100) (inc 'x)) x)
2875 (= 101 (do-while (< x 100) (inc 'x)) x)
2878 (define (test-write-buffer )
2880 (dotimes (x 5) (write-buffer str "hello"))
2881 (and (= str "hellohellohellohellohello")
2882 (test-read-buffer)))
2884 (define (test-write-char )
2885 (file-copy "qa-comma" "junk")
2886 (delete-file "junk"))
2888 (define (test-write-file )
2889 (write-file "junk" "newlisp")
2890 (= (read-file "junk") "newlisp"))
2892 (define (test-write-line )
2894 (set 'fle (open "testwrite" "w"))
2895 (write-line "hello" fle)
2897 (set 'fle (open "testwrite" "r"))
2898 (= (read-line fle) "hello")
2900 (delete-file "testwrite") ))
2903 (define (test-xml-error )
2904 (= (xml-error) nil))
2906 (define (test-xml-parse )
2907 (= (xml-parse "<hello att='value'></hello>") '(("ELEMENT" "hello"
2911 (define (test-xml-type-tags )
2912 (length (xml-type-tags) 4))
2914 (define (test-zero?)
2915 (= (map zero? '(1 0 1,2 0,0)) '(nil true nil true)))
2918 (= (| -1431655766 1431655765) -1))
2924 (and (> opsys 5) (< opsys 9)) ;; Win32
2925 (= (format "%I64x" (~ 0xa0a0a0a0a0a0a0a0)) "5f5f5f5f5f5f5f5f")
2928 (= (format "%lx" (~ 0xa0a0a0a0a0a0a0a0)) "5f5f5f5f5f5f5f5f")
2930 (= (format "%llx" (~ 0xa0a0a0a0a0a0a0a0)) "5f5f5f5f5f5f5f5f"))
2933 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN ENTRY POINT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2935 (if (or (not (or (file? "newlisp") (file? "newlisp.exe"))) (not (file? "qa-comma")))
2937 (println "both newlisp(.exe) and qa-comma should be in the current directory.")
2942 (println "Testing built-in functions ...")
2949 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2951 (println "Testing contexts as objects and scoping rules ...")
2954 ;; check creating local symbols
2955 ;; in case they already exist in MAIN
2958 (if (or (!= CTX:var 456) (!= var 123))
2959 (println ">>>>> problem creating local symbols"))
2964 (set 'myprint print)
2966 ;; following would fail without dynamic symbols for non-existing
2967 ;; contexts because 'accnt' is not a context at this moment
2968 (define (report accnt)
2969 (list accnt:name accnt:balance))
2971 ;; late in ACCOUNT the definition of 'deposit' should
2972 ;; should not fail, locals should always be created for
2973 ;; the current context
2974 (constant 'amount 999)
2975 (constant 'stat 999)
2977 ;; the symbol defined should always be forced into the current
2978 ;; context, even if alread exists in MAIN, if not following
2979 ;; definition of 'deposit' would fail
2982 (constant 'withdraw 999)
2984 (define balance 1000.00)
2985 (constant 'phone "123-456-789")
2989 (set 'ACCOUNT:name "") ; force creation of local symbol with
2990 (define balance 0,0) ; same name as built in primitive
2991 (constant 'phone "")
2993 (define (deposit amount)
2994 (inc 'balance amount))
2996 (define (withdraw amount)
2997 (dec 'balance amount))
2999 ; make sure contexts are inherited
3000 ; but not variables containing contexts
3001 (if (not (context? CTX))
3002 (QA:failed ">>>> problem inheriting context symbols"))
3004 ; make sure context variables get not inherited
3005 (if (= ctx CTX) (QA:failed ">>>>> should not inherit context var"))
3009 ; make sure redefined primitives get inherited
3010 (if (not (primitive? myprint))
3011 (QA:failed ">>>> problem inheriting redefined primitives"))
3017 ;; make sure again that context defs did not overwrite MAIN symbols
3018 (if (or (!= deposit 999) (!= clear 999) (!= withdraw 999) (!= stat 999) (!= ctx CTX)
3019 (not (primitive? name)) (!= balance 1000.0) (!= phone "123-456-789"))
3020 (QA:failed ">>>> context definitions are overwriting MAIN"))
3022 (new ACCOUNT 'John true) ; this creates a new context copy of
3023 ; ACCOUNT called 'John' if exists overwrite symbols
3025 (set 'John:name "John Doe")
3026 (set 'John:phone "555-123-456")
3028 (John:deposit 100,00)
3031 (new ACCOUNT 'Anne true)
3033 (set 'Anne:name "Anne Somebody")
3034 (set 'Anne:phone "555-456-123")
3036 (Anne:deposit 120,00)
3038 (if (or (!= John:balance 40) (!= Anne:balance 70))
3039 (QA:failed ">>>> problem with methods in contexts"))
3041 (if (or (!= (report John) (list John:name John:balance))
3042 (!= (report Anne) (list Anne:name Anne:balance)))
3043 (QA:failed ">>>> problem using context variables"))
3045 (if (!= (map report (map eval '(John Anne)))
3046 '(("John Doe" 40) ("Anne Somebody" 70)) )
3047 (QA:failed ">>>> problem mapping functions using context vars"))
3050 ;; dynamic context var as symbol to be defined
3053 (define (ctx:foo x) (+ x x)))
3057 (if (!= (ctx:foo 10) 20)
3058 (QA:failed ">>>> problem with dyna symbols in defined symbol"))
3061 ;; check setq, define (as set) and inc, dec on dynamic context vars
3063 (define (foo-set ct value) (set 'ct:var value))
3064 (define (foo-setq ct value) (setq ct:var value))
3065 (define (foo-define ct value) (define ct:var value))
3066 (define (foo-inc ct value) (inc 'ct:var))
3067 (define (foo-dec ct value) (dec 'ct:var))
3069 (set 'CTX:var 0) ;; make sure var is existent
3072 (QA:failed ">>>> problem with set on context vars"))
3076 (QA:failed ">>>> problem with setq on context vars"))
3080 (QA:failed ">>>> problem with define on context vars"))
3084 (QA:failed ">>>> problem with inc on context vars"))
3088 (QA:failed ">>>> problem with dec on context vars"))
3090 ;; dynamic context vars inside a context (since version 7.5.1)
3094 (define (init ctx value)
3095 (set 'ctx:foo value))
3097 ;; since version 8.7.8 when calling a function in a context the current runtime
3099 (define (test-context-change)
3104 ;; foo does not exist in CTX
3108 (if (!= 999 CTX:foo)
3109 (QA:failed ">>>> problem with dyna vars in contexts"))
3111 ;; now foo does exist
3114 (if (!= 222 CTX:foo)
3115 (QA:failed ">>>> problem with dyna vars in contexts"))
3118 (define (cdf:cdf a b) (+ a b))
3120 (if (!= (cdf 3 4) 7)
3121 (QA:failed ">>>> problem with context default vars"))
3123 ;; check for existence of dynamic context symbol
3125 (define (check-sym-existence ctx)
3126 (if (symbol? 'ctx:foovar) ;; will not create is only check
3127 (QA:failed ">>>> problem with symbol? for dyna vars")))
3129 (check-sym-existence CTX)
3131 ;; do not overwrite existing symbols
3139 (if (not (= Bctx:x 999))
3140 (QA:failed ">>>>> problem with new in overwriting symbols"))
3147 ; (map delete '(Actx Bctx cdf))
3149 (QA:failed ">>>>> problem deleting contexts"))
3151 ;; define static default functions
3153 (define foobar:foobar)
3155 (define (def-static s contents)
3156 (def-new 'contents (sym (name s) s)))
3160 (def-static 'foobar (fn (x) (+ x x)))
3161 (= foobar:foobar (lambda (foobar:x) (+ foobar:x foobar:x)))
3162 (= (foobar 10) 20)))
3163 (QA:failed ">>>>> problem with static default function definition"))
3165 ;; calling into context changes context
3166 (if (not TST:test-context-change)
3167 (QA:failed ">>>>> problem changing runtime context with symbol"))
3169 ;; but calling with raw lambda doesn't
3170 (if ((eval TST:test-context-change))
3171 (QA:failed ">>>>> problem maintaining runtime context with lambda"))
3173 ;; apply evaluates functor
3174 (if (not (apply 'TST:test-context-change))
3175 (QA:failed ">>>>> problem changing runtime context with apply symbol"))
3177 ;; apply evaluates functor
3178 (if (apply TST:test-context-change)
3179 (QA:failed ">>>>> problem maintaining runtime context with apply lambda"))
3181 ;; map evaluates functor
3182 (if (!= (map 'TST:test-context-change '(a b c)) '(true true true))
3183 (QA:failed ">>>>> problem changing runtime context with map symbol"))
3185 ;; map evaluates functor
3186 (if (!= (map TST:test-context-change '(a b c)) '(nil nil nil))
3187 (QA:failed ">>>>> problem maintaining runtime context with map lambda"))
3189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;; testing the default functor ;;;;;;;;;;;;;;;
3191 (define (double:double x) (+ x x))
3193 (define (test-default-functor)
3195 (= (map double '(1 2 3 4 5)) '(2 4 6 8 10))
3196 (= (map 'double '(1 2 3 4 5)) '(2 4 6 8 10))
3197 (set 'dflt:dflt '(a b c d e f g))
3198 (= (map dflt '(1 2 6)) '(b c g))
3199 (set 'i 0 'j -1 'k 6)
3206 (if (not (test-default-functor))
3207 (QA:failed ">>>>> problem testing default functor"))
3210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3212 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3215 (if QA:failed-messages
3217 (println "TESTING: " (main-args 0) " FINISHED WITH ERRORS:")
3219 (dolist (func (reverse QA:failed-messages))
3221 (println "ALL FUNCTIONS FINISHED SUCCESSFULL: " (main-args 0)))
3224 (delete-file "sharetest.lsp")
3225 (delete-file "udptest.lsp")
3228 (println "total time: " (- (time-of-day) start-of-qa))