Incorrect range contents and count with step != 1

Description

From https://groups.google.com/d/msg/clojure/dweCm6Bd-vc/atritH--xUEJ.

Cause: absCount method in LongRange is not computing count correctly.

Approach: Fix computation in LongRange.absCount() and add a generative test that compares the long and non-long versions of range produce the same ranges.

Screened by: Alex Miller, also verified that generative test failed without the fix.

Patch: clj-1709-2.patch

Environment

clojure 1.7.0-beta1

Attachments

2

Activity

Show:

Alex Miller April 24, 2015 at 3:02 PM

Well Rich has now ok'ed it so would prefer no more changes to this patch.

Nelson Morris April 24, 2015 at 2:40 PM

Since this is still open to suggestions, if I were to write the spec over again I'd probably use (such-that #(not= 0 %) gen/int) for the step. A negative step will produce non-empty lists when end < start, and those might be worth checking. The case to avoid is one that makes an infinite range like (repeat 0 1 0), due to the equality check in the property. A more complicated generator could probably avoid that without a such-that filter, but not sure it would be worth the effort in this case.

Alex Miller April 24, 2015 at 2:20 PM

Tweaked one line in the test per Steve's suggestion.

Steve Miner April 23, 2015 at 6:36 PM

Regarding the test code, you could use gen/s-pos-int instead of (gen/such-that #(> % 0) gen/nat).

Devin Walters April 23, 2015 at 1:47 AM

Hey Michael, thanks for the background. I discussed this briefly with Alex at Clojure/West. By the sound of it, using defspec here should be fine. He mentioned he'd take a peek at it.

Completed

Details

Assignee

Reporter

Approval

Ok

Patch

Code and Test

Priority

Affects versions

Fix versions

Created April 18, 2015 at 11:12 PM
Updated April 24, 2015 at 4:14 PM
Resolved April 24, 2015 at 4:14 PM