Add tests for partition#893
Conversation
There was a problem hiding this comment.
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.cljctest 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.
| ;; 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" |
| ;; 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)" |
There was a problem hiding this comment.
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)))) |
There was a problem hiding this comment.
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)))) |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
Closes #389