PageRenderTime 47ms CodeModel.GetById 26ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/core/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
 19#import "GTMCalculatedRange.h"
 20#import "GTMSenTestCase.h"
 21
 22@interface GTMCalculatedRangeTest : GTMTestCase {
 23  GTMCalculatedRange *range_;
 24}
 25@end
 26
 27@implementation GTMCalculatedRangeTest
 28NSString *kStrings[] = { @"Fee", @"Fi", @"Fo", @"Fum" };
 29const NSUInteger kStringCount = sizeof(kStrings) / sizeof(NSString*);
 30const CGFloat kOddPosition = 0.14159265f;
 31const CGFloat kExistingPosition = 0.5f;
 32const NSUInteger kExisitingIndex = 2;
 33
 34- (void)setUp {
 35  range_ = [[GTMCalculatedRange alloc] init];
 36  for(NSUInteger i = kStringCount; i > 0; --i) {
 37    [range_ insertStop:kStrings[kStringCount - i] atPosition:(CGFloat)(1.0 / i)];
 38  }
 39}
 40
 41- (void)tearDown {
 42  [range_ release];
 43}
 44
 45- (void)testInsertStop {
 46  // new position
 47  NSString *theString = @"I smell the blood of an Englishman!";
 48  [range_ insertStop:theString atPosition:kOddPosition];
 49  STAssertEquals([range_ stopCount], kStringCount + 1, @"Stop count was bad");
 50  NSString *getString = [range_ valueAtPosition:kOddPosition];
 51  STAssertNotNil(getString, @"String was bad");
 52  STAssertEquals(theString, getString, @"Stops weren't equal");
 53  // existing position
 54  NSString *theStringTake2 = @"I smell the blood of an Englishman! Take 2";
 55  [range_ insertStop:theStringTake2 atPosition:kOddPosition];
 56  STAssertEquals([range_ stopCount], kStringCount + 1, @"Stop count was bad");
 57  getString = [range_ valueAtPosition:kOddPosition];
 58  STAssertNotNil(getString, @"String was bad");
 59  STAssertEquals(theStringTake2, getString, @"Stops weren't equal");
 60  STAssertNotEquals(theString, getString, @"Should be the new value");
 61  STAssertNotEqualObjects(theString, getString, @"Should be the new value");
 62}
 63
 64- (void)testRemoveStopAtPosition {
 65  STAssertFalse([range_ removeStopAtPosition: kOddPosition], @"Was able to remove non-existant stop");
 66  STAssertTrue([range_ removeStopAtPosition: kExistingPosition], @"Was unable to remove good stop");
 67  STAssertEquals([range_ stopCount], kStringCount - 1, @"Removing stop should adjust stop count");
 68}
 69
 70- (void)testRemoveStopAtIndex {
 71  STAssertThrows([range_ removeStopAtIndex: kStringCount], @"Was able to remove non-existant stop");
 72  STAssertNoThrow([range_ removeStopAtIndex: kStringCount - 1], @"Was unable to remove good stop");
 73  STAssertEquals([range_ stopCount], kStringCount - 1, @"Removing stop should adjust stop count");  
 74}
 75
 76- (void)testStopCount {
 77  STAssertEquals([range_ stopCount], kStringCount, @"Bad stop count");
 78}
 79
 80- (void)testValueAtPosition {
 81  STAssertEqualObjects([range_ valueAtPosition: kExistingPosition], kStrings[kExisitingIndex], nil);
 82  STAssertNotEqualObjects([range_ valueAtPosition: kExistingPosition], kStrings[kStringCount - 1], nil);
 83  STAssertNil([range_ valueAtPosition: kOddPosition], nil);
 84}
 85
 86- (void)testStopAtIndex {
 87  CGFloat thePosition;
 88  
 89  STAssertEqualObjects([range_ stopAtIndex:kStringCount - 1 position:nil], kStrings[kStringCount - 1], nil);
 90  STAssertEqualObjects([range_ stopAtIndex:kExisitingIndex position:&thePosition], kStrings[kExisitingIndex], nil);
 91  STAssertEquals(thePosition, kExistingPosition, nil);
 92  STAssertNotEqualObjects([range_ stopAtIndex:kStringCount - 1 position:nil], kStrings[2], nil);
 93  STAssertThrows([range_ stopAtIndex:kStringCount position:nil], nil);
 94}
 95
 96- (void)testDescription {
 97  // we expect a description of atleast a few chars
 98  STAssertGreaterThan([[range_ description] length], (NSUInteger)10, nil);
 99}
100
101@end