rational.lsp 1.53 KB
 1 2 3 4 5 6 7 8 ``````;-*- Mode: Lisp -*- ;;;; Author: Paul Dietz ;;;; Created: Mon Sep 1 13:49:18 2003 ;;;; Contains: Tests of RATIONAL (in-package :cl-test) (deftest rational.error.1 `````` pfdietz committed Jan 17, 2004 9 10 `````` (signals-error (rational) program-error) t) `````` 11 12 `````` (deftest rational.error.2 `````` pfdietz committed Jan 17, 2004 13 14 `````` (signals-error (rational 0 nil) program-error) t) `````` 15 16 `````` (deftest rational.error.3 `````` pfdietz committed Jan 17, 2004 17 18 `````` (signals-error (rational 0 0) program-error) t) `````` 19 20 `````` (deftest rational.error.4 `````` pfdietz committed May 06, 2005 21 `````` (check-type-error #'rational #'realp) `````` 22 23 24 `````` nil) (deftest rational.1 `````` pfdietz committed Feb 08, 2004 25 `````` (loop for x in (loop for r in *reals* `````` sds committed Aug 12, 2009 26 27 28 29 30 31 32 33 34 `````` when (or (not (floatp r)) (<= -1000 (nth-value 1 (integer-decode-float r)) 1000)) collect r) for r = (rational x) unless (and (rationalp r) (if (floatp x) (= (float r x) x) (eql x r))) collect (list x r)) `````` 35 36 37 38 `````` nil) (deftest rational.2 (loop for type in '(short-float single-float double-float long-float) `````` sds committed Aug 12, 2009 39 40 41 42 43 `````` collect (loop for i from -10000 to 10000 for x = (coerce i type) for r = (rational x) count (not (eql r i)))) `````` 44 45 46 47 `````` (0 0 0 0)) (deftest rational.3 (loop for type in '(short-float single-float double-float long-float) `````` sds committed Aug 12, 2009 48 49 50 51 52 53 54 55 56 `````` for bound in '(1.0s5 1.0f10 1.0d20 1.0l30) nconc (loop for x = (random-from-interval bound) for r = (rational x) for x2 = (float r x) repeat 1000 unless (and (rationalp r) (= x x2)) collect (list x r x2))) nil)``````