Last active
July 29, 2019 17:42
-
-
Save trikitrok/6f25524b46d5693d73580031a0f0d542 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 fizzbuzz-pbt.core-test | |
(:require | |
[midje.sweet :refer :all] | |
[clojure.set :as set] | |
[clojure.test.check.generators :as gen] | |
[midje.experimental :refer [for-all]] | |
[fizzbuzz-pbt.core :as sut])) | |
(defn- multiples-of [n] | |
(iterate #(+ % n) n)) | |
(defn- fizzbuzz-for [n] | |
(nth (sut/fizzbuzz) (dec n))) | |
(def multiples-of-3 (set (take-while #(< % 101) (multiples-of 3)))) | |
(def multiples-of-5 (set (take-while #(< % 101) (multiples-of 5)))) | |
(facts | |
"about fizzbuzz" | |
(fact | |
"multiples of 3 but not 5 are Fizz" | |
(for-all | |
[n (gen/elements | |
(set/difference | |
multiples-of-3 | |
multiples-of-5))] | |
{:num-tests 100} | |
(fizzbuzz-for n) => "Fizz")) | |
(fact | |
"multiples of 5 but not 3 are Buzz" | |
(for-all | |
[n (gen/elements | |
(set/difference | |
multiples-of-5 | |
multiples-of-3))] | |
{:num-tests 100} | |
(fizzbuzz-for n) => "Buzz")) | |
(fact | |
"multiples of 3 and 5 are FizzBuzz" | |
(for-all | |
[n (gen/elements | |
(set/intersection | |
multiples-of-5 | |
multiples-of-3))] | |
{:num-tests 100} | |
(fizzbuzz-for n) => "FizzBuzz")) | |
(fact | |
"the rest of numbers are casted to string" | |
(for-all | |
[n (gen/elements | |
(set/difference | |
(set (range 1 101)) | |
multiples-of-3 | |
multiples-of-5))] | |
{:num-tests 100} | |
(fizzbuzz-for n) => (str n)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment