Last active
May 23, 2017 21:33
-
-
Save thieux/f5647532e1ddb8d3c4e5904f4cd79e18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 anonymous-letter.core-test | |
| (:require [clojure.test :refer :all] | |
| [anonymous-letter.core :refer :all])) | |
| (defn decrement-dict [word dictionary] | |
| (conj dictionary | |
| [word | |
| (dec (let [count (get dictionary word)] | |
| (if (nil? count) 0 count)))])) | |
| (defn can-write-letter [words-in-letter dictionary] | |
| (loop [words words-in-letter | |
| current-dictionary dictionary | |
| result true] | |
| (let [[first-word] words] | |
| (if (nil? first-word) | |
| result | |
| (let [is-in-dictionary (let [count (get dictionary first-word)] | |
| (if (nil? count) false (> count 0)))] | |
| (recur (rest words) | |
| (decrement-dict first-word current-dictionary) | |
| is-in-dictionary)))))) | |
| (deftest a-test | |
| (testing "single word in dictionary" | |
| (is (= (can-write-letter ["hello"] {"hello" 1}) true)))) | |
| (deftest b-test | |
| (testing "single word not in dictionary" | |
| (is (= (can-write-letter ["hello"] {"world" 1}) false)))) | |
| (deftest c-test | |
| (testing "one word in dictionary but the second is not" | |
| (is (= (can-write-letter ["hello" "world"] {"hello" 1}) false)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment