PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/Foundation/CPIndexPathTest.j

http://github.com/cacaodev/cappuccino
Unknown | 81 lines | 61 code | 20 blank | 0 comment | 0 complexity | cb807e25c4f2ecf0db3d432061348221 MD5 | raw file
 1
 2@import <Foundation/CPIndexPath.j>
 3
 4
 5@implementation CPIndexPathTest : OJTestCase
 6{
 7    CPIndexPath indexPath;
 8}
 9
10- (void)setUp
11{
12    indexPath = [[CPIndexPath alloc] initWithIndexes:[1,5,3,7,3] length:3];
13}
14
15- (void)testIndexPathConstructed
16{
17    [self assertNotNull:indexPath];
18}
19
20- (void)testLength
21{
22    [self assert:3 equals:[indexPath length]];
23}
24
25- (void)testIndexAtPosition
26{
27    [self assert:5 equals:[indexPath indexAtPosition:1]];
28}
29
30- (void)testIndexPathByAddingIndex
31{
32    [self assert:[CPIndexPath indexPathWithIndexes:[[indexPath indexes] arrayByAddingObject:3]]
33          equals:[indexPath indexPathByAddingIndex:3]];
34}
35
36- (void)testIndexPathByRemovingLastIndex
37{
38    // Keep removing indexes until the indexPath is empty
39    while ([indexPath length] > 0)
40    {
41        var expectedIndexes = [[indexPath indexes] copy];
42        [expectedIndexes removeObject:[expectedIndexes lastObject]];
43
44        indexPath = [indexPath indexPathByRemovingLastIndex];
45        [self assert:[CPIndexPath indexPathWithIndexes:expectedIndexes] equals:indexPath];
46    }
47}
48
49- (void)testIndexes
50{
51    var newIndexes = [indexPath indexes];
52    [newIndexes removeObjectAtIndex:0];
53
54    [self assert:[indexPath indexes] notEqual:newIndexes];
55}
56
57- (void)testCompareThrowsOnNil
58{
59    [self assertThrows:function() { [indexPath compare:nil] }];
60}
61
62- (void)testCompare
63{
64    var comparisonIndexPath = [CPIndexPath indexPathWithIndexes:[CPArray arrayWithObjects:1,5,2]];
65
66    [self assert:CPOrderedDescending equals:[indexPath compare:comparisonIndexPath]];
67
68    comparisonIndexPath = [CPIndexPath indexPathWithIndexes:[CPArray arrayWithObjects:1,4]];
69    [self assert:CPOrderedDescending equals:[indexPath compare:comparisonIndexPath]];
70
71    comparisonIndexPath = [CPIndexPath indexPathWithIndexes:[CPArray arrayWithObjects:1,5,3]];
72    [self assert:CPOrderedSame equals:[indexPath compare:comparisonIndexPath]];
73
74    comparisonIndexPath = [CPIndexPath indexPathWithIndexes:[CPArray arrayWithObjects:1,5,4]];
75    [self assert:CPOrderedAscending equals:[indexPath compare:comparisonIndexPath]];
76
77    comparisonIndexPath = [CPIndexPath indexPathWithIndexes:[CPArray arrayWithObjects:1,6]];
78    [self assert:CPOrderedAscending equals:[indexPath compare:comparisonIndexPath]];
79}
80
81@end