Skip to content

Commit

Permalink
Better comment and a few more test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
cdlm committed Jan 29, 2021
1 parent af049f2 commit 5d1c1d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/Collections-Sequenceable-Tests/IntervalTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,16 @@ IntervalTest >> testRangeIncludes [

self assert: ((1 to: 10) rangeIncludes: 3).
self assert: ((1 to: 10 by: 2) rangeIncludes: 3).
self assert: ((1 to: 10 by: 2) rangeIncludes: 4).
self assert: ((10 to: 1 by: -2) rangeIncludes: 3).
self assert: ((1 to: 10 by: 2) rangeIncludes: 4).
self assert: ((1 to: 10) rangeIncludes: 3.5).

self deny: ((1 to: 10) rangeIncludes: 0).
self deny: ((1 to: 10) rangeIncludes: 11).
self deny: ((1 to: 10 by: 2) rangeIncludes: 0).
self deny: ((1 to: 10 by: 2) rangeIncludes: 11)
self deny: ((1 to: 10 by: 2) rangeIncludes: 11).
self deny: ((10 to: 1) rangeIncludes: 3).
self deny: ((10 to: 1) rangeIncludes: -3)
]

{ #category : #tests }
Expand Down
7 changes: 5 additions & 2 deletions src/Collections-Sequenceable/Interval.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,11 @@ Interval >> printOn: aStream [

{ #category : #testing }
Interval >> rangeIncludes: aNumber [
"Return true if the number lies in the interval between start and stop, considering all values in between as if step was either +1 or -1.
Use #include: to take the exact step into account."
"Return true if aNumber lies anywhere between the interval bounds.
This is a fast O(1) bounds check.
Beware: because #rangeIncludes: only considers the sign of the step, not its magnitude, it also returns true for values that are not actual elements of the interval.
For precise element inclusion with arbitrary step, use #includes:."

^ step >= 0
ifTrue: [ aNumber between: start and: stop ]
Expand Down

0 comments on commit 5d1c1d7

Please sign in to comment.