test.lisp @ 01ba812a486a default tip

More binary primitives
author Steve Losh <steve@stevelosh.com>
date Wed, 10 Mar 2021 22:01:41 -0500
parents 37b7eecfdf6e
children (none)
(ql:quickload '(:1am :losh :alexandria))

(load (compile-file "iacc.lisp"))

(defpackage :iacc/test
  (:use :cl :losh)
  (:use :iacc)
  (:export horrifying-repl))

(in-package :iacc/test)

(defun run (program)
  (iacc:compile-program program)
  (losh:sh '("make" "prog"))
  (string-trim '(#\newline) (losh:sh "./prog" :result-type 'string)))

(defun repl ()
  (loop :for program = (progn (write-string "> ")
                              (force-output)
                              (read))
        :until (equal program 'q)
        :do (write-line (run program))))

(defun reload ()
  (load (compile-file "test.lisp")))

(defun run-tests ()
  (let ((*print-level* 50))
    (time (1am:run))))


(defmacro define-test (name &body body)
  `(1am:test ,(intern (concatenate 'string (symbol-name 'test/) (symbol-name name)))
    (let ((*package* ,*package*))
      ,@body)))

(defmacro check (program expected)
  `(1am:is (string= ,expected (run ,program))))

(define-test fixnums
  (check 0 "0")
  (check 1 "1")
  (check -1 "-1")
  (check 10 "10")
  (check -10 "-10")
  (check 2736 "2736")
  (check -2736 "-2736")
  (check 536870911 "536870911")
  (check -536870912 "-536870912"))

(define-test booleans
  (check :true "#t")
  (check :false "#f"))

(define-test null
  (check nil "()"))

(define-test characters
  (check #\a "#\\a")
  (check #\A "#\\A")
  (check #\space "#\\ "))

(define-test primitives/fxadd1
  (check '(fxadd1 0) "1")
  (check '(fxadd1 99) "100")
  (check '(fxadd1 (fxadd1 202)) "204")
  (check '(fxadd1 (fxadd1 -6)) "-4")
  (check '(fxadd1 -1) "0")
  (check '(fxadd1 1) "2")
  (check '(fxadd1 -100) "-99")
  (check '(fxadd1 1000) "1001")
  (check '(fxadd1 536870910) "536870911")
  (check '(fxadd1 -536870912) "-536870911")
  (check '(fxadd1 (fxadd1 0)) "2")
  (check '(fxadd1 (fxadd1 (fxadd1 (fxadd1 (fxadd1 (fxadd1 12)))))) "18"))

(define-test primitives/fxsub1
  (check '(fxsub1 1) "0")
  (check '(fxsub1 0) "-1")
  (check '(fxsub1 -1) "-2")
  (check '(fxsub1 99) "98")
  (check '(fxsub1 (fxsub1 202)) "200")
  (check '(fxsub1 (fxadd1 -6)) "-6")
  (check '(fxsub1 -100) "-101")
  (check '(fxsub1 1000) "999")
  (check '(fxsub1 536870911) "536870910")
  (check '(fxsub1 -536870911) "-536870912")
  (check '(fxsub1 (fxsub1 0)) "-2")
  (check '(fxsub1 (fxsub1 (fxsub1 (fxsub1 (fxsub1 (fxsub1 12)))))) "6")
  (check '(fxsub1 (fxadd1 0)) "0"))

(define-test primitives/fxlognot
  (check '(fxlognot 0) "-1")
  (check '(fxlognot -1) "0")
  (check '(fxlognot 1) "-2")
  (check '(fxlognot -2) "1")
  (check '(fxlognot 536870911) "-536870912")
  (check '(fxlognot -536870912) "536870911")
  (check '(fxlognot (fxlognot 237463)) "237463"))

(define-test primitives/char-fixnum-conversion
  (check '(fixnum->char (fxadd1 (char->fixnum #\A))) "#\\B")
  (check '(fixnum->char 65) "#\\A")
  (check '(fixnum->char 97) "#\\a")
  (check '(fixnum->char 122) "#\\z")
  (check '(fixnum->char 90) "#\\Z")
  (check '(fixnum->char 48) "#\\0")
  (check '(fixnum->char 57) "#\\9")
  (check '(char->fixnum #\A) "65")
  (check '(char->fixnum #\a) "97")
  (check '(char->fixnum #\z) "122")
  (check '(char->fixnum #\Z) "90")
  (check '(char->fixnum #\0) "48")
  (check '(char->fixnum #\9) "57")
  (check '(char->fixnum (fixnum->char 12)) "12")
  (check '(fixnum->char (char->fixnum #\x)) "#\\x"))

(define-test primitives/fixnum?
  (check '(fixnum? 1)      "#t")
  (check '(fixnum? 0)      "#t")
  (check '(fixnum? -1)     "#t")
  (check '(fixnum? nil)    "#f")
  (check '(fixnum? :true)  "#f")
  (check '(fixnum? :false) "#f")
  (check '(fixnum? #\A)    "#f")
  (check '(fixnum? 37287) "#t")
  (check '(fixnum? -23873) "#t")
  (check '(fixnum? 536870911) "#t")
  (check '(fixnum? -536870912) "#t")
  (check '(fixnum? (fixnum? 12)) "#f")
  (check '(fixnum? (fixnum? :false)) "#f")
  (check '(fixnum? (fixnum? #\A)) "#f")
  (check '(fixnum? (char->fixnum #\r)) "#t")
  (check '(fixnum? (fixnum->char 12)) "#f"))

(define-test primitives/boolean?
  (check '(boolean? 1)      "#f")
  (check '(boolean? 0)      "#f")
  (check '(boolean? -1)     "#f")
  (check '(boolean? nil)    "#f")
  (check '(boolean? :true)  "#t")
  (check '(boolean? :false) "#t")
  (check '(boolean? #\A)    "#f"))

(define-test primitives/char?
  (check '(char? 1)      "#f")
  (check '(char? 0)      "#f")
  (check '(char? -1)     "#f")
  (check '(char? nil)    "#f")
  (check '(char? :true)  "#f")
  (check '(char? :false) "#f")
  (check '(char? #\A)    "#t"))

(define-test primitives/null?
  (check '(null? 1)      "#f")
  (check '(null? 0)      "#f")
  (check '(null? -1)     "#f")
  (check '(null? nil)    "#t")
  (check '(null? :true)  "#f")
  (check '(null? :false) "#f")
  (check '(null? #\A)    "#f"))

(define-test primitives/fxzero?
  (check '(fxzero? 1)      "#f")
  (check '(fxzero? 0)      "#t")
  (check '(fxzero? -1)     "#f")
  (check '(fxzero? nil)    "#f")
  (check '(fxzero? :true)  "#f")
  (check '(fxzero? :false) "#f")
  (check '(fxzero? #\A)    "#f"))

(define-test primitives/not
  (check '(not 1)      "#f")
  (check '(not 0)      "#f")
  (check '(not -1)     "#f")
  (check '(not nil)    "#f")
  (check '(not :true)  "#f")
  (check '(not :false) "#t")
  (check '(not #\A)    "#f")
  (check '(not (not :true)) "#t")
  (check '(not (not :false)) "#f")
  (check '(not (not 15)) "#t")
  (check '(not (fixnum? 15)) "#f")
  (check '(not (fixnum? :false)) "#t"))

(define-test if
  (check '(if :true 1 2) "1")
  (check '(if :false 1 2) "2")
  (check '(if nil 1 2) "1")
  (check '(if :true 12 13) "12")
  (check '(if :false 12 13) "13")
  (check '(if 0 12 13)  "12")
  (check '(if () 43 ()) "43")
  (check '(if :true (if 12 13 4) 17) "13")
  (check '(if :false 12 (if :false 13 4)) "4")
  (check '(if #\X (if 1 2 3) (if 4 5 6)) "2")
  (check '(if (not (boolean? :true)) 15 (boolean? :false)) "#t")
  (check '(if (if (char? #\a) (boolean? #\b) (fixnum? #\c)) 119 -23) "-23")
  (check '(if (if (if (not 1) (not 2) (not 3)) 4 5) 6 7) "6")
  (check '(if (not (if (if (not 1) (not 2) (not 3)) 4 5)) 6 7) "7")
  (check '(not (if (not (if (if (not 1) (not 2) (not 3)) 4 5)) 6 7)) "#f")
  (check '(if (char? 12) 13 14) "14")
  (check '(if (char? #\a) 13 14) "13")
  (check '(fxadd1 (if (fxsub1 1) (fxsub1 13) 14)) "13")
  (check '(if (fx= 12 13) 12 13) "13")
  (check '(if (fx= 12 12) 13 14) "13")
  (check '(if (fx< 12 13) 12 13) "12")
  (check '(if (fx< 12 12) 13 14) "14")
  (check '(if (fx< 13 12) 13 14) "14")
  (check '(if (fx<= 12 13) 12 13) "12")
  (check '(if (fx<= 12 12) 12 13) "12")
  (check '(if (fx<= 13 12) 13 14) "14")
  (check '(if (fx> 12 13) 12 13) "13")
  (check '(if (fx> 12 12) 12 13) "13")
  (check '(if (fx> 13 12) 13 14) "13")
  (check '(if (fx>= 12 13) 12 13) "13")
  (check '(if (fx>= 12 12) 12 13) "12")
  (check '(if (fx>= 13 12) 13 14) "13"))

(define-test if/predicate-fusion
  (check '(if (null? nil) 1 2) "1")
  (check '(if (null? 1) 1 2) "2")
  (check '(if (char? nil) 1 2) "2")
  (check '(if (char? #\A) 1 2) "1")
  (check '(if (boolean? :true) 1 2) "1")
  (check '(if (boolean? :false) 1 2) "1")
  (check '(if (boolean? nil) 1 2) "2")
  (check '(if (boolean? 999) 1 2) "2")
  (check '(if (fixnum? 0) 1 2) "1")
  (check '(if (fixnum? #\x) 1 2) "2")
  (check '(if (fxzero? 0) 1 2) "1")
  (check '(if (fxzero? 99) 1 2) "2")
  (check '(if (not :false) 1 2) "1")
  (check '(if (not :true) 1 2) "2")
  (check '(if (not nil) 1 2) "2")
  (check '(if (not (fixnum? 0)) 1 2) "2")
  (check '(if (not (fixnum? #\x)) 1 2) "1")

  (check '(if (fx= 6 0) 1 2) "2")
  (check '(if (fx= 0 6) 1 2) "2")
  (check '(if (fx= 0 0) 1 2) "1")

  (check '(if (fx< 6 0) 1 2) "2")
  (check '(if (fx< 0 6) 1 2) "1")
  (check '(if (fx< 0 0) 1 2) "2")

  (check '(if (fx> 6 0) 1 2) "1")
  (check '(if (fx> 0 6) 1 2) "2")
  (check '(if (fx> 0 0) 1 2) "2")

  (check '(if (fx>= 6 0) 1 2) "1")
  (check '(if (fx>= 0 6) 1 2) "2")
  (check '(if (fx>= 0 0) 1 2) "1")

  (check '(if (fx<= 6 0) 1 2) "2")
  (check '(if (fx<= 0 6) 1 2) "1")
  (check '(if (fx<= 0 0) 1 2) "1"))

(define-test primitives/simple-combos
  (check '(fxzero? (fxsub1 (fxadd1 0))) "#t")
  (check '(boolean? (fixnum? 1)) "#t")
  (check '(boolean? (boolean? 1)) "#t")
  (check '(fixnum? (char->fixnum #\A)) "#t")
  (check '(char? (fixnum->char (fxadd1 65))) "#t")
  (check '(boolean? (not 1)) "#t")
  (check '(not (boolean? (not 1))) "#f")
  (check '(not (not (boolean? (not 1)))) "#t"))

(define-test primitives/fx+
  (check '(fx+ 1 2) "3")
  (check '(fx+ 1 -2) "-1")
  (check '(fx+ -1 2) "1")
  (check '(fx+ -1 -2) "-3")
  (check '(fx+ 536870911 -1) "536870910")
  (check '(fx+ 536870910 1) "536870911")
  (check '(fx+ -536870912 1) "-536870911")
  (check '(fx+ -536870911 -1) "-536870912")
  (check '(fx+ 536870911 -536870912) "-1")
  (check '(fx+ 1 (fx+ 2 3)) "6")
  (check '(fx+ 1 (fx+ 2 -3)) "0")
  (check '(fx+ 1 (fx+ -2 3)) "2")
  (check '(fx+ 1 (fx+ -2 -3)) "-4")
  (check '(fx+ -1 (fx+ 2 3)) "4")
  (check '(fx+ -1 (fx+ 2 -3)) "-2")
  (check '(fx+ -1 (fx+ -2 3)) "0")
  (check '(fx+ -1 (fx+ -2 -3)) "-6")
  (check '(fx+ (fx+ 1 2) 3) "6")
  (check '(fx+ (fx+ 1 2) -3) "0")
  (check '(fx+ (fx+ 1 -2) 3) "2")
  (check '(fx+ (fx+ 1 -2) -3) "-4")
  (check '(fx+ (fx+ -1 2) 3) "4")
  (check '(fx+ (fx+ -1 2) -3) "-2")
  (check '(fx+ (fx+ -1 -2) 3) "0")
  (check '(fx+ (fx+ -1 -2) -3) "-6")
  (check '(fx+ (fx+ (fx+ (fx+ (fx+ (fx+ (fx+ (fx+ 1 2) 3) 4) 5) 6) 7) 8) 9) "45")
  (check '(fx+ 1 (fx+ 2 (fx+ 3 (fx+ 4 (fx+ 5 (fx+ 6 (fx+ 7 (fx+ 8 9)))))))) "45"))

(define-test primitives/fx-
  (check '(fx- 1 2) "-1")
  (check '(fx- 1 -2) "3")
  (check '(fx- -1 2) "-3")
  (check '(fx- -1 -2) "1")
  (check '(fx- 536870910 -1) "536870911")
  (check '(fx- 536870911 1) "536870910")
  (check '(fx- -536870911 1) "-536870912")
  (check '(fx- -536870912 -1) "-536870911")
  (check '(fx- 1 536870911) "-536870910")
  (check '(fx- -1 536870911) "-536870912")
  (check '(fx- 1 -536870910) "536870911")
  (check '(fx- -1 -536870912) "536870911")
  (check '(fx- 536870911 536870911) "0")
  (check '(fx- -536870911 -536870912) "1")
  (check '(fx- 1 (fx- 2 3)) "2")
  (check '(fx- 1 (fx- 2 -3)) "-4")
  (check '(fx- 1 (fx- -2 3)) "6")
  (check '(fx- 1 (fx- -2 -3)) "0")
  (check '(fx- -1 (fx- 2 3)) "0")
  (check '(fx- -1 (fx- 2 -3)) "-6")
  (check '(fx- -1 (fx- -2 3)) "4")
  (check '(fx- -1 (fx- -2 -3)) "-2")
  (check '(fx- 0 (fx- -2 -3)) "-1")
  (check '(fx- (fx- 1 2) 3) "-4")
  (check '(fx- (fx- 1 2) -3) "2")
  (check '(fx- (fx- 1 -2) 3) "0")
  (check '(fx- (fx- 1 -2) -3) "6")
  (check '(fx- (fx- -1 2) 3) "-6")
  (check '(fx- (fx- -1 2) -3) "0")
  (check '(fx- (fx- -1 -2) 3) "-2")
  (check '(fx- (fx- -1 -2) -3) "4")
  (check '(fx- (fx- (fx- (fx- (fx- (fx- (fx- (fx- 1 2) 3) 4) 5) 6) 7) 8) 9) "-43")
  (check '(fx- 1 (fx- 2 (fx- 3 (fx- 4 (fx- 5 (fx- 6 (fx- 7 (fx- 8 9)))))))) "5"))

(define-test primitives/fx*
  (check '(fx* 2 3) "6")
  (check '(fx* 2 -3) "-6")
  (check '(fx* -2 3) "-6")
  (check '(fx* -2 -3) "6")
  (check '(fx* 536870911 1) "536870911")
  (check '(fx* 536870911 -1) "-536870911")
  (check '(fx* -536870912 1) "-536870912")
  (check '(fx* -536870911 -1) "536870911")
  (check '(fx* 2 (fx* 3 4)) "24")
  (check '(fx* (fx* 2 3) 4) "24")
  (check '(fx* (fx* (fx* (fx* (fx* 2 3) 4) 5) 6) 7) "5040")
  (check '(fx* 2 (fx* 3 (fx* 4 (fx* 5 (fx* 6 7))))) "5040"))

(define-test primitives/fxbitops
  (check '(fxlogand 3 7) "3")
  (check '(fxlogand 3 5) "1")
  (check '(fxlogand 2346 (fxlognot 2346)) "0")
  (check '(fxlogand (fxlognot 2346) 2346) "0")
  (check '(fxlogand 2376 2376) "2376")
  (check '(fxlogor 3 16) "19")
  (check '(fxlogor 3 5)  "7")
  (check '(fxlogor 3 7)  "7")
  (check '(fxlognot (fxlogor (fxlognot 7) 1)) "6")
  (check '(fxlognot (fxlogor 1 (fxlognot 7))) "6"))

(define-test primitives/fx=
  (check '(fx= 0 0)            "#t")
  (check '(fx= 0 1)            "#f")
  (check '(fx= (fx+ 1 2) 3)    "#t")
  (check '(fx= 3 (fx+ 1 2))    "#t")
  (check '(fx= (fx+ 2 2) 3)    "#f")
  (check '(fx= 3 (fx+ 2 2))    "#f")
  (check '(fx= 12 13)          "#f")
  (check '(fx= 12 12)          "#t")
  (check '(fx= 16 (fx+ 13 3))  "#t")
  (check '(fx= 16 (fx+ 13 13)) "#f")
  (check '(fx= (fx+ 13 3) 16)  "#t")
  (check '(fx= (fx+ 13 13) 16) "#f"))

(define-test primitives/fx<
  (check '(fx< 0 0)         "#f")
  (check '(fx< 0 1)         "#t")
  (check '(fx< 1 0)         "#f")
  (check '(fx< (fx+ 1 2) 3) "#f")
  (check '(fx< (fx+ 1 2) 4) "#t")
  (check '(fx< -3 1)        "#t")
  (check '(fx< 1 -3)        "#f")
  (check '(fx< 12 13) "#t")
  (check '(fx< 12 12) "#f")
  (check '(fx< 13 12) "#f")
  (check '(fx< 16 (fx+ 13 1)) "#f")
  (check '(fx< 16 (fx+ 13 3)) "#f")
  (check '(fx< 16 (fx+ 13 13)) "#t")
  (check '(fx< (fx+ 13 1) 16) "#t")
  (check '(fx< (fx+ 13 3) 16) "#f")
  (check '(fx< (fx+ 13 13) 16) "#f"))

(define-test primitives/fx<=
  (check '(fx<= 0 0)         "#t")
  (check '(fx<= 0 1)         "#t")
  (check '(fx<= 1 0)         "#f")
  (check '(fx<= (fx+ 1 2) 3) "#t")
  (check '(fx<= (fx+ 1 2) 4) "#t")
  (check '(fx<= (fx+ 9 2) 4) "#f")
  (check '(fx<= -3 1)        "#t")
  (check '(fx<= 1 -3)        "#f")
  (check '(fx<= 12 13) "#t")
  (check '(fx<= 12 12) "#t")
  (check '(fx<= 13 12) "#f")
  (check '(fx<= 16 (fx+ 13 1)) "#f")
  (check '(fx<= 16 (fx+ 13 3)) "#t")
  (check '(fx<= 16 (fx+ 13 13)) "#t")
  (check '(fx<= (fx+ 13 1) 16) "#t")
  (check '(fx<= (fx+ 13 3) 16) "#t")
  (check '(fx<= (fx+ 13 13) 16) "#f"))

(define-test primitives/fx>
  (check '(fx> 0 0)         "#f")
  (check '(fx> 1 0)         "#t")
  (check '(fx> 0 1)         "#f")
  (check '(fx> 3 (fx+ 1 2)) "#f")
  (check '(fx> 4 (fx+ 1 2)) "#t")
  (check '(fx> 1 -3)        "#t")
  (check '(fx> -3 1)        "#f")
  (check '(fx<= 12 13) "#t")
  (check '(fx<= 12 12) "#t")
  (check '(fx<= 13 12) "#f")
  (check '(fx<= 16 (fx+ 13 1)) "#f")
  (check '(fx<= 16 (fx+ 13 3)) "#t")
  (check '(fx<= 16 (fx+ 13 13)) "#t")
  (check '(fx<= (fx+ 13 1) 16) "#t")
  (check '(fx<= (fx+ 13 3) 16) "#t")
  (check '(fx<= (fx+ 13 13) 16) "#f"))

(define-test primitives/fx>=
  (check '(fx>= 0 0)         "#t")
  (check '(fx>= 1 0)         "#t")
  (check '(fx>= 0 1)         "#f")
  (check '(fx>= 3 (fx+ 1 2)) "#t")
  (check '(fx>= 4 (fx+ 1 2)) "#t")
  (check '(fx>= 4 (fx+ 9 2)) "#f")
  (check '(fx>= 1 -3)        "#t")
  (check '(fx>= -3 1)        "#f")
  (check '(fx>= 12 13) "#f")
  (check '(fx>= 12 12) "#t")
  (check '(fx>= 13 12) "#t")
  (check '(fx>= 16 (fx+ 13 1)) "#t")
  (check '(fx>= 16 (fx+ 13 3)) "#t")
  (check '(fx>= 16 (fx+ 13 13)) "#f")
  (check '(fx>= (fx+ 13 1) 16) "#f")
  (check '(fx>= (fx+ 13 3) 16) "#t")
  (check '(fx>= (fx+ 13 13) 16) "#t"))

(define-test primitives/binary-combos
  (check '(fxlognot -7) "6")
  (check '(fxlognot (fxlogor (fxlognot 7) 1)) "6")
  (check '(fxlognot (fxlogor (fxlognot 7) (fxlognot 2))) "2")
  (check '(fxlogand (fxlognot (fxlognot 12)) (fxlognot (fxlognot 12))) "12")
  (check '(fx+ (fx+ 1 2) (fx+ 3 4)) "10")
  (check '(fx+ (fx+ 1 2) (fx+ 3 -4)) "2")
  (check '(fx+ (fx+ 1 2) (fx+ -3 4)) "4")
  (check '(fx+ (fx+ 1 2) (fx+ -3 -4)) "-4")
  (check '(fx+ (fx+ 1 -2) (fx+ 3 4)) "6")
  (check '(fx+ (fx+ 1 -2) (fx+ 3 -4)) "-2")
  (check '(fx+ (fx+ 1 -2) (fx+ -3 4)) "0")
  (check '(fx+ (fx+ 1 -2) (fx+ -3 -4)) "-8")
  (check '(fx+ (fx+ -1 2) (fx+ 3 4)) "8")
  (check '(fx+ (fx+ -1 2) (fx+ 3 -4)) "0")
  (check '(fx+ (fx+ -1 2) (fx+ -3 4)) "2")
  (check '(fx+ (fx+ -1 2) (fx+ -3 -4)) "-6")
  (check '(fx+ (fx+ -1 -2) (fx+ 3 4)) "4")
  (check '(fx+ (fx+ -1 -2) (fx+ 3 -4)) "-4")
  (check '(fx+ (fx+ -1 -2) (fx+ -3 4)) "-2")
  (check '(fx+ (fx+ -1 -2) (fx+ -3 -4)) "-10")
  (check '(fx+ (fx+ (fx+ (fx+ (fx+ (fx+ (fx+ (fx+ 1 2) 3) 4) 5) 6) 7) 8) 9) "45")
  (check '(fx+ 1 (fx+ 2 (fx+ 3 (fx+ 4 (fx+ 5 (fx+ 6 (fx+ 7 (fx+ 8 9)))))))) "45")
  (check '(fx+ (fx+ (fx+ (fx+ 1 2) (fx+ 3 4)) (fx+ (fx+ 5 6) (fx+ 7 8))) (fx+ (fx+ (fx+ 9 10) (fx+ 11 12)) (fx+ (fx+ 13 14) (fx+ 15 16)))) "136")
  (check '(fx- (fx- 1 2) (fx- 3 4)) "0")
  (check '(fx- (fx- 1 2) (fx- 3 -4)) "-8")
  (check '(fx- (fx- 1 2) (fx- -3 4)) "6")
  (check '(fx- (fx- 1 2) (fx- -3 -4)) "-2")
  (check '(fx- (fx- 1 -2) (fx- 3 4)) "4")
  (check '(fx- (fx- 1 -2) (fx- 3 -4)) "-4")
  (check '(fx- (fx- 1 -2) (fx- -3 4)) "10")
  (check '(fx- (fx- 1 -2) (fx- -3 -4)) "2")
  (check '(fx- (fx- -1 2) (fx- 3 4)) "-2")
  (check '(fx- (fx- -1 2) (fx- 3 -4)) "-10")
  (check '(fx- (fx- -1 2) (fx- -3 4)) "4")
  (check '(fx- (fx- -1 2) (fx- -3 -4)) "-4")
  (check '(fx- (fx- -1 -2) (fx- 3 4)) "2")
  (check '(fx- (fx- -1 -2) (fx- 3 -4)) "-6")
  (check '(fx- (fx- -1 -2) (fx- -3 4)) "8")
  (check '(fx- (fx- -1 -2) (fx- -3 -4)) "0")
  (check '(fx- (fx- (fx- (fx- (fx- (fx- (fx- (fx- 1 2) 3) 4) 5) 6) 7) 8) 9) "-43")
  (check '(fx- 1 (fx- 2 (fx- 3 (fx- 4 (fx- 5 (fx- 6 (fx- 7 (fx- 8 9)))))))) "5")
  (check '(fx- (fx- (fx- (fx- 1 2) (fx- 3 4)) (fx- (fx- 5 6) (fx- 7 8)))
            (fx- (fx- (fx- 9 10) (fx- 11 12)) (fx- (fx- 13 14) (fx- 15 16))))
         "0")
  (check '(fx* (fx* (fx* (fx* 2 3) (fx* 4 5)) (fx* (fx* 6 7) (fx* 8 9))) (fx* (fx* (fx* 2 3) (fx* 2 3)) (fx* (fx* 2 3) (fx* 2 3)))) "470292480")
  (check '(fxlognot (fxlogor (fxlognot 7) 1)) "6")
  (check '(fxlognot (fxlogor (fxlognot 7) (fxlognot 2))) "2")
  (check '(fxlogand (fxlognot (fxlognot 12)) (fxlognot (fxlognot 12))) "12")
  (check '(fx= (fx+ 13 3) (fx+ 10 6)) "#t")
  (check '(fx= (fx+ 13 0) (fx+ 10 6)) "#f")
  (check '(fx= (fx+ 12 1) (fx+ -12 -1)) "#f")
  (check '(fx< (fx+ 10 6) (fx+ 13 1)) "#f")
  (check '(fx< (fx+ 10 6) (fx+ 13 3)) "#f")
  (check '(fx< (fx+ 10 6) (fx+ 13 31)) "#t")
  (check '(fx< (fx+ 12 1) (fx+ -12 -1)) "#f")
  (check '(fx< (fx+ -12 -1) (fx+ 12 1)) "#t")
  (check '(fx<= (fx+ 10 6) (fx+ 13 1)) "#f")
  (check '(fx<= (fx+ 10 6) (fx+ 13 3)) "#t")
  (check '(fx<= (fx+ 10 6) (fx+ 13 31)) "#t")
  (check '(fx<= (fx+ 12 1) (fx+ -12 -1)) "#f")
  (check '(fx<= (fx+ -12 -1) (fx+ 12 1)) "#t")
  (check '(fx> (fx+ 10 6) (fx+ 13 1)) "#t")
  (check '(fx> (fx+ 10 6) (fx+ 13 3)) "#f")
  (check '(fx> (fx+ 10 6) (fx+ 13 31)) "#f")
  (check '(fx> (fx+ 12 1) (fx+ -12 -1)) "#t")
  (check '(fx> (fx+ -12 -1) (fx+ 12 1)) "#f")
  (check '(fx>= (fx+ 10 6) (fx+ 13 1)) "#t")
  (check '(fx>= (fx+ 10 6) (fx+ 13 3)) "#t")
  (check '(fx>= (fx+ 10 6) (fx+ 13 31)) "#f")
  (check '(fx>= (fx+ 12 1) (fx+ -12 -1)) "#t")
  (check '(fx>= (fx+ -12 -1) (fx+ 12 1)) "#f"))

(define-test primitives/char=
  (check '(char= #\A #\A)             "#t")
  (check '(char= #\A #\B)             "#f")
  (check '(char= #\B #\A)             "#f")
  (check '(char= #\a #\A)             "#f")
  (check '(char= #\newline #\x)       "#f")
  (check '(char= #\x #\newline)       "#f")
  (check '(char= #\newline #\newline) "#t"))

(define-test primitives/char<
  (check '(char< #\A #\A)             "#f")
  (check '(char< #\A #\B)             "#t")
  (check '(char< #\B #\A)             "#f")
  (check '(char< #\a #\A)             "#f")
  (check '(char< #\newline #\x)       "#t")
  (check '(char< #\x #\newline)       "#f")
  (check '(char< #\newline #\newline) "#f"))

(define-test primitives/char>
  (check '(char> #\A #\A)             "#f")
  (check '(char> #\B #\A)             "#t")
  (check '(char> #\A #\B)             "#f")
  (check '(char> #\A #\a)             "#f")
  (check '(char> #\x #\newline)       "#t")
  (check '(char> #\newline #\x)       "#f")
  (check '(char> #\newline #\newline) "#f"))

(define-test primitives/char<=
  (check '(char<= #\A #\A)             "#t")
  (check '(char<= #\A #\B)             "#t")
  (check '(char<= #\B #\A)             "#f")
  (check '(char<= #\a #\A)             "#f")
  (check '(char<= #\newline #\x)       "#t")
  (check '(char<= #\x #\newline)       "#f")
  (check '(char<= #\newline #\newline) "#t"))

(define-test primitives/char>
  (check '(char>= #\A #\A)             "#t")
  (check '(char>= #\B #\A)             "#t")
  (check '(char>= #\A #\B)             "#f")
  (check '(char>= #\A #\a)             "#f")
  (check '(char>= #\x #\newline)       "#t")
  (check '(char>= #\newline #\x)       "#f")
  (check '(char>= #\newline #\newline) "#t"))