Created
August 12, 2021 23:00
-
-
Save mdwhatcott/4e13110f14f84dc0cb8b1c7820cbf1eb to your computer and use it in GitHub Desktop.
prime-factors.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns factors.core-spec | |
(:require [speclj.core :refer :all] | |
[factors.core :refer :all])) | |
(defn factors-of [n] | |
(loop [n n, d 2, fs []] | |
(cond (= n 1) fs | |
(zero? (mod n d)) (recur (/ n d) d (conj fs d)) | |
:else (recur n (inc d) fs)))) | |
(describe "Prime Factors Kata" | |
(it "computes prime factors" | |
(->> (factors-of 1) (should= [])) | |
(->> (factors-of 2) (should= [2])) | |
(->> (factors-of 3) (should= [3])) | |
(->> (factors-of 4) (should= [2 2])) | |
(->> (factors-of 5) (should= [5])) | |
(->> (factors-of 6) (should= [2 3])) | |
(->> (factors-of 7) (should= [7])) | |
(->> (factors-of 8) (should= [2 2 2])) | |
(->> (factors-of 9) (should= [3 3])) | |
(->> (factors-of 10) (should= [2 5])) | |
(->> (factors-of (* 2 3 5 7 11 13 17)) | |
(should= [2 3 5 7 11 13 17])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment