mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-02 21:29:45 +00:00
Fix a bug in [CPArray indexOfObject:sortedByDesciptors:], add a matching test.
This commit is contained in:
1 parent
7d158de356
commit
adde315e2d
2 files changed
+37
-1
No files matched your search
@@ -488,7 +488,7 @@
|
||||
*/
|
||||
- (unsigned)indexOfObject:(id)anObject sortedByDescriptors:(CPArray)descriptors
|
||||
{
|
||||
[self indexOfObject:anObject sortedByFunction:function(lhs, rhs)
|
||||
return [self indexOfObject:anObject sortedByFunction:function(lhs, rhs)
|
||||
{
|
||||
var i = 0,
|
||||
count = [descriptors count],
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@import <Foundation/CPArray.j>
|
||||
@import <Foundation/CPString.j>
|
||||
@import <Foundation/CPNumber.j>
|
||||
@import <Foundation/CPSortDescriptor.j>
|
||||
|
||||
@implementation CPArrayTest : OJTestCase
|
||||
|
||||
@@ -92,4 +93,39 @@
|
||||
|
||||
[self assert:array equals:[@"one", @"two", @"four"]];
|
||||
}
|
||||
|
||||
- (void)testIndexOfObjectSortedByFunction
|
||||
{
|
||||
var array = [0, 1, 2, 3, 4, 7];
|
||||
|
||||
[self assert:[array indexOfObject:3 sortedByFunction:function(a, b){ return a - b; }] equals:3];
|
||||
[self assert:[[array arrayByReversingArray] indexOfObject:3 sortedByFunction:function(a, b){ return b - a; }] equals:2];
|
||||
}
|
||||
|
||||
- (void)testIndexOfObjectSortedByDescriptors
|
||||
{
|
||||
var array = [0, 1, 2, 3, 4, 7];
|
||||
|
||||
[self assert:[array indexOfObject:3
|
||||
sortedByDescriptors:[[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:YES]]]
|
||||
equals:3];
|
||||
|
||||
[self assert:[[array arrayByReversingArray] indexOfObject:3
|
||||
sortedByDescriptors:[[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:NO]]]
|
||||
equals:2];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPArray (reverse)
|
||||
|
||||
- (CPArray)arrayByReversingArray
|
||||
{
|
||||
var a = [];
|
||||
for (i = length - 1; i>0; --i)
|
||||
a.push(self[i]);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user