lcm.lsp 2.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
;-*- 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
12
  (check-type-error #'lcm #'integerp)
13 14 15 16 17 18 19 20
  nil)

(deftest lcm.1
  (lcm)
  1)

(deftest lcm.2
  (loop for i = (random-fixnum)
sds's avatar
sds committed
21 22 23 24 25
        for a = (abs i)
        repeat 1000
        unless (and (eql a (lcm i))
                    (eql a (lcm 1 i)))
        collect i)
26 27 28 29
  nil)

(deftest lcm.3
  (loop for i = (random-from-interval 10000000000000000)
sds's avatar
sds committed
30 31 32 33 34
        for a = (abs i)
        repeat 1000
        unless (and (eql a (lcm i))
                    (eql a (lcm i 1)))
        collect i)
35 36 37 38
  nil)

(deftest lcm.4
  (loop for i = (random-fixnum)
sds's avatar
sds committed
39 40 41 42
        for j = (random-fixnum)
        repeat 1000
        unless (eql (my-lcm i j) (lcm i j))
        collect (list i j))
43 44 45 46 47
  nil)

(deftest lcm.5
  (let ((bound (ash 1 200)))
    (loop for i = (random-from-interval bound)
sds's avatar
sds committed
48 49 50 51
          for j = (random-from-interval bound)
          repeat 1000
          unless (eql (my-lcm i j) (lcm i j))
          collect (list i j)))
52 53 54 55
  nil)

(deftest lcm.6
  (loop for i = (random-fixnum)
sds's avatar
sds committed
56 57 58 59 60
        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))
61 62 63 64
  nil)

(deftest lcm.7
  (loop for i = (random-fixnum)
sds's avatar
sds committed
65 66 67 68 69 70
        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 n))
71 72 73 74
  nil)

(deftest lcm.8
  (loop for i from 1 to (min 256 (1- call-arguments-limit))
sds's avatar
sds committed
75
        always (eql (apply #'lcm (make-list i :initial-element 1)) 1))
76 77
  t)

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
(deftest lcm.9
  (lcm 0 0)
  0)

(deftest lcm.10
  (lcm 1 0 0)
  0)

(deftest lcm.11
  (lcm 0 1 0)
  0)

(deftest lcm.12
  (lcm 0 0 1)
  0)


95 96 97 98
(deftest lcm.order.1
  (let ((i 0) x y)
    (values
     (lcm (progn (setf x (incf i)) 15)
sds's avatar
sds committed
99
          (progn (setf y (incf i)) 25))
100 101 102 103 104 105 106
     i x y))
  75 2 1 2)

(deftest lcm.order.2
  (let ((i 0) x y)
    (values
     (lcm (progn (setf x (incf i)) 0)
sds's avatar
sds committed
107
          (progn (setf y (incf i)) 10))
108 109 110 111 112 113 114 115 116
     i x y))
  0 2 1 2)

(deftest lcm.order.3
  (let ((i 0))
    (values
     (lcm (progn (incf i) 0))
     i))
  0 1)
117 118