-
-
Save jah2488/7157424c8453c2027706 to your computer and use it in GitHub Desktop.
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 problem1.core) | |
(defn- real-numbers-below [x] (range 1 x)) | |
(defn- multiple-of [x num] (zero? (mod x num)) | |
(defn- multiple-of-three [x] (multiple-of x 3)) | |
(defn- multiple-of-five [x] (multiple-of x 5)) | |
(defn multiple-of-three-or-five [x] | |
(or (multiple-of-three x) | |
(multiple-of-five x))) | |
(defn multiples-of-three-and-five-below [x] | |
(filter multiple-of-three-or-five (real-numbers-below x))) | |
(defn sum-of-multiples [x] | |
(reduce + (multiples-of-three-and-five-below x))) |
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 problem1.core-test | |
(:require [clojure.test :refer :all] | |
[problem1.core :refer :all])) | |
(deftest multiples-of-n | |
(testing "3 should be a multiple of three" | |
(is (multiple-of-three 3))) | |
(testing "4 should not be a multiple of three" | |
(is (not (multiple-of-three 4)))) | |
(testing "5 should be a multiple of five" | |
(is (multiple-of-five 5))) | |
(testing "6 should not be a multiple of five" | |
(is (not (multiple-of-five 6)))) | |
(testing "below 10 the multiples should be 3 5 6 and 9" | |
(is (= (multiples-of-three-and-five-below 10), [3 5 6 9]))) | |
(testing "the sum of all multiples below 10 should be 23" | |
(is (= (sum-of-multiples 10), 23))) | |
; SPOILERS!!! | |
(testing "the sum of all multiples below 1000 should be something" | |
(is (= (sum-of-multiples 1000), 233168))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment