oddp.lsp 1.72 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Aug 31 10:48:25 2003
;;;; Contains: Tests of ODDP

(in-package :cl-test)

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

10 11
;;; Error tests

pfdietz's avatar
pfdietz committed
12
(deftest oddp.error.1
13 14
  (signals-error (oddp) program-error)
  t)
pfdietz's avatar
pfdietz committed
15 16

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

(deftest oddp.error.3
pfdietz's avatar
pfdietz committed
21
  (check-type-error #'oddp #'integerp)
22 23 24
  nil)

;;; Non-error tests
pfdietz's avatar
pfdietz committed
25 26 27

(deftest oddp.1
  (loop for x in *numbers*
sds's avatar
sds committed
28 29
        when (integerp x)
        do (oddp x))
pfdietz's avatar
pfdietz committed
30 31 32
  nil)

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

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

pfdietz's avatar
pfdietz committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
(deftest oddp.5
  (notnot-mv (oddp 1))
  t)

(deftest oddp.6
  (oddp 0)
  nil)

(deftest oddp.7
  (notnot-mv (oddp 100000000000000000000000000000001))
  t)

(deftest oddp.8
  (oddp 100000000000000000000000000000000)
  nil)

sds's avatar
sds committed
82