Commit ee6d1507 authored by pfdietz's avatar pfdietz

Reduced iteration count on randomized numeric tests to 1000. Added LCM tests.

parent 4738f34a
......@@ -12,7 +12,7 @@
for vals = (multiple-value-list (ceiling n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(= n n2)
......@@ -28,7 +28,7 @@
for vals = (multiple-value-list (ceiling n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(<= r 0)
......@@ -41,7 +41,7 @@
for vals = (multiple-value-list (ceiling n))
for (q r) = vals
for n2 = (+ q r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(= n n2)
......@@ -57,7 +57,7 @@
for vals = (multiple-value-list (ceiling n))
for (q r) = vals
for n2 = (+ q r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(rationalp r)
......@@ -77,7 +77,7 @@
for vals = (multiple-value-list (ceiling n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(rationalp r)
......@@ -96,7 +96,7 @@
for vals = (multiple-value-list (ceiling n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(rationalp r)
......
......@@ -45,7 +45,7 @@
(deftest /.3
(loop for i = (random-fixnum)
repeat 10000
repeat 1000
unless (or (zerop i)
(let ((q1 (/ i))
(q2 (/ 1 i)))
......@@ -63,7 +63,7 @@
for g = (gcd i j)
for q = (/ i j)
for q2 = (/ j)
repeat 10000
repeat 1000
unless (and (integerp g)
(zerop (mod i g))
(zerop (mod j g))
......@@ -80,7 +80,7 @@
(loop for i = (1+ (random bound))
for r1 = (/ i)
for r2 = (/ 1 i)
repeat 10000
repeat 1000
unless (eql r1 r2)
collect (list i r1 r2)))
nil)
......@@ -91,7 +91,7 @@
for i = (if (zerop i1) 1 i1)
for c = (complex 0 i)
for r = (/ c)
repeat 10000
repeat 1000
unless (eql r (complex 0 (- (/ i))))
collect (list i c r))
nil)
......@@ -132,7 +132,7 @@
(loop for a = (random-fixnum)
for b = (random-fixnum)
for m = (+ (* a a) (* b b))
repeat 10000
repeat 1000
unless
(or (zerop m)
(let* ((q (/ (complex a b)))
......@@ -148,7 +148,7 @@
(loop for a = (random-from-interval bound)
for b = (random-from-interval bound)
for m = (+ (* a a) (* b b))
repeat 10000
repeat 1000
unless
(or (zerop m)
(let* ((q (/ (complex a b)))
......@@ -164,7 +164,7 @@
for b = (random-fixnum)
for n = (complex (random-fixnum) (random-fixnum))
for m = (+ (* a a) (* b b))
repeat 10000
repeat 1000
unless
(or (zerop m)
(let* ((q (/ n (complex a b)))
......
......@@ -12,7 +12,7 @@
for vals = (multiple-value-list (floor n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(= n n2)
......@@ -28,7 +28,7 @@
for vals = (multiple-value-list (floor n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(<= 0 r)
......@@ -41,7 +41,7 @@
for vals = (multiple-value-list (floor n))
for (q r) = vals
for n2 = (+ q r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(= n n2)
......@@ -57,7 +57,7 @@
for vals = (multiple-value-list (floor n))
for (q r) = vals
for n2 = (+ q r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(rationalp r)
......@@ -77,7 +77,7 @@
for vals = (multiple-value-list (floor n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(rationalp r)
......@@ -96,7 +96,7 @@
for vals = (multiple-value-list (floor n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10000
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(rationalp r)
......
......@@ -23,4 +23,12 @@
(psetq x (mod y x)
y x)))
(defun my-lcm (x y)
(when (< x 0) (setf x (- x)))
(when (< y 0) (setf y (- y)))
(if (or (= x 0) (= y 0))
0
(/ (* x y) (my-gcd x y))))
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Thu Sep 4 22:03:21 2003
;;;; Contains: Tests of LCM
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(compile-and-load "gcd-aux.lsp")
(deftest lcm.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (lcm ',x))) 'type-error))
collect x)
nil)
(deftest lcm.1
(lcm)
1)
(deftest lcm.2
(loop for i = (random-fixnum)
for a = (abs i)
repeat 1000
unless (and (eql a (lcm i))
(eql a (lcm 1 i)))
collect i)
nil)
(deftest lcm.3
(loop for i = (random-from-interval 10000000000000000)
for a = (abs i)
repeat 1000
unless (and (eql a (lcm i))
(eql a (lcm i 1)))
collect i)
nil)
(deftest lcm.4
(loop for i = (random-fixnum)
for j = (random-fixnum)
repeat 1000
unless (eql (my-lcm i j) (lcm i j))
collect (list i j))
nil)
(deftest lcm.5
(let ((bound (ash 1 200)))
(loop for i = (random-from-interval bound)
for j = (random-from-interval bound)
repeat 1000
unless (eql (my-lcm i j) (lcm i j))
collect (list i j)))
nil)
(deftest lcm.6
(loop for i = (random-fixnum)
for j = (random-fixnum)
for k = (random-fixnum)
repeat 1000
unless (eql (my-lcm i (my-lcm j k)) (lcm i j k))
collect (list i j k))
nil)
(deftest lcm.7
(loop for i = (random-fixnum)
for j = (random-fixnum)
for k = (random-fixnum)
for n = (random-fixnum)
repeat 1000
unless (eql (my-lcm (my-lcm i j) (my-lcm k n)) (lcm i j k n))
collect (list i j k))
nil)
(deftest lcm.8
(loop for i from 1 to (min 256 (1- call-arguments-limit))
always (eql (apply #'lcm (make-list i :initial-element 1)) 1))
t)
(deftest lcm.order.1
(let ((i 0) x y)
(values
(lcm (progn (setf x (incf i)) 15)
(progn (setf y (incf i)) 25))
i x y))
75 2 1 2)
(deftest lcm.order.2
(let ((i 0) x y)
(values
(lcm (progn (setf x (incf i)) 0)
(progn (setf y (incf i)) 10))
i x y))
0 2 1 2)
(deftest lcm.order.3
(let ((i 0))
(values
(lcm (progn (incf i) 0))
i))
0 1)
......@@ -35,6 +35,7 @@
(load "gcd.lsp")
(load "incf.lsp")
(load "decf.lsp")
(load "lcm.lsp")
(load "rational.lsp")
(load "rationalize.lsp")
......
......@@ -71,7 +71,7 @@
(loop
for x = (+ (random (- upper-bound lower-bound)) lower-bound)
for neg = (- x)
repeat 10000
repeat 1000
unless (and (integerp neg)
(eql (abs x) (abs neg))
(if (> x 0) (< neg 0) (>= neg 0))
......@@ -101,7 +101,7 @@
(loop
for x = (random-fixnum)
for y = (random-fixnum)
repeat 10000
repeat 1000
unless (and (eql (+ x (- y)) (- x y))
(eql (+ 1 x (- y)) (- x (1- y)))
(eql (+ -1 x (- y)) (- x (1+ y))))
......@@ -150,7 +150,7 @@
for idiff2 = (- j i)
for diff1 = (- x y)
for diff2 = (- y x)
repeat 10000
repeat 1000
unless (or (zerop idiff1)
(and (eql idiff1 (- idiff2))
(eql diff1 (- diff2))
......@@ -169,7 +169,7 @@
for j = (random-fixnum)
for cj = (complex j (- j 200))
for diff = (- ci cj)
repeat 10000
repeat 1000
unless (eql diff (complex (- i j) (+ (- i j) 300)))
collect (list i ci j cj (- ci cj)))
nil)
......@@ -23,7 +23,7 @@
(loop for x = (random-fixnum)
for y = (1- x)
for z = (- x 1)
repeat 10000
repeat 1000
unless (eql y z)
collect (list x y z))
nil)
......@@ -41,7 +41,7 @@
(loop for x = (random (1- most-positive-short-float))
for y = (1- x)
for z = (- x 1.0s0)
repeat 10000
repeat 1000
unless (eql y z)
collect (list x y z))
nil)
......@@ -50,7 +50,7 @@
(loop for x = (random (1- most-positive-single-float))
for y = (1- x)
for z = (- x 1.0f0)
repeat 10000
repeat 1000
unless (eql y z)
collect (list x y z))
nil)
......@@ -59,7 +59,7 @@
(loop for x = (random (1- most-positive-double-float))
for y = (1- x)
for z = (- x 1.0d0)
repeat 10000
repeat 1000
unless (eql y z)
collect (list x y z))
nil)
......@@ -68,7 +68,7 @@
(loop for x = (random (1- most-positive-long-float))
for y = (1- x)
for z = (- x 1.0l0)
repeat 10000
repeat 1000
unless (eql y z)
collect (list x y z))
nil)
......@@ -80,7 +80,7 @@
for r = (/ x y2)
for r1 = (1- r)
for r2 = (- r 1)
repeat 10000
repeat 1000
unless (eql r1 r2)
collect (list x y2 r1 r2))
nil)
......@@ -93,7 +93,7 @@
for r = (/ x y2)
for r1 = (1- r)
for r2 = (- r 1)
repeat 10000
repeat 1000
unless (eql r1 r2)
collect (list x y2 r1 r2)))
nil)
......@@ -104,7 +104,7 @@
for xi = (random-fixnum)
for xc = (complex xr xi)
for xc1 = (1- xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (- xr 1) xi))
collect (list xr xi xc xc1))
nil)
......@@ -116,7 +116,7 @@
for xi = (random-from-interval bound)
for xc = (complex xr xi)
for xc1 = (1- xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (- xr 1) xi))
collect (list xr xi xc xc1)))
nil)
......@@ -127,7 +127,7 @@
for xi = (random bound)
for xc = (complex xr xi)
for xc1 = (1- xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (- xr 1) xi))
collect (list xr xi xc xc1)))
nil)
......@@ -138,7 +138,7 @@
for xi = (random bound)
for xc = (complex xr xi)
for xc1 = (1- xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (- xr 1) xi))
collect (list xr xi xc xc1)))
nil)
......@@ -149,7 +149,7 @@
for xi = (random bound)
for xc = (complex xr xi)
for xc1 = (1- xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (- xr 1) xi))
collect (list xr xi xc xc1)))
nil)
......@@ -160,7 +160,7 @@
for xi = (random bound)
for xc = (complex xr xi)
for xc1 = (1- xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (- xr 1) xi))
collect (list xr xi xc xc1)))
nil)
......@@ -23,7 +23,7 @@
(loop for x = (random-fixnum)
for y = (1+ x)
for z = (+ x 1)
repeat 10000
repeat 1000
unless (eql y z)
collect (list x y z))
nil)
......@@ -41,7 +41,7 @@
(loop for x = (random (1- most-positive-short-float))
for y = (1+ x)
for z = (+ x 1.0s0)
repeat 10000
repeat 1000
unless (eql y z)
collect (list x y z))
nil)
......@@ -50,7 +50,7 @@
(loop for x = (random (1- most-positive-single-float))
for y = (1+ x)
for z = (+ x 1.0f0)
repeat 10000
repeat 1000
unless (eql y z)
collect (list x y z))
nil)
......@@ -59,7 +59,7 @@
(loop for x = (random (1- most-positive-double-float))
for y = (1+ x)
for z = (+ x 1.0d0)
repeat 10000
repeat 1000
unless (eql y z)
collect (list x y z))
nil)
......@@ -68,7 +68,7 @@
(loop for x = (random (1- most-positive-long-float))
for y = (1+ x)
for z = (+ x 1.0l0)
repeat 10000
repeat 1000
unless (eql y z)
collect (list x y z))
nil)
......@@ -80,7 +80,7 @@
for r = (/ x y2)
for r1 = (1+ r)
for r2 = (+ r 1)
repeat 10000
repeat 1000
unless (eql r1 r2)
collect (list x y2 r1 r2))
nil)
......@@ -93,7 +93,7 @@
for r = (/ x y2)
for r1 = (1+ r)
for r2 = (+ r 1)
repeat 10000
repeat 1000
unless (eql r1 r2)
collect (list x y2 r1 r2)))
nil)
......@@ -104,7 +104,7 @@
for xi = (random-fixnum)
for xc = (complex xr xi)
for xc1 = (1+ xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (+ xr 1) xi))
collect (list xr xi xc xc1))
nil)
......@@ -116,7 +116,7 @@
for xi = (random-from-interval bound)
for xc = (complex xr xi)
for xc1 = (1+ xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (+ xr 1) xi))
collect (list xr xi xc xc1)))
nil)
......@@ -127,7 +127,7 @@
for xi = (random bound)
for xc = (complex xr xi)
for xc1 = (1+ xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (+ xr 1) xi))
collect (list xr xi xc xc1)))
nil)
......@@ -138,7 +138,7 @@
for xi = (random bound)
for xc = (complex xr xi)
for xc1 = (1+ xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (+ xr 1) xi))
collect (list xr xi xc xc1)))
nil)
......@@ -149,7 +149,7 @@
for xi = (random bound)
for xc = (complex xr xi)
for xc1 = (1+ xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (+ xr 1) xi))
collect (list xr xi xc xc1)))
nil)
......@@ -160,7 +160,7 @@
for xi = (random bound)
for xc = (complex xr xi)
for xc1 = (1+ xc)
repeat 10000
repeat 1000
unless (eql xc1 (complex (+ xr 1) xi))
collect (list xr xi xc xc1)))
nil)
......@@ -47,7 +47,7 @@
for s4 = (+ x z y)
for s5 = (+ z x y)
for s6 = (+ y z x)
repeat 10000
repeat 1000
unless (and (eql s1 s2) (eql s1 s3) (eql s1 s4)
(eql s1 s5) (eql s1 s6))
collect (list x y z s1 s2 s3 s4 s5 s6))))
......@@ -67,7 +67,7 @@
for s4 = (+ x z y)
for s5 = (+ z x y)
for s6 = (+ y z x)
repeat 10000
repeat 1000
unless (and (eql s1 s2) (eql s1 s3) (eql s1 s4)
(eql s1 s5) (eql s1 s6))
collect (list x y z s1 s2 s3 s4 s5 s6))))
......@@ -87,7 +87,7 @@
for s4 = (+ x z y)
for s5 = (+ z x y)
for s6 = (+ y z x)
repeat 10000
repeat 1000
unless (and (eql s1 s2) (eql s1 s3) (eql s1 s4)
(eql s1 s5) (eql s1 s6))
collect (list x y z s1 s2 s3 s4 s5 s6)
......@@ -149,7 +149,7 @@
(loop for x = (%r)
for y = (%r)
for s = (+ x y)
repeat 10000
repeat 1000
unless (and (eql s (+ y x))
(typep s 'short-float))
collect (list x y s)))
......@@ -160,7 +160,7 @@
(loop for x = (%r)
for y = (%r)
for s = (+ x y)
repeat 10000
repeat 1000
unless (and (eql s (+ y x))
(typep s 'single-float))
collect (list x y s)))
......@@ -171,7 +171,7 @@
(loop for x = (%r)
for y = (%r)
for s = (+ x y)
repeat 10000
repeat 1000
unless (and (eql s (+ y x))
(typep s 'double-float))
collect (list x y s)))
......@@ -182,7 +182,7 @@
(loop for x = (%r)
for y = (%r)
for s = (+ x y)
repeat 10000
repeat 1000
unless (and (eql s (+ y x))
(typep s 'long-float))
collect (list x y s)))
......@@ -194,7 +194,7 @@
(loop for x = (- (random bound) (/ bound 2))
for y = (- (random bound2)(/ bound2 2))
for p = (+ x y)
repeat 10000
repeat 1000
unless (and (eql p (+ y x))
(typep p 'single-float))
collect (list x y p)))
......@@ -206,7 +206,7 @@
(loop for x = (- (random bound) (/ bound 2))
for y = (- (random bound2)(/ bound2 2))
for p = (+ x y)
repeat 10000
repeat 1000
unless (and (eql p (+ y x))
(typep p 'double-float))
collect (list x y p)))
......@@ -218,7 +218,7 @@
(loop for x = (- (random bound) (/ bound 2))
for y = (- (random bound2)(/ bound2 2))
for p = (+ x y)
repeat 10000
repeat 1000
unless (and (eql p (+ y x))
(typep p 'long-float))
collect (list x y p)))
......@@ -230,7 +230,7 @@
(loop for x = (- (random bound) (/ bound 2))
for y = (- (random bound2)(/ bound2 2))
for p = (+ x y)
repeat 10000
repeat 1000
unless (and (eql p (+ y x))
(typep p 'double-float))
collect (list x y p)))
......@@ -242,7 +242,7 @@
(loop for x = (- (random bound) (/ bound 2))
for y = (- (random bound2)(/ bound2 2))
for p = (+ x y)
repeat 10000
repeat 1000
unless (and (eql p (+ y x))
(typep p 'long-float))
collect (list x y p)))
......@@ -254,7 +254,7 @@
(loop for x = (- (random bound) (/ bound 2))
for y = (- (random bound2)(/ bound2 2))
for p = (+ x y)
repeat 10000
repeat 1000
unless (and (eql p (+ y x))
(typep p 'long-float))
collect (list x y p)))
......@@ -271,7 +271,7 @@
for j = (random bound)
for y = (coerce j type)
for sum = (+ x y)
repeat 10000
repeat 1000
unless (and (eql sum (coerce (+ i j) type))
(eql sum (+ y x)))
collect (list i j x y sum (coerce (+ i j) type))))
......@@ -290,7 +290,7 @@
for j = (random bound)
for y = (complex (coerce j type) one)
for sum = (+ x y)
repeat 10000
repeat 1000
unless (and (eql sum (complex (coerce (+ i j) type)
(coerce 2 type)))
(eql sum (+ y x)))
......@@ -310,7 +310,7 @@
for j = (random bound)
for y = (complex one (coerce j type))
for sum = (+ x y)
repeat 10000
repeat 1000
unless (and (eql sum (complex (coerce 2 type)
(coerce (+ i j) type)))
(eql sum (+ y x)))
......
......@@ -12,7 +12,7 @@
for vals = (multiple-value-list (round n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(= n n2)
......@@ -30,7 +30,7 @@
for vals = (multiple-value-list (round n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(<= (- (/ d 2)) r (/ d 2))
......@@ -44,7 +44,7 @@
for vals = (multiple-value-list (round n))
for (q r) = vals
for n2 = (+ q r)
repeat 10
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(= n n2)
......@@ -61,7 +61,7 @@
for vals = (multiple-value-list (round n))
for (q r) = vals
for n2 = (+ q r)
repeat 10
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(rationalp r)
......@@ -82,7 +82,7 @@
for vals = (multiple-value-list (round n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(rationalp r)
......@@ -102,7 +102,7 @@
for vals = (multiple-value-list (round n d))
for (q r) = vals
for n2 = (+ (* q d) r)
repeat 10
repeat 1000
unless (and (eql (length vals) 2)
(integerp q)
(rationalp r)
......
......@@ -102,7 +102,7 @@
for yc = (%r)
for y = (complex yr yc)
for prod = (* x y)
repeat 10000
repeat 1000
unless (and (eql (realpart prod) (- (integer-times xr yr)
(integer-times xc yc)))
(eql (imagpart prod) (+ (integer-times xr yc)
......@@ -122,7 +122,7 @@
for yc = (%r)
for y = (complex yr yc)
for prod = (* x y)
repeat 10000
repeat 1000
unless (and (eql (realpart prod) (- (rat-times xr yr)
(rat-times xc yc)))
(eql (imagpart prod) (+ (rat-times xr yc)
......@@ -183,7 +183,7 @@
(loop for x = (random-from-interval bound)
for y = (random-from-interval bound)
for p = (* x y)
repeat 10000
repeat 1000
unless (and (eql p (* y x))
(typep p 'short-float))
collect (list x y p)))
......@@ -194,7 +194,7 @@
(loop for x = (random-from-interval bound)
for y = (random-from-interval bound)
for p = (* x y)
repeat 10000
repeat 1000
unless (and (eql p (* y x))
(typep p 'single-float))
collect (list x y p)))
......@@ -205,7 +205,7 @@
(loop for x = (random-from-interval bound)
for y = (random-from-interval bound)
for p = (* x y)
repeat 10000
repeat 1000
unless (and (eql p (* y x))
(typep p 'double-float))
collect (list x y p)))
......@@ -216,7 +216,7 @@
(loop for x = (random-from-interval bound)
for y = (random-from-interval bound)
for p = (* x y)
repeat 10000
repeat 1000
unless (and (eql p (* y x))
(typep p 'long-float))
collect (list x y p)))
......@@ -228,7 +228,7 @@
(loop for x = (random-from-interval bound)
for y = (random-from-interval bound2)
for p = (* x y)
repeat 10000
repeat 1000
unless (and (eql p (* y x))
(typep p 'single-float))
collect (list x y p)))
......@@ -240,7 +240,7 @@
(loop for x = (random-from-interval bound)
for y = (random-from-interval bound2)
for p = (* x y)
repeat 10000
repeat 1000
unless (and (eql p (* y x))
(typep p 'double-float))
collect (list x y p)))
......@@ -252,7 +252,7 @@
(loop for x = (random-from-interval bound)
for y = (random-from-interval bound2)
for p = (* x y)
repeat 10000
repeat 1000
unless (and (eql p (* y x))
(typep p 'long-float))
collect (list x y p)))
......@@ -264,7 +264,7 @@
(loop for x = (random-from-interval bound)
for y = (random-from-interval bound2)
for p = (* x y)
repeat 10000
repeat 1000
unless (and (eql p (* y x))