-
Notifications
You must be signed in to change notification settings - Fork 1
/
1_33.test.rkt
37 lines (29 loc) · 973 Bytes
/
1_33.test.rkt
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
#lang racket
(require rackunit/text-ui)
(require rackunit "../solutions/utils.rkt")
(require rackunit "../solutions/1_33.rkt")
(require rackunit "../solutions/1_28.rkt")
(define (sum-of-prime-squares a b)
(define (next a) (+ a 1))
(define (combine a b) (+ a b))
(filter-accumulate combine miller-robin-prime? 0 square a next b))
(define (smallest-common-diveder a b)
(if (= b 0)
a
(smallest-common-diveder b (remainder a b))))
(define (product-of-prim-to n)
(define (nod-to-n-is-one? a)
(= (smallest-common-diveder n a) 1))
(define (prod a b) (* a b))
(define (inc a) (+ a 1))
(filter-accumulate prod nod-to-n-is-one? 1 identity 1 inc n))
(define tests
(test-suite
"simple suite"
(test-case
"Sums-of-primes"
(check-equal? (sum-of-prime-squares 2 10) 87 "Simple addition"))
(test-case
"Product of prime to n"
(check-equal? (product-of-prim-to 10) 189 "Simple addition"))))
(run-tests tests 'verbose)