1
exercism fetch common-lisp prime-factors

prime-factors-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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(ql:quickload "lisp-unit")
#-xlisp-test (load "prime-factors")

(defpackage #:prime-factors-test
  (:use #:common-lisp #:lisp-unit))

(in-package #:prime-factors-test)

(define-test one
  (assert-equal '() (prime-factors:factors-of 1)))

(define-test two
  (assert-equal '(2) (prime-factors:factors-of 2)))

(define-test three
  (assert-equal '(3) (prime-factors:factors-of 3)))

(define-test four
  (assert-equal '(2 2) (prime-factors:factors-of 4)))

(define-test six
  (assert-equal '(2 3) (sort (prime-factors:factors-of 6) #'<)))

(define-test eight
  (assert-equal '(2 2 2) (prime-factors:factors-of 8)))

(define-test nine
  (assert-equal '(3 3) (prime-factors:factors-of 9)))

(define-test twenty-seven
  (assert-equal '(3 3 3) (prime-factors:factors-of 27)))

(define-test six-hundred-twenty-five
  (assert-equal '(5 5 5 5) (prime-factors:factors-of 625)))

(define-test a-large-number
  (assert-equal '(5 17 23 461)
                (sort (prime-factors:factors-of 901255) #'<)))

(define-test a-huge-number
  (assert-equal '(11 9539 894119)
                (sort (prime-factors:factors-of 93819012551) #'<)))

(define-test triple-squares-number
  (assert-equal '(2 2 5 5 7 7)
                (sort (prime-factors:factors-of 4900) #'<)))

(define-test mersenne-composite-1
  (assert-equal '(23 89)
                (sort (prime-factors:factors-of 2047) #'<)))

(define-test fermat-composite-1
  (assert-equal '(641 6700417)
                (sort (prime-factors:factors-of 4294967297) #'<)))

(define-test weak-probable-prime
  (assert-equal '(11 31)
                (sort (prime-factors:factors-of 341) #'<)))

(define-test strong-probable-prime
  (assert-equal '(7 31 73)
                (sort (prime-factors:factors-of 15841) #'<)))

(define-test carmichael-small-1
  (assert-equal '(3 11 17)
                (sort (prime-factors:factors-of 561) #'<)))

(define-test carmichael-small-2
  (assert-equal '(11 13 17 31)
                (sort (prime-factors:factors-of 75361) #'<)))

(define-test pseudoprime-smallish
  (assert-equal '(1303 16927 157543)
                (sort (prime-factors:factors-of 3474749660383) #'<)))

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