source: trunk/source/tests/ansi-tests/gcd.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.0 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Wed Sep  3 06:51:03 2003
4;;;; Contains: Tests of GCD
5
6(in-package :cl-test)
7
8(compile-and-load "numbers-aux.lsp")
9(compile-and-load "gcd-aux.lsp")
10
11;;; Error tests
12
13(deftest gcd.error.1
14  (check-type-error #'gcd #'integerp)
15  nil)
16
17;;; Non-error tests
18
19(deftest gcd.1
20  (gcd)
21  0)
22
23(deftest gcd.2
24  (loop for i = (random-fixnum)
25        for a = (abs i)
26        repeat 10000
27        unless (and (eql a (gcd i))
28                    (eql a (gcd 0 i)))
29        collect i)
30  nil)
31
32(deftest gcd.3
33  (loop for i = (random-from-interval 10000000000000000)
34        for a = (abs i)
35        repeat 10000
36        unless (and (eql a (gcd i))
37                    (eql a (gcd i 0)))
38        collect i)
39  nil)
40
41(deftest gcd.4
42  (loop for i = (random-fixnum)
43        for j = (random-fixnum)
44        repeat 1000
45        unless (eql (my-gcd i j) (gcd i j))
46        collect (list i j))
47  nil)
48
49(deftest gcd.5
50  (let ((bound (ash 1 200)))
51    (loop for i = (random-from-interval bound)
52          for j = (random-from-interval bound)
53          repeat 1000
54          unless (eql (my-gcd i j) (gcd i j))
55          collect (list i j)))
56  nil)
57
58(deftest gcd.6
59  (loop for i = (random-fixnum)
60        for j = (random-fixnum)
61        for k = (random-fixnum)
62        repeat 1000
63        unless (eql (my-gcd i (my-gcd j k)) (gcd i j k))
64        collect (list i j k))
65  nil)
66
67(deftest gcd.7
68  (loop for i = (random-fixnum)
69        for j = (random-fixnum)
70        for k = (random-fixnum)
71        for n = (random-fixnum)
72        repeat 1000
73        unless (eql (my-gcd (my-gcd i j) (my-gcd k n)) (gcd i j k n))
74        collect (list i j k))
75  nil)
76
77(deftest gcd.8
78  (loop for i from 1 to (min 256 (1- call-arguments-limit))
79        always (eql (apply #'gcd (make-list i :initial-element 1)) 1))
80  t)
81
82(deftest gcd.order.1
83  (let ((i 0) x y)
84    (values
85     (gcd (progn (setf x (incf i)) 15)
86          (progn (setf y (incf i)) 25))
87     i x y))
88  5 2 1 2)
89
90(deftest gcd.order.2
91  (let ((i 0) x y)
92    (values
93     (gcd (progn (setf x (incf i)) 0)
94          (progn (setf y (incf i)) 10))
95     i x y))
96  10 2 1 2)
97
98(deftest gcd.order.3
99  (let ((i 0))
100    (values
101     (gcd (progn (incf i) 0))
102     i))
103  0 1)
104
105   
Note: See TracBrowser for help on using the repository browser.