source: trunk/source/tests/ansi-tests/rational.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 12 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

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