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 1 commit
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
15 changes: 15 additions & 0 deletions test/clojure/core_test/partial.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns clojure.core-test.partial
(:require [clojure.test :as t]))

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

(t/deftest test-partial []
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about:

  1. Chaining partials
  2. Including lazy sequences
  3. A partial partial

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to add some more cases.

For 2, I am pushing up a test that has an infinite sequence and takes from it. If that's not quite right let me know.

For 1, do you mean a sequence of partials? I included what could be a test for that, but also, if that's not quite right let me know.

Copy link
Member

@jeaye jeaye Jan 4, 2025

Choose a reason for hiding this comment

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

  1. You got this one
  2. Looks good
  3. I was thinking something like (((partial partial) +) 0 5)

Seemed like a good edge case to cover.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally. I adjusted the partial-partial tests. Lemme know any other adjustments.

(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)))))
Loading