Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for partial #30

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/clojure/core_test/partial.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(ns clojure.core-test.partial
(:require [clojure.test :as t]))

(defn test-fn [& args]
(into [] args))

(t/deftest test-partial
(let [simple-use (partial inc 2)]
(t/is (= 3 (simple-use))))
(let [lazily-evaluated (partial inc 2 3)]
#?(:clj (t/is (thrown? Exception (lazily-evaluated)))
:cljs (t/is (thrown? js/Error (lazily-evaluated)))))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if handling the JS case is needed, but I thought I'd add this. I can remove if that makes more sense.

(let [variadic (partial test-fn 1 2 3)]
(t/is (= [1 2 3 4] (variadic 4)))
(t/is (= [1 2 3 4 5] (variadic 4 5))))
(let [infinite-sequence (partial #(take %2 %1) (range))]
(t/is (= '(0 1 2 3 4) (infinite-sequence 5)))
(t/is (= '(0 1 2) (infinite-sequence 3))))
(let [partial-partial ((partial partial) test-fn)
pppartial (partial partial-partial :inner)]
(t/is (= [:inner :outer] (partial-partial :inner :outer)))
(t/is (= [:inner :outer] (pppartial :outer))))
(let [seq-of-partials (map #(partial * %1 %2) (range) (range))]
(t/is (= (map #(* % % %) (range 5))
(map #(%1 %2) seq-of-partials (range 5))))))
Loading