### Tests of FLOOR, and some infrastructure for generating random inputs (not...

`Tests of FLOOR, and some infrastructure for generating random inputs (not fully used).  I haven't fully tested FLOOR since its standardized behavior in the face of float imprecision is not entirely clear.`
parent be69494d
 ;-*- Mode: Lisp -*- ;;;; Author: Paul Dietz ;;;; Created: Sat Aug 9 08:08:00 2003 ;;;; Contains: Aux. functions used in FLOOR tests (in-package :cl-test) (defun floor.1-fn () (loop for n = (- (random 2000000000) 1000000000) for d = (1+ (random 10000)) for vals = (multiple-value-list (floor n d)) for (q r) = vals for n2 = (+ (* q d) r) repeat 10000 unless (and (eql (length vals) 2) (integerp q) (= n n2) (integerp r) (< -1 r d)) collect (list n d q r n2))) (defun floor.2-fn () (loop for num = (random 1000000000) for denom = (1+ (random 1000)) for n = (/ num denom) for d = (1+ (random 10000)) for vals = (multiple-value-list (floor n d)) for (q r) = vals for n2 = (+ (* q d) r) repeat 10000 unless (and (eql (length vals) 2) (integerp q) (<= 0 r) (< r d) (= n n2)) collect (list n d q r n2))) (defun floor.3-fn (width) (loop for n = (- (random width) (/ width 2)) for vals = (multiple-value-list (floor n)) for (q r) = vals for n2 = (+ q r) repeat 10000 unless (and (eql (length vals) 2) (integerp q) (= n n2) (<= 0 r) (< r 1) ) collect (list n q r n2))) (defun floor.7-fn () (loop for numerator = (- (random 10000000000) 5000000000) for denominator = (1+ (random 100000)) for n = (/ numerator denominator) for vals = (multiple-value-list (floor n)) for (q r) = vals for n2 = (+ q r) repeat 10000 unless (and (eql (length vals) 2) (integerp q) (= n n2) (<= 0 r) (< r 1) ) collect (list n q r n2))) (defun floor.8-fn () (loop for num1 = (- (random 10000000000) 5000000000) for den1 = (1+ (random 100000)) for n = (/ num1 den1) for num2 = (- (1+ (random 1000000))) for den2 = (1+ (random 1000000)) for d = (/ num2 den2) for vals = (multiple-value-list (floor n d)) for (q r) = vals for n2 = (+ (* q d) r) repeat 10000 unless (and (eql (length vals) 2) (integerp q) (>= 0 r) (> r d) (= n n2)) collect (list n q d r n2))) (defun floor.9-fn () (loop for num1 = (- (random 1000000000000000) 500000000000000) for den1 = (1+ (random 10000000000)) for n = (/ num1 den1) for num2 = (- (1+ (random 1000000000))) for den2 = (1+ (random 10000000)) for d = (/ num2 den2) for vals = (multiple-value-list (floor n d)) for (q r) = vals for n2 = (+ (* q d) r) repeat 10000 unless (and (eql (length vals) 2) (integerp q) (>= 0 r) (> r d) (= n n2)) collect (list n q d r n2)))
 ;-*- Mode: Lisp -*- ;;;; Author: Paul Dietz ;;;; Created: Mon Aug 4 22:16:00 2003 ;;;; Contains: Tests of FLOOR (in-package :cl-test) (compile-and-load "numbers-aux.lsp") (compile-and-load "floor-aux.lsp") (deftest floor.error.1 (classify-error (floor)) program-error) (deftest floor.error.2 (classify-error (floor 1.0 1 nil)) program-error) ;;; (deftest floor.1 (floor.1-fn) nil) (deftest floor.2 (floor.2-fn) nil) (deftest floor.3 (floor.3-fn 2.0s4) nil) (deftest floor.4 (floor.3-fn 2.0f4) nil) (deftest floor.5 (floor.3-fn 2.0d4) nil) (deftest floor.6 (floor.3-fn 2.0l4) nil) (deftest floor.7 (floor.7-fn) nil) (deftest floor.8 (floor.8-fn) nil) (deftest floor.9 (floor.9-fn) nil) (deftest floor.10 (loop for x in (remove-if #'zerop *reals*) for (q r) = (multiple-value-list (floor x x)) unless (and (eql q 1) (zerop r) (if (rationalp x) (eql r 0) (eql r (float 0 x)))) collect x) nil) (deftest floor.11 (loop for x in (remove-if #'zerop *reals*) for (q r) = (multiple-value-list (floor (- x) x)) unless (and (eql q -1) (zerop r) (if (rationalp x) (eql r 0) (eql r (float 0 x)))) collect x) nil)