1
exercism fetch common-lisp perfect-numbers

perfect-numbers-test.lisp

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
(ql:quickload "lisp-unit")
#-xlisp-test (load "perfect-numbers")

(defpackage #:perfect-numbers-test
  (:use #:common-lisp #:lisp-unit))

(in-package #:perfect-numbers-test)


;; Perfect numbers tests:
(define-test smallest-perfect-number
  (assert-equal "perfect" (perfect-numbers:classify 6)))

(define-test medium-perfect-number
  (assert-equal "perfect" (perfect-numbers:classify 28)))

(define-test large-perfect-number
  (assert-equal "perfect" (perfect-numbers:classify 33550336)))


;; Abundant numbers tests:
(define-test smallest-abundant-number
  (assert-equal "abundant" (perfect-numbers:classify 12)))

(define-test medium-abundant-number
  (assert-equal "abundant" (perfect-numbers:classify 30)))

(define-test large-abundant-number
  (assert-equal "abundant" (perfect-numbers:classify 33550335)))


;; Deficient numbers tests:
(define-test smallest-prime-deficient-number
  (assert-equal "deficient" (perfect-numbers:classify 2)))

(define-test smallest-non-prime-deficient-number
  (assert-equal "deficient" (perfect-numbers:classify 1)))

(define-test medium-deficient-number
  (assert-equal "deficient" (perfect-numbers:classify 32)))

(define-test large-deficient-number
  (assert-equal "deficient" (perfect-numbers:classify 33550337)))


;; Undefined values of classify tests:
(define-test undefinded-0
  (assert-equal NIL (perfect-numbers:classify 0)))

(define-test undefined-negative
  (assert-equal NIL (perfect-numbers:classify -3)))

#-xlisp-test
(let ((*print-errors* t)
      (*print-failures* t))
  (run-tests :all))