isqrt.lsp 1.37 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Sep  6 15:40:09 2003
;;;; Contains: Tests of ISQRT

6

7

8

9

10 11
;;; Error tests

12
(deftest isqrt.error.1
13 14
  (signals-error (isqrt) program-error)
  t)
15 16

(deftest isqrt.error.2
17 18
  (signals-error (isqrt 0 0) program-error)
  t)
19 20

(deftest isqrt.error.3
21 22
  (signals-error (isqrt 0 nil) program-error)
  t)
23 24

(deftest isqrt.error.4
25 26
  (signals-error (isqrt 0 0 0) program-error)
  t)
27 28 29

(deftest isqrt.error.5
  (loop for x in *mini-universe*
sds's avatar
sds committed
30 31 32
        unless (or (and (integerp x) (>= x 0))
                   (eval `(signals-type-error x ',x (isqrt x))))
        collect x)
33 34
  nil)

35 36
;;; Non-error tests

37 38
(deftest isqrt.1
  (loop for i from 0 to 10000
sds's avatar
sds committed
39 40 41 42
        for i2 = (* i i)
        for s = (isqrt i2)
        unless (eql s i)
        collect i)
43 44 45 46
  nil)

(deftest isqrt.2
  (loop for i = (random-from-interval most-positive-fixnum 0)
sds's avatar
sds committed
47 48 49 50 51 52 53
        for s = (isqrt i)
        repeat 1000
        unless (and (integerp s)
                    (>= s 0)
                    (<= (* s s) i)
                    (> (* (1+ s) (1+ s)) i))
        collect (list i s))
54 55 56 57
  nil)

(deftest isqrt.3
  (loop for i = (random-from-interval 1000000000000000 0)
sds's avatar
sds committed
58 59 60 61 62 63 64
        for s = (isqrt i)
        repeat 1000
        unless (and (integerp s)
                    (>= s 0)
                    (<= (* s s) i)
                    (> (* (1+ s) (1+ s)) i))
        collect (list i s))
65
  nil)