Created
January 6, 2014 14:40
-
-
Save adomokos/8283663 to your computer and use it in GitHub Desktop.
An example to create keyword-like arguments for a Clojure function
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 keyword-like-function-test | |
(:require [clojure.test :refer :all])) | |
(defn find-values | |
[& {:keys [p1 p2] :or {p1 [0 0] p2 [1 1]}}] | |
[p1 p2]) | |
(deftest keyword-arguments-test | |
(testing "when both of the arguments were passed" | |
(is (= [4 15] (first (find-values :p1 [4 15] :p2 [3 21])))) | |
(is (= [3 21] (last (find-values :p1 [4 15] :p2 [3 21]))))) | |
(testing "when only the first arugment was passed" | |
(is (= [4 15] (first (find-values :p1 [4 15])))) | |
(is (= [1 1] (last (find-values :p1 [4 15]))))) | |
(testing "when no argument was passed" | |
(is (= [0 0] (first (find-values)))) | |
(is (= [1 1] (last (find-values)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment