~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to ansi-tests/rational.lsp

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  (loop for x in *mini-universe*
 
22
        unless (or (realp x)
 
23
                   (eval `(signals-error (rational ',x) type-error)))
 
24
        collect x)
 
25
  nil)
 
26
 
 
27
(deftest rational.1
 
28
  (loop for x in (loop for r in *reals*
 
29
                       when (or (not (floatp r))
 
30
                                (<= -1000 (nth-value 1 (integer-decode-float r)) 1000))
 
31
                       collect r)
 
32
        for r = (rational x)
 
33
        unless (and (rationalp r)
 
34
                    (if (floatp x)
 
35
                        (= (float r x) x)
 
36
                      (eql x r)))
 
37
        collect (list x r))
 
38
  nil)
 
39
 
 
40
(deftest rational.2
 
41
  (loop for type in '(short-float single-float double-float long-float)
 
42
        collect
 
43
        (loop for i from -10000 to 10000
 
44
              for x = (coerce i type)
 
45
              for r = (rational x)
 
46
              count (not (eql r i))))
 
47
  (0 0 0 0))
 
48
 
 
49
(deftest rational.3
 
50
  (loop for type in '(short-float single-float double-float long-float)
 
51
        for bound in '(1.0s5 1.0f10 1.0d20 1.0l30)
 
52
        nconc
 
53
        (loop for x = (random-from-interval bound)
 
54
              for r = (rational x)
 
55
              for x2 = (float r x)
 
56
              repeat 1000
 
57
              unless (and (rationalp r) (= x x2))
 
58
              collect (list x r x2)))
 
59
  nil)
 
 
b'\\ No newline at end of file'