Commit ee6d1507 by 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)