/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMCalculatedRangeTest.m

http://macfuse.googlecode.com/ · Objective C · 101 lines · 67 code · 14 blank · 20 comment · 1 complexity · bda99739fa3a5187f42e23ebb7ecffb2 MD5 · raw file

  1. //
  2. // GTMCalculatedRangeTest.m
  3. //
  4. // Copyright 2006-2008 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import "GTMCalculatedRange.h"
  19. #import "GTMSenTestCase.h"
  20. @interface GTMCalculatedRangeTest : GTMTestCase {
  21. GTMCalculatedRange *range_;
  22. }
  23. @end
  24. @implementation GTMCalculatedRangeTest
  25. NSString *kStrings[] = { @"Fee", @"Fi", @"Fo", @"Fum" };
  26. const NSUInteger kStringCount = sizeof(kStrings) / sizeof(NSString*);
  27. const CGFloat kOddPosition = 0.14159265f;
  28. const CGFloat kExistingPosition = 0.5f;
  29. const NSUInteger kExisitingIndex = 2;
  30. - (void)setUp {
  31. range_ = [[GTMCalculatedRange alloc] init];
  32. for(NSUInteger i = kStringCount; i > 0; --i) {
  33. [range_ insertStop:kStrings[kStringCount - i] atPosition:(CGFloat)(1.0 / i)];
  34. }
  35. }
  36. - (void)tearDown {
  37. [range_ release];
  38. }
  39. - (void)testInsertStop {
  40. // new position
  41. NSString *theString = @"I smell the blood of an Englishman!";
  42. [range_ insertStop:theString atPosition:kOddPosition];
  43. STAssertEquals([range_ stopCount], kStringCount + 1, @"Stop count was bad");
  44. NSString *getString = [range_ valueAtPosition:kOddPosition];
  45. STAssertNotNil(getString, @"String was bad");
  46. STAssertEquals(theString, getString, @"Stops weren't equal");
  47. // existing position
  48. NSString *theStringTake2 = @"I smell the blood of an Englishman! Take 2";
  49. [range_ insertStop:theStringTake2 atPosition:kOddPosition];
  50. STAssertEquals([range_ stopCount], kStringCount + 1, @"Stop count was bad");
  51. getString = [range_ valueAtPosition:kOddPosition];
  52. STAssertNotNil(getString, @"String was bad");
  53. STAssertEquals(theStringTake2, getString, @"Stops weren't equal");
  54. STAssertNotEquals(theString, getString, @"Should be the new value");
  55. STAssertNotEqualObjects(theString, getString, @"Should be the new value");
  56. }
  57. - (void)testRemoveStopAtPosition {
  58. STAssertFalse([range_ removeStopAtPosition: kOddPosition], @"Was able to remove non-existant stop");
  59. STAssertTrue([range_ removeStopAtPosition: kExistingPosition], @"Was unable to remove good stop");
  60. STAssertEquals([range_ stopCount], kStringCount - 1, @"Removing stop should adjust stop count");
  61. }
  62. - (void)testRemoveStopAtIndex {
  63. STAssertThrows([range_ removeStopAtIndex: kStringCount], @"Was able to remove non-existant stop");
  64. STAssertNoThrow([range_ removeStopAtIndex: kStringCount - 1], @"Was unable to remove good stop");
  65. STAssertEquals([range_ stopCount], kStringCount - 1, @"Removing stop should adjust stop count");
  66. }
  67. - (void)testStopCount {
  68. STAssertEquals([range_ stopCount], kStringCount, @"Bad stop count");
  69. }
  70. - (void)testValueAtPosition {
  71. STAssertEqualObjects([range_ valueAtPosition: kExistingPosition], kStrings[kExisitingIndex], nil);
  72. STAssertNotEqualObjects([range_ valueAtPosition: kExistingPosition], kStrings[kStringCount - 1], nil);
  73. STAssertNil([range_ valueAtPosition: kOddPosition], nil);
  74. }
  75. - (void)testStopAtIndex {
  76. CGFloat thePosition;
  77. STAssertEqualObjects([range_ stopAtIndex:kStringCount - 1 position:nil], kStrings[kStringCount - 1], nil);
  78. STAssertEqualObjects([range_ stopAtIndex:kExisitingIndex position:&thePosition], kStrings[kExisitingIndex], nil);
  79. STAssertEquals(thePosition, kExistingPosition, nil);
  80. STAssertNotEqualObjects([range_ stopAtIndex:kStringCount - 1 position:nil], kStrings[2], nil);
  81. STAssertThrows([range_ stopAtIndex:kStringCount position:nil], nil);
  82. }
  83. - (void)testDescription {
  84. // we expect a description of atleast a few chars
  85. STAssertGreaterThan([[range_ description] length], (NSUInteger)10, nil);
  86. }
  87. @end