Commit bf2e44b8 authored by pfdietz's avatar pfdietz

Initial checkin of tests for GCD.

parent 17747d98
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Wed Sep 3 06:57:22 2003
;;;; Contains: Aux. functions for testing GCD
(in-package :cl-test)
(defun my-gcd (x y)
(cond
((< x 0)
(my-gcd (- x) y))
((< y 0)
(my-gcd x (- y)))
((<= x y)
(my-gcd* x y))
(t
(my-gcd* y x))))
(defun my-gcd* (x y)
;;; 0 <= x <= y
(loop
(when (zerop x) (return y))
(psetq x (mod y x)
y x)))
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Wed Sep 3 06:51:03 2003
;;;; Contains: Tests of GCD
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(compile-and-load "gcd-aux.lsp")
(deftest gcd.error.1
(loop for x in *mini-universe*
unless (or (integerp x)
(eq (eval `(classify-error (gcd ',x))) 'type-error))
collect x)
nil)
(deftest gcd.1
(gcd)
0)
(deftest gcd.2
(loop for i = (random-fixnum)
for a = (abs i)
repeat 10000
unless (and (eql a (gcd i))
(eql a (gcd 0 i)))
collect i)
nil)
(deftest gcd.3
(loop for i = (random-from-interval 10000000000000000)
for a = (abs i)
repeat 10000
unless (and (eql a (gcd i))
(eql a (gcd i 0)))
collect i)
nil)
(deftest gcd.4
(loop for i = (random-fixnum)
for j = (random-fixnum)
repeat 1000
unless (eql (my-gcd i j) (gcd i j))
collect (list i j))
nil)
(deftest gcd.5
(let ((bound (ash 1 200)))
(loop for i = (random-from-interval bound)
for j = (random-from-interval bound)
repeat 1000
unless (eql (my-gcd i j) (gcd i j))
collect (list i j)))
nil)
(deftest gcd.6
(loop for i = (random-fixnum)
for j = (random-fixnum)
for k = (random-fixnum)
repeat 1000
unless (eql (my-gcd i (my-gcd j k)) (gcd i j k))
collect (list i j k))
nil)
......@@ -32,6 +32,7 @@
(load "abs.lsp")
;;(load "exp.lsp")
(load "expt.lsp")
(load "gcd.lsp")
(load "rational.lsp")
(load "rationalize.lsp")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment