~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Sep  6 15:40:09 2003
;;;; Contains: Tests of ISQRT

(in-package :cl-test)

(compile-and-load "numbers-aux.lsp")

;;; Error tests

(deftest isqrt.error.1
  (signals-error (isqrt) program-error)
  t)

(deftest isqrt.error.2
  (signals-error (isqrt 0 0) program-error)
  t)

(deftest isqrt.error.3
  (signals-error (isqrt 0 nil) program-error)
  t)

(deftest isqrt.error.4
  (signals-error (isqrt 0 0 0) program-error)
  t)

(deftest isqrt.error.5
  (loop for x in *mini-universe*
	unless (or (and (integerp x) (>= x 0))
		   (eval `(signals-error (isqrt ',x) type-error)))
	collect x)
  nil)

;;; Non-error tests

(deftest isqrt.1
  (loop for i from 0 to 10000
	for i2 = (* i i)
	for s = (isqrt i2)
	unless (eql s i)
	collect i)
  nil)

(deftest isqrt.2
  (loop for i = (random-from-interval most-positive-fixnum 0)
	for s = (isqrt i)
	repeat 1000
	unless (and (integerp s)
		    (>= s 0)
		    (<= (* s s) i)
		    (> (* (1+ s) (1+ s)) i))
	collect (list i s))
  nil)

(deftest isqrt.3
  (loop for i = (random-from-interval 1000000000000000 0)
	for s = (isqrt i)
	repeat 1000
	unless (and (integerp s)
		    (>= s 0)
		    (<= (* s s) i)
		    (> (* (1+ s) (1+ s)) i))
	collect (list i s))
  nil)