/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. @import <Foundation/CPIndexPath.j>
  2. @implementation CPIndexPathTest : OJTestCase
  3. {
  4. CPIndexPath indexPath;
  5. }
  6. - (void)setUp
  7. {
  8. indexPath = [[CPIndexPath alloc] initWithIndexes:[1,5,3,7,3] length:3];
  9. }
  10. - (void)testIndexPathConstructed
  11. {
  12. [self assertNotNull:indexPath];
  13. }
  14. - (void)testLength
  15. {
  16. [self assert:3 equals:[indexPath length]];
  17. }
  18. - (void)testIndexAtPosition
  19. {
  20. [self assert:5 equals:[indexPath indexAtPosition:1]];
  21. }
  22. - (void)testIndexPathByAddingIndex
  23. {
  24. [self assert:[CPIndexPath indexPathWithIndexes:[[indexPath indexes] arrayByAddingObject:3]]
  25. equals:[indexPath indexPathByAddingIndex:3]];
  26. }
  27. - (void)testIndexPathByRemovingLastIndex
  28. {
  29. // Keep removing indexes until the indexPath is empty
  30. while ([indexPath length] > 0)
  31. {
  32. var expectedIndexes = [[indexPath indexes] copy];
  33. [expectedIndexes removeObject:[expectedIndexes lastObject]];
  34. indexPath = [indexPath indexPathByRemovingLastIndex];
  35. [self assert:[CPIndexPath indexPathWithIndexes:expectedIndexes] equals:indexPath];
  36. }
  37. }
  38. - (void)testIndexes
  39. {
  40. var newIndexes = [indexPath indexes];
  41. [newIndexes removeObjectAtIndex:0];
  42. [self assert:[indexPath indexes] notEqual:newIndexes];
  43. }
  44. - (void)testCompareThrowsOnNil
  45. {
  46. [self assertThrows:function() { [indexPath compare:nil] }];
  47. }
  48. - (void)testCompare
  49. {
  50. var comparisonIndexPath = [CPIndexPath indexPathWithIndexes:[CPArray arrayWithObjects:1,5,2]];
  51. [self assert:CPOrderedDescending equals:[indexPath compare:comparisonIndexPath]];
  52. comparisonIndexPath = [CPIndexPath indexPathWithIndexes:[CPArray arrayWithObjects:1,4]];
  53. [self assert:CPOrderedDescending equals:[indexPath compare:comparisonIndexPath]];
  54. comparisonIndexPath = [CPIndexPath indexPathWithIndexes:[CPArray arrayWithObjects:1,5,3]];
  55. [self assert:CPOrderedSame equals:[indexPath compare:comparisonIndexPath]];
  56. comparisonIndexPath = [CPIndexPath indexPathWithIndexes:[CPArray arrayWithObjects:1,5,4]];
  57. [self assert:CPOrderedAscending equals:[indexPath compare:comparisonIndexPath]];
  58. comparisonIndexPath = [CPIndexPath indexPathWithIndexes:[CPArray arrayWithObjects:1,6]];
  59. [self assert:CPOrderedAscending equals:[indexPath compare:comparisonIndexPath]];
  60. }
  61. @end