Skip to content

Instantly share code, notes, and snippets.

@adomokos
Created January 6, 2014 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adomokos/8283663 to your computer and use it in GitHub Desktop.
Save adomokos/8283663 to your computer and use it in GitHub Desktop.
An example to create keyword-like arguments for a Clojure function
(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