Skip to content

Add tests for partition#893

Open
dgr wants to merge 1 commit into
jank-lang:mainfrom
dgr:dgr-partition
Open

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

Conversation

@dgr
Copy link
Copy Markdown
Collaborator

@dgr dgr commented May 22, 2026

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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 on lines +12 to +14
;; do not overlap. If a pad collection is supplied, use its elements as
;; necessary to complete last partition upto n items. In case there are
;; not enough padding elements, return a partition with less than n items.
(is (= '() (partition 2 1 '())))
(is (= '() (partition 2 1 nil))))

(testing "arity 4 - (partition n step pad coll"
Copy link
Copy Markdown
Member

@jeaye jeaye left a comment

Choose a reason for hiding this comment

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

Nice work!

;; necessary to complete last partition upto n items. In case there are
;; not enough padding elements, return a partition with less than n items.

(testing "arity 2 - (partition n coll)"
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 tests: n is zero or negative

Potential tests: step is zero or negative

Potential tests: pad is zero or negative

(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?


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

Let's use different values in the pad, to catch any issues around the order that they're used. Just [:a :b :c] should be fine.

(deftest test-partition

;; Docstring:
;; [n coll] [n step coll] [n step pad coll]
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.

What do we think about testing n and step being something more interesting than a Long? Such as a big integer? Still fits within the valid input assumption, I think, so worthwhile.

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

3 participants