Commit 811de4aa authored by pfdietz's avatar pfdietz

More tests of numeric comparison functions, and begin testing MAX.

parent 0dea93db
......@@ -7,3 +7,4 @@
(compile-and-load "numbers-aux.lsp")
(load "number-comparison.lsp")
(load "max.lsp")
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sun Aug 3 15:55:17 2003
;;;; Contains: Tests of MAX
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(deftest max.error.1
(classify-error (max))
program-error)
(deftest max.error.2
(loop for x in *mini-universe*
unless (or (realp x)
(eq (classify-error** `(classify-error (max ',x)))
'type-error))
collect x)
nil)
(deftest max.1
(loop for n in *reals*
when (or (not (eql (max n) n))
(not (eql (max n n) n))
(not (eql (max n n n) n))
(not (eql (apply #'max (make-list
(min 256 call-arguments-limit)
:initial-element n))
n)))
collect n)
nil)
(deftest max.2
(max.2-fn)
nil)
......@@ -157,6 +157,36 @@
collect (list a b c d)))
nil)
(deftest =.order.1
(let ((i 0) x y)
(values
(= (progn (setf x (incf i)) 1)
(progn (setf y (incf i)) 2))
i x y))
nil 2 1 2)
(deftest =.order.2
(let ((i 0) x y z)
(values
(= (progn (setf x (incf i)) 1)
(progn (setf y (incf i)) 2)
(progn (setf z (incf i)) 3))
i x y z))
nil 3 1 2 3)
(deftest =.order.3
(let ((i 0) u v w x y z)
(values
(=
(progn (setf u (incf i)) 1)
(progn (setf v (incf i)) 2)
(progn (setf w (incf i)) 3)
(progn (setf x (incf i)) 4)
(progn (setf y (incf i)) 5)
(progn (setf z (incf i)) 6))
i u v w x y z))
nil 6 1 2 3 4 5 6)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deftest /=.1
......@@ -270,6 +300,37 @@
collect (list x y))))
nil)
(deftest /=.order.1
(let ((i 0) x y)
(values
(notnot (/= (progn (setf x (incf i)) 1)
(progn (setf y (incf i)) 2)))
i x y))
t 2 1 2)
(deftest /=.order.2
(let ((i 0) x y z)
(values
(notnot (/= (progn (setf x (incf i)) 1)
(progn (setf y (incf i)) 2)
(progn (setf z (incf i)) 3)))
i x y z))
t 3 1 2 3)
(deftest /=.order.3
(let ((i 0) u v w x y z)
(values
(notnot
(/=
(progn (setf u (incf i)) 1)
(progn (setf v (incf i)) 2)
(progn (setf w (incf i)) 3)
(progn (setf x (incf i)) 4)
(progn (setf y (incf i)) 5)
(progn (setf z (incf i)) 6)))
i u v w x y z))
t 6 1 2 3 4 5 6)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deftest <.1
......@@ -409,6 +470,37 @@
(<.10-fn)
nil)
(deftest <.order.1
(let ((i 0) x y)
(values
(notnot (< (progn (setf x (incf i)) 1)
(progn (setf y (incf i)) 2)))
i x y))
t 2 1 2)
(deftest <.order.2
(let ((i 0) x y z)
(values
(notnot (< (progn (setf x (incf i)) 1)
(progn (setf y (incf i)) 2)
(progn (setf z (incf i)) 3)))
i x y z))
t 3 1 2 3)
(deftest <.order.3
(let ((i 0) u v w x y z)
(values
(notnot
(<
(progn (setf u (incf i)) 1)
(progn (setf v (incf i)) 2)
(progn (setf w (incf i)) 3)
(progn (setf x (incf i)) 4)
(progn (setf y (incf i)) 5)
(progn (setf z (incf i)) 6)))
i u v w x y z))
t 6 1 2 3 4 5 6)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deftest <=.1
......@@ -545,6 +637,38 @@
(<=.9-fn)
nil)
(deftest <=.order.1
(let ((i 0) x y)
(values
(notnot (<= (progn (setf x (incf i)) 1)
(progn (setf y (incf i)) 2)))
i x y))
t 2 1 2)
(deftest <=.order.2
(let ((i 0) x y z)
(values
(notnot (<= (progn (setf x (incf i)) 1)
(progn (setf y (incf i)) 2)
(progn (setf z (incf i)) 3)))
i x y z))
t 3 1 2 3)
(deftest <=.order.3
(let ((i 0) u v w x y z)
(values
(notnot
(<=
(progn (setf u (incf i)) 1)
(progn (setf v (incf i)) 2)
(progn (setf w (incf i)) 3)
(progn (setf x (incf i)) 4)
(progn (setf y (incf i)) 5)
(progn (setf z (incf i)) 6)))
i u v w x y z))
t 6 1 2 3 4 5 6)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deftest >.1
......@@ -597,6 +721,37 @@
(>.8-fn)
nil)
(deftest >.order.1
(let ((i 0) x y)
(values
(notnot (> (progn (setf x (incf i)) 2)
(progn (setf y (incf i)) 1)))
i x y))
t 2 1 2)
(deftest >.order.2
(let ((i 0) x y z)
(values
(notnot (> (progn (setf x (incf i)) 3)
(progn (setf y (incf i)) 2)
(progn (setf z (incf i)) 1)))
i x y z))
t 3 1 2 3)
(deftest >.order.3
(let ((i 0) u v w x y z)
(values
(notnot
(>
(progn (setf u (incf i)) 6)
(progn (setf v (incf i)) 5)
(progn (setf w (incf i)) 4)
(progn (setf x (incf i)) 3)
(progn (setf y (incf i)) 2)
(progn (setf z (incf i)) 1)))
i u v w x y z))
t 6 1 2 3 4 5 6)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deftest >=.1
......@@ -652,6 +807,37 @@
(>=.8-fn)
nil)
(deftest >=.order.1
(let ((i 0) x y)
(values
(notnot (>= (progn (setf x (incf i)) 2)
(progn (setf y (incf i)) 1)))
i x y))
t 2 1 2)
(deftest >=.order.2
(let ((i 0) x y z)
(values
(notnot (>= (progn (setf x (incf i)) 3)
(progn (setf y (incf i)) 2)
(progn (setf z (incf i)) 1)))
i x y z))
t 3 1 2 3)
(deftest >=.order.3
(let ((i 0) u v w x y z)
(values
(notnot
(>=
(progn (setf u (incf i)) 6)
(progn (setf v (incf i)) 5)
(progn (setf w (incf i)) 4)
(progn (setf x (incf i)) 3)
(progn (setf y (incf i)) 2)
(progn (setf z (incf i)) 1)))
i u v w x y z))
t 6 1 2 3 4 5 6)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Comparison of rationals
......
......@@ -29,70 +29,58 @@
collect (list x y))))
(defun <.8-fn ()
(loop for x in *numbers*
when (realp x)
(loop for x in *reals*
nconc
(loop for y in *numbers*
when (and (realp y) (and (< x y) (> x y)))
(loop for y in *reals*
when (and (< x y) (> x y))
collect (list x y))))
(defun <.9-fn ()
(loop for x in *numbers*
when (realp x)
(loop for x in *reals*
nconc
(loop for y in *numbers*
when (and (realp y) (if (< x y)
(not (> y x))
(> y x)))
(loop for y in *reals*
when (if (< x y) (not (> y x))
(> y x))
collect (list x y))))
(defun <.10-fn ()
(loop for x in *numbers*
when (realp x)
(loop for x in *reals*
nconc
(loop for y in *numbers*
when (and (realp y) (if (< x y)
(>= x y)
(not (>= x y))))
(loop for y in *reals*
when (if (< x y) (>= x y)
(not (>= x y)))
collect (list x y))))
(defun <=.8-fn ()
(loop for x in *numbers*
when (realp x)
(loop for x in *reals*
nconc
(loop for y in *numbers*
when (and (realp y) (if (<= x y) (not (>= y x))
(>= y x)))
(loop for y in *reals*
when (if (<= x y) (not (>= y x))
(>= y x))
collect (list x y))))
(defun <=.9-fn ()
(loop for x in *numbers*
when (realp x)
(loop for x in *reals*
nconc
(loop for y in *numbers*
when (and (realp y)
(if (<= x y) (not (or (= x y) (< x y)))
(or (= x y) (< x y))))
(loop for y in *reals*
when (if (<= x y) (not (or (= x y) (< x y)))
(or (= x y) (< x y)))
collect (list x y))))
(defun >.8-fn ()
(loop for x in *numbers*
when (realp x)
(loop for x in *reals*
nconc
(loop for y in *numbers*
when (and (realp y) (if (> x y)
(<= x y)
(not (<= x y))))
(loop for y in *reals*
when (if (> x y) (<= x y)
(not (<= x y)))
collect (list x y))))
(defun >=.8-fn ()
(loop for x in *numbers*
when (realp x)
(loop for x in *reals*
nconc
(loop for y in *numbers*
when (and (realp y)
(if (>= x y) (not (or (= x y) (> x y)))
(or (= x y) (> x y))))
(loop for y in *reals*
when (if (>= x y) (not (or (= x y) (> x y)))
(or (= x y) (> x y)))
collect (list x y))))
;;; Comparison of rationsls
......@@ -121,5 +109,11 @@
(if (/= q1 q2) (not (/= ad bc)) (/= ad bc)))))
collect (list a b c d)))
(defun max.2-fn ()
(loop for x in *reals*
nconc
(loop for y in *reals*
for m = (max x y)
unless (and (>= m x) (>= m y)
(or (= m x) (= m y)))
collect (list x y m))))
......@@ -134,6 +134,8 @@
*ratios*
*complexes*))
(defvar *reals* (append *integers* *floats* *ratios*))
(defun try-to-read-chars (&rest namelist)
(loop
for name in namelist append
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment