Created
August 14, 2010 18:31
-
-
Save hammerdr/524566 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)testThatCPArrayDoesSortUsingTwoDescriptors | |
| { | |
| var descriptors = [ | |
| [[CPSortDescriptor alloc] initWithKey:@"value" ascending:NO], | |
| [[CPSortDescriptor alloc] initWithKey:@"number" ascending:NO] | |
| ]; | |
| var target = [ | |
| [[CPPrettyObject alloc] initWithValue:@"a" number:1], | |
| [[CPPrettyObject alloc] initWithValue:@"a" number:2], | |
| [[CPPrettyObject alloc] initWithValue:@"a" number:3], | |
| [[CPPrettyObject alloc] initWithValue:@"b" number:1], | |
| [[CPPrettyObject alloc] initWithValue:@"b" number:2], | |
| [[CPPrettyObject alloc] initWithValue:@"b" number:3], | |
| ]; | |
| [target sortUsingDescriptors:descriptors]; | |
| [self assert:@"3:b" equals:[target[0] description]]; | |
| [self assert:@"2:b" equals:[target[1] description]]; | |
| [self assert:@"1:b" equals:[target[2] description]]; | |
| [self assert:@"3:a" equals:[target[3] description]]; | |
| [self assert:@"2:a" equals:[target[4] description]]; | |
| [self assert:@"1:a" equals:[target[5] description]]; | |
| } | |
| - (void)testThatCPArrayDoesSortUsingTwoDescriptorsOpposite | |
| { | |
| var descriptors = [ | |
| [[CPSortDescriptor alloc] initWithKey:@"number" ascending:NO], | |
| [[CPSortDescriptor alloc] initWithKey:@"value" ascending:NO] | |
| ]; | |
| var target = [ | |
| [[CPPrettyObject alloc] initWithValue:@"a" number:1], | |
| [[CPPrettyObject alloc] initWithValue:@"a" number:2], | |
| [[CPPrettyObject alloc] initWithValue:@"a" number:3], | |
| [[CPPrettyObject alloc] initWithValue:@"b" number:1], | |
| [[CPPrettyObject alloc] initWithValue:@"b" number:2], | |
| [[CPPrettyObject alloc] initWithValue:@"b" number:3], | |
| ]; | |
| [target sortUsingDescriptors:descriptors]; | |
| [self assert:@"3:b" equals:[target[0] description]]; | |
| [self assert:@"3:a" equals:[target[1] description]]; | |
| [self assert:@"2:b" equals:[target[2] description]]; | |
| [self assert:@"2:a" equals:[target[3] description]]; | |
| [self assert:@"1:b" equals:[target[4] description]]; | |
| [self assert:@"1:a" equals:[target[5] description]]; | |
| } | |
| - (void)testThatCPArrayDoesSortUsingDescriptorWithMultipleSameValues | |
| { | |
| var descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:NO]]; | |
| var target = [1, 1, 2, 4, 3, 1, 2, 4, 5, 1]; | |
| [target sortUsingDescriptors:descriptors]; | |
| [self assert:[5, 4, 4, 3, 2, 2, 1, 1, 1] equals:target]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment