Add some tests for the new functions
authorOwen Rodley <Strigoides@gmail.com>
Sat, 18 May 2013 23:17:23 +0000 (11:17 +1200)
committerOwen Rodley <Strigoides@gmail.com>
Sun, 19 May 2013 23:07:22 +0000 (11:07 +1200)
tests/numbers.lisp

index bccde55..f58473f 100644 (file)
 (test      (oddp -3))
 (test (not (oddp  2)))
 (test (not (oddp  0)))
+
+; +, -, *, /
+; The builtin definition of these is variadic, but the function definition
+; should be as well. So, test it using MAPCAR
+(let* ((a '(1 2))
+       (b a)
+       (c a))
+  (test (equal (mapcar #'+ a b c) '( 3  6)))
+  (test (equal (mapcar #'- a b c) '(-1 -2)))
+  (test (equal (mapcar #'* a b c) '( 1  8)))
+  ; This test will need to be changed when rationals are introduced
+  (test (equal (mapcar #'/ a b c) '( 1  0.5))))
+
+; >, >=, =, <, <=, /=
+; As above, we need to make sure the function is called, not the builtin
+(let ((a '(1 3 1 2 1))
+      (b '(2 2 2 2 1))
+      (c '(3 1 2 1 1)))
+  (test (equal (mapcar #'>  a b c) '(nil   t nil nil nil)))
+  (test (equal (mapcar #'>= a b c) '(nil   t nil   t   t)))
+  (test (equal (mapcar #'=  a b c) '(nil nil nil nil   t)))
+  (test (equal (mapcar #'<  a b c) '(  t nil nil nil nil)))
+  (test (equal (mapcar #'<= a b c) '(  t nil   t nil   t)))
+  (test (equal (mapcar #'/= a b c) '(  t   t nil nil nil))))
+
+; INTEGERP
+(test (integerp  1))
+(test (integerp -1))
+(test (integerp  0))
+
+; FLOATP
+(expected-failure (floatp    1.0)) ; The reader reads 1.0 as an int 
+(test             (floatp    1.1))
+(test             (floatp    pi))
+(test             (floatp (- pi)))
+(test        (not (floatp    1)))