Last active
December 29, 2016 21:27
-
-
Save thieux/0dc909c9c6dacbd2c4d046cf4090ad1d 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 clojure-brave-true-exercises.crashcourse-test | |
(:require [clojure.test :refer :all])) | |
(deftest map-empty | |
(testing "empty" | |
(is (= #{} (mapset inc []))))) | |
(defn mapset [f list] #{}) | |
(deftest map-singleton | |
(testing "singleton" | |
(is (= #{2} (mapset inc [1]))))) | |
(defn mapset [f list] | |
(if (= list []) | |
#{} | |
#{2})) | |
(defn mapset [f list] | |
(if (= list []) | |
#{} | |
#{(inc 1)})) | |
(defn mapset [f list] | |
(if (= list []) | |
#{} | |
#{(inc (first list))})) | |
(defn mapset [f list] | |
(if (= list []) | |
#{} | |
#{(f (first list))})) | |
(defn mapset [f list] | |
(if (= list []) | |
#{} | |
(let [[head & tail] list] | |
(into #{(inc head)} #{})))) | |
(deftest map-dual | |
(testing "dual" | |
(is (= #{2 3} (mapset inc [1 2]))))) | |
(defn mapset [f list] | |
(if (= list []) | |
#{} | |
(let [[head & tail] list] | |
(into #{(inc head)} (mapset f (into [] tail)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment