// // HOMNSDictionaryCollectTest.m // HigherOrderMessaging // // Created by Ofri Wolfus on 11/10/06. // Copyright 2006 Ofri Wolfus. All rights reserved. // #import "HOMNSDictionaryCollectTest.h" @implementation HOMNSDictionaryCollectTest - (id)init { if ((self = [super init])) { int i; msg = [MSG(stringByAppendingString:@"x") retain]; for (i = 0; i < 10000; i++) [largeDictResult setObject:[NSString stringWithFormat:@"%dx", i] forKey:[NSNumber numberWithUnsignedInt:i]]; } return self; } - (void)dealloc { [msg release]; msg = nil; [super dealloc]; } #pragma mark - #pragma mark Small Dictionary Tests - (id)testSmallDictionary { return [smallDict collect:MSG(stringByAppendingString:@"x")]; } - (id)testSmallDictionary_CachedMessage { return [smallDict collect:msg]; } - (id)testSmallDictionary_objectAtIndex { unsigned i; NSMutableDictionary *r = [NSMutableDictionary dictionary]; NSArray *keys = [smallDict allKeys]; unsigned c = [smallDict count]; for (i = 0U; i < c; i++) { id key = [keys objectAtIndex:i]; [r setObject:[[smallDict objectForKey:key] stringByAppendingString:@"x"] forKey:key]; } return r; } - (id)testSmallDictionary_NSEnumerator { NSMutableDictionary *r = [NSMutableDictionary dictionary]; NSEnumerator *e = [smallDict keyEnumerator]; id key; while ((key = [e nextObject])) [r setObject:[[smallDict objectForKey:key] stringByAppendingString:@"x"] forKey:key]; return r; } #pragma mark - #pragma mark Large Dictionary Tests - (id)testLargeDictionary { return [largeDict collect:MSG(stringByAppendingString:@"x")]; } - (id)testLargeDictionary_CachedMessage { return [largeDict collect:msg]; } - (id)testLargeDictionary_objectAtIndex { unsigned i; NSMutableDictionary *r = [NSMutableDictionary dictionary]; NSArray *keys = [largeDict allKeys]; unsigned c = [largeDict count]; for (i = 0U; i < c; i++) { id key = [keys objectAtIndex:i]; [r setObject:[[largeDict objectForKey:key] stringByAppendingString:@"x"] forKey:key]; } return r; } - (id)testLargeDictionary_NSEnumerator { NSMutableDictionary *r = [NSMutableDictionary dictionary]; NSEnumerator *e = [largeDict keyEnumerator]; id key; while ((key = [e nextObject])) [r setObject:[[largeDict objectForKey:key] stringByAppendingString:@"x"] forKey:key]; return r; } #pragma mark - #pragma mark Tests Verification - (BOOL)verifyResult:(NSDictionary *)dict ofTest:(SEL)sel { NSString *name = NSStringFromSelector(sel); if ([name hasPrefix:@"testSmallDictionary"]) { DPTestAssert([dict count] == 3U, @"The result doesn't contain 3 objects. Result = %@", dict); DPTestAssert([[dict objectForKey:[NSNumber numberWithUnsignedInt:1]] isEqualToString:@"ax"], @"The result doesn't contain 'ax'. Result = %@", dict); DPTestAssert([[dict objectForKey:[NSNumber numberWithUnsignedInt:2]] isEqualToString:@"bx"], @"The result doesn't contain 'abcx'. Result = %@", dict); DPTestAssert([[dict objectForKey:[NSNumber numberWithUnsignedInt:3]] isEqualToString:@"abcx"], @"The result doesn't contain 'bx'. Result = %@", dict); } return [super verifyResult:dict ofTest:sel]; } @end