evenp.lsp 1.66 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Aug 31 10:39:01 2003
;;;; Contains: Tests of EVENP

6

pfdietz's avatar
pfdietz committed
7

8

9

pfdietz's avatar
pfdietz committed
10
(deftest evenp.error.1
11 12
  (signals-error (evenp) program-error)
  t)
pfdietz's avatar
pfdietz committed
13 14

(deftest evenp.error.2
15 16
  (signals-error (evenp 0 nil) program-error)
  t)
pfdietz's avatar
pfdietz committed
17

18 19 20 21
(deftest evenp.error.3
  (check-type-error #'evenp #'integerp)
  nil)

pfdietz's avatar
pfdietz committed
22 23
(deftest evenp.1
  (loop for x in *numbers*
sds's avatar
sds committed
24 25
        when (integerp x)
        do (evenp x))
pfdietz's avatar
pfdietz committed
26 27 28
  nil)

(deftest evenp.3
sds's avatar
sds committed
29 30 31 32 33 34 35 36 37 38 39 40 41
  (loop for x = (random-fixnum)
        repeat 10000
        when (or
              (not (evenp (+ x x)))
              (evenp (+ x x 1))
              (if (evenp x)
                  (or (evenp (1+ x))
                      (evenp (1- x))
                      (/= (mod x 2) 0))
                (or (not (evenp (1+ x)))
                    (not (evenp (1- x)))
                    (= (mod x 2) 0))))
        collect x)
pfdietz's avatar
pfdietz committed
42 43 44 45
  nil)

(deftest evenp.4
  (let ((upper-bound 1000000000000000)
sds's avatar
sds committed
46
        (lower-bound -1000000000000000))
47
    (loop for x = (random-from-interval upper-bound lower-bound)
sds's avatar
sds committed
48 49 50 51 52 53 54 55 56 57 58 59
          repeat 10000
          when (or
                (not (evenp (+ x x)))
                (evenp (+ x x 1))
                (if (evenp x)
                    (or (evenp (1+ x))
                        (evenp (1- x))
                        (/= (mod x 2) 0))
                  (or (not (evenp (1+ x)))
                      (not (evenp (1- x)))
                      (= (mod x 2) 0))))
          collect x))
pfdietz's avatar
pfdietz committed
60 61
  nil)

pfdietz's avatar
pfdietz committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
(deftest evenp.5
  (notnot-mv (evenp 0))
  t)

(deftest evenp.6
  (evenp 1)
  nil)

(deftest evenp.7
  (notnot-mv (evenp 100000000000000000000000000000000))
  t)

(deftest evenp.8
  (evenp 100000000000000000000000000000001)
  nil)