source: trunk/source/tests/ansi-tests/numerator-denominator.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: 2.4 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sun Sep  7 08:24:57 2003
4;;;; Contains: Tests of NUMERATOR, DENOMINATOR
5
6(in-package :cl-test)
7
8(compile-and-load "numbers-aux.lsp")
9
10(deftest numerator.error.1
11  (signals-error (numerator) program-error)
12  t)
13
14(deftest numerator.error.2
15  (signals-error (numerator 1/2 nil) program-error)
16  t)
17
18(deftest denominator.error.1
19  (signals-error (denominator) program-error)
20  t)
21
22(deftest denominator.error.2
23  (signals-error (denominator 1/2 nil) program-error)
24  t)
25
26(deftest numerator-denominator.1
27  (loop for n = (abs (random-fixnum))
28        for d = (1+ (abs (random-fixnum)))
29        for g = (gcd n d)
30        for n1 = (/ n g)
31        for d1 = (/ d g)
32        for r = (/ n d)
33        for n2 = (numerator r)
34        for d2 = (denominator r)
35        repeat 1000
36        unless (and (eql (gcd n1 d1) 1)
37                    (>= n1 0)
38                    (>= d1 1)
39                    (eql n1 n2)
40                    (eql d1 d2))
41        collect (list n1 d1 r n2 d2))
42  nil)
43
44(deftest numerator-denominator.2
45  (let ((bound (expt 10 20)))
46    (loop
47     for n = (random-from-interval bound 0)
48     for d = (random-from-interval bound 1)
49     for g = (gcd n d)
50     for n1 = (/ n g)
51     for d1 = (/ d g)
52     for r = (/ n d)
53     for n2 = (numerator r)
54     for d2 = (denominator r)
55     repeat 1000
56     unless (and (eql (gcd n1 d1) 1)
57                 (>= n1 0)
58                 (>= d1 1)
59                 (eql n1 n2)
60                 (eql d1 d2))
61     collect (list n1 d1 r n2 d2)))
62  nil)
63
64(deftest numerator-denominator.3
65  (loop for n = (abs (random-fixnum))
66        for d = (1+ (abs (random-fixnum)))
67        for g = (gcd n d)
68        for n1 = (/ n g)
69        for d1 = (/ d g)
70        for r = (/ n (- d))
71        for n2 = (numerator r)
72        for d2 = (denominator r)
73        repeat 1000
74        unless (and (eql (gcd n1 d1) 1)
75                    (>= n1 0)
76                    (>= d1 1)
77                    (eql n1 (- n2))
78                    (eql d1 d2))
79        collect (list n1 d1 r n2 d2))
80  nil)
81
82(deftest numerator-denominator.4
83  (let ((bound (expt 10 20)))
84    (loop
85     for n = (random-from-interval bound 0)
86     for d = (random-from-interval bound 1)
87     for g = (gcd n d)
88     for n1 = (/ n g)
89     for d1 = (/ d g)
90     for r = (/ n (- d))
91     for n2 = (numerator r)
92     for d2 = (denominator r)
93     repeat 1000
94     unless (and (eql (gcd n1 d1) 1)
95                 (>= n1 0)
96                 (>= d1 1)
97                 (eql n1 (- n2))
98                 (eql d1 d2))
99     collect (list n1 d1 r n2 d2)))
100  nil)
101       
102(deftest numerator-denominator.5
103  (loop for r in *rationals*
104        for n = (numerator r)
105        for d = (denominator r)
106        unless (and (integerp n)
107                    (integerp d)
108                    (eql (gcd n d) 1)
109                    (>= d 1)
110                    (eql (/ n d) r))
111        collect (list r n d))
112  nil)
Note: See TracBrowser for help on using the repository browser.