Fixed: indexOfObject:inSortedRange: searched 1 index too far when a range was applied.

This commit is contained in:
Alexander Ljungberg
2011-01-04 17:00:48 -03:00
parent 51848b6cce
commit be71d957e1
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -418,7 +418,7 @@ CPBinarySearchingInsertionIndex = 1 << 10;
return (options & CPBinarySearchingInsertionIndex) ? 0 : CPNotFound;
var first = aRange ? aRange.location : 0,
last = aRange ? CPMaxRange(aRange) : [self count] - 1;
last = (aRange ? CPMaxRange(aRange) : [self count]) - 1;
if (first < 0)
_CPRaiseRangeException(self, _cmd, first, count);
+13
View File
@@ -238,6 +238,19 @@
options:CPBinarySearchingLastEqual | CPBinarySearchingInsertionIndex
usingComparator:numComparator]
equals:6];
[self assert:[array indexOfObject:3
inSortedRange:CPMakeRange(2, 6) // [ -, -, 1, 1, 2, 2, 3, 3, -, -, -]
options:CPBinarySearchingLastEqual | CPBinarySearchingInsertionIndex
usingComparator:numComparator]
equals:8 message:"inserting index at end of range"];
[self assert:[[1, 2, 2] indexOfObject:2
inSortedRange:CPMakeRange(0, 2) // [1, 2]
options:CPBinarySearchingLastEqual | CPBinarySearchingInsertionIndex
usingComparator:numComparator]
equals:2 message:"insertion index should not be off by one when applying a range"];
}
- (void)testIndexOutOfBounds