1 | ;-*- Mode: Lisp -*- |
---|
2 | ;;;; Author: Paul Dietz |
---|
3 | ;;;; Created: Thu Aug 21 14:21:07 2003 |
---|
4 | ;;;; Contains: Aux. functions for testing ROUND |
---|
5 | |
---|
6 | (in-package :cl-test) |
---|
7 | |
---|
8 | (defun round.1-fn () |
---|
9 | (loop for n = (- (random 2000000000) |
---|
10 | 1000000000) |
---|
11 | for d = (1+ (random 10000)) |
---|
12 | for vals = (multiple-value-list (round n d)) |
---|
13 | for (q r) = vals |
---|
14 | for n2 = (+ (* q d) r) |
---|
15 | repeat 1000 |
---|
16 | unless (and (eql (length vals) 2) |
---|
17 | (integerp q) |
---|
18 | (= n n2) |
---|
19 | (integerp r) |
---|
20 | (<= (- (/ d 2)) r (/ d 2))) |
---|
21 | unless (or (not (= (abs r) (/ d 2))) |
---|
22 | (evenp q)) |
---|
23 | collect (list n d q r n2))) |
---|
24 | |
---|
25 | (defun round.2-fn () |
---|
26 | (loop for num = (random 1000000000) |
---|
27 | for denom = (1+ (random 1000)) |
---|
28 | for n = (/ num denom) |
---|
29 | for d = (1+ (random 10000)) |
---|
30 | for vals = (multiple-value-list (round n d)) |
---|
31 | for (q r) = vals |
---|
32 | for n2 = (+ (* q d) r) |
---|
33 | repeat 1000 |
---|
34 | unless (and (eql (length vals) 2) |
---|
35 | (integerp q) |
---|
36 | (<= (- (/ d 2)) r (/ d 2)) |
---|
37 | (or (not (= (abs r) (/ d 2))) |
---|
38 | (evenp q)) |
---|
39 | (= n n2)) |
---|
40 | collect (list n d q r n2))) |
---|
41 | |
---|
42 | (defun round.3-fn (width) |
---|
43 | (loop for n = (- (random width) (/ width 2)) |
---|
44 | for vals = (multiple-value-list (round n)) |
---|
45 | for (q r) = vals |
---|
46 | for n2 = (+ q r) |
---|
47 | repeat 1000 |
---|
48 | unless (and (eql (length vals) 2) |
---|
49 | (integerp q) |
---|
50 | (= n n2) |
---|
51 | (<= -1/2 r 1/2) |
---|
52 | (or (not (= (abs r) 1/2)) |
---|
53 | (evenp q)) |
---|
54 | ) |
---|
55 | collect (list n q r n2))) |
---|
56 | |
---|
57 | (defun round.7-fn () |
---|
58 | (loop for numerator = (- (random 10000000000) 5000000000) |
---|
59 | for denominator = (1+ (random 100000)) |
---|
60 | for n = (/ numerator denominator) |
---|
61 | for vals = (multiple-value-list (round n)) |
---|
62 | for (q r) = vals |
---|
63 | for n2 = (+ q r) |
---|
64 | repeat 1000 |
---|
65 | unless (and (eql (length vals) 2) |
---|
66 | (integerp q) |
---|
67 | (rationalp r) |
---|
68 | (= n n2) |
---|
69 | (<= -1/2 r 1/2) |
---|
70 | (or (not (= (abs r) 1/2)) |
---|
71 | (evenp q)) |
---|
72 | ) |
---|
73 | collect (list n q r n2))) |
---|
74 | |
---|
75 | (defun round.8-fn () |
---|
76 | (loop for num1 = (- (random 10000000000) 5000000000) |
---|
77 | for den1 = (1+ (random 100000)) |
---|
78 | for n = (/ num1 den1) |
---|
79 | for num2 = (- (1+ (random 1000000))) |
---|
80 | for den2 = (1+ (random 1000000)) |
---|
81 | for d = (/ num2 den2) |
---|
82 | for vals = (multiple-value-list (round n d)) |
---|
83 | for (q r) = vals |
---|
84 | for n2 = (+ (* q d) r) |
---|
85 | repeat 1000 |
---|
86 | unless (and (eql (length vals) 2) |
---|
87 | (integerp q) |
---|
88 | (rationalp r) |
---|
89 | (<= (/ d 2) r (- (/ d 2))) |
---|
90 | (or (not (= (abs r) (- (/ d 2)))) |
---|
91 | (evenp q)) |
---|
92 | (= n n2)) |
---|
93 | collect (list n q d r n2))) |
---|
94 | |
---|
95 | (defun round.9-fn () |
---|
96 | (loop for num1 = (- (random 1000000000000000) 500000000000000) |
---|
97 | for den1 = (1+ (random 10000000000)) |
---|
98 | for n = (/ num1 den1) |
---|
99 | for num2 = (- (1+ (random 1000000000))) |
---|
100 | for den2 = (1+ (random 10000000)) |
---|
101 | for d = (/ num2 den2) |
---|
102 | for vals = (multiple-value-list (round n d)) |
---|
103 | for (q r) = vals |
---|
104 | for n2 = (+ (* q d) r) |
---|
105 | repeat 1000 |
---|
106 | unless (and (eql (length vals) 2) |
---|
107 | (integerp q) |
---|
108 | (rationalp r) |
---|
109 | (<= (/ d 2) r (- (/ d 2))) |
---|
110 | (or (not (= (abs r) (- (/ d 2)))) |
---|
111 | (evenp q)) |
---|
112 | (= n n2)) |
---|
113 | collect (list n q d r n2))) |
---|