Skip to content

Add tests for partition#893

Open
dgr wants to merge 4 commits into
jank-lang:mainfrom
dgr:dgr-partition
Open

Add tests for partition#893
dgr wants to merge 4 commits into
jank-lang:mainfrom
dgr:dgr-partition

Conversation

@dgr

@dgr dgr commented May 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #389

@dgr dgr requested review from E-A-Griffin and jeaye May 22, 2026 00:55
@jeaye jeaye requested a review from Copilot May 22, 2026 01:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new clojure.core/partition test namespace to cover expected behavior across its supported arities and validate laziness characteristics (issue #389).

Changes:

  • Introduces a new partition.cljc test file guarded by (when-var-exists partition ...).
  • Adds assertions for arities 2/3/4 including overlapping partitions, padding behavior, and empty/nil collection inputs.
  • Includes checks that the result is a lazy seq and initially unrealized.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/clojure/core_test/partition.cljc
Comment thread test/clojure/core_test/partition.cljc Outdated

@jeaye jeaye left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work!

Comment thread test/clojure/core_test/partition.cljc
Comment thread test/clojure/core_test/partition.cljc Outdated
(testing "arity 4 - (partition n step pad coll"
;; Use padding for the last element
(is (= '((0 1 2) (1 2 3) (2 3 4) (3 4 :a)) (partition 3 1 [:a :a :a] (range 5))))
(is (= '((0 1 2) (3 4 5) (6 7 8) (9 :a :a)) (partition 3 3 [:a :a :a] (range 10))))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Potential test: What if pad collection is too small?

Potential test: What if pad collection is empty?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, added.

Comment thread test/clojure/core_test/partition.cljc Outdated
Comment thread test/clojure/core_test/partition.cljc
@dgr

dgr commented May 23, 2026

Copy link
Copy Markdown
Collaborator Author

I believe this is ready to merge.

@dgr dgr requested a review from jeaye May 23, 2026 17:05
@jeaye

jeaye commented May 23, 2026

Copy link
Copy Markdown
Member

I'm not convinced we want the TODO for the floating point value support, since I gather that the fn is intended to only accept integral values. CLJS just happens to support it since there's only one number type for JS.

I think we should remove the floating point case, and the TODO. Keeping the big integer case is good, though, since it's an integral type.

@E-A-Griffin

Copy link
Copy Markdown
Collaborator

I'm not convinced we want the TODO for the floating point value support, since I gather that the fn is intended to only accept integral values. CLJS just happens to support it since there's only one number type for JS.

I think we should remove the floating point case, and the TODO. Keeping the big integer case is good, though, since it's an integral type.

I think the test is good to keep but the TODO should be dropped as I don't think non CLJS are obligated to do any particular behavior with floats, that being said, I think CLJS' behavior is interesting and worth documenting here (could see this causing a real bug in the wild for someone)

@E-A-Griffin E-A-Griffin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should add a test for (partition 0 ...) akin to what's shown here: https://clojuredocs.org/clojure.core/partition#example-57aa75fae4b0bafd3e2a04d3

@E-A-Griffin E-A-Griffin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Mostly looks good, left some optional suggestions

@dgr

dgr commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator Author

I think we should add a test for (partition 0 ...) akin to what's shown here: https://clojuredocs.org/clojure.core/partition#example-57aa75fae4b0bafd3e2a04d3

Sorry for the lag. Been busy with other things.

I originally tried some tests like that with zero and negative values for n and step, but they hang or repeat infinite values, which made me rethink them. Yes, the example at clojuredocs.org uses take to get the first few of an infinite stream of empty lists. But is that really useful? Is that really within the contract that partition is making? The assumption seems to be that n and step are positive integers, not zero or negative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clojure.core/partition

4 participants