// // HOMNSDictionaryRejectWhereTests.m // HigherOrderMessaging // // Created by Ofri Wolfus on 13/10/06. // Copyright 2006 Ofri Wolfus. All rights reserved. // #import "HOMNSDictionaryRejectWhereTests.h" @implementation HOMNSDictionaryRejectWhereTests - (id)init { if ((self = [super init])) { int i; msg1 = [MSG(hasPrefix:@"a") retain]; msg2 = [MSG(hasPrefix:@"1") retain]; for (i = 0; i < 10000; i++) { NSString *str = [NSString stringWithFormat:@"%d", i]; if (![str hasPrefix:@"1"]) [largeDictResult setObject:str forKey:[NSNumber numberWithUnsignedInt:i]]; } } return self; } - (void)dealloc { [msg1 release]; msg1 = nil; [msg2 release]; msg2 = nil; [super dealloc]; } #pragma mark - #pragma mark Small Dictionary Tests - (id)testSmallDictionary { return [smallDict rejectWhere:MSG(hasPrefix:@"a"), nil]; } - (id)testSmallDictionary_CachedMessage { return [smallDict rejectWhere:msg1, nil]; } - (id)testSmallDictionary_objectAtIndex { int i; NSMutableDictionary *r = [NSMutableDictionary dictionary]; NSArray *keys = [smallDict allKeys]; unsigned c = [smallDict count]; NSString *str; for (i = 0; i < c; i++) { id key = [keys objectAtIndex:i]; str = [smallDict objectForKey:key]; if (![str hasPrefix:@"a"]) [r setObject:str forKey:key]; } return r; } - (id)testSmallDictionary_NSEnumerator { NSMutableDictionary *r = [NSMutableDictionary dictionary]; NSEnumerator *e = [smallDict keyEnumerator]; id key; NSString *str; while ((key = [e nextObject])) { str = [smallDict objectForKey:key]; if (![str hasPrefix:@"a"]) [r setObject:str forKey:key]; } return r; } #pragma mark - #pragma mark Large Dictionary Tests - (id)testLargeDictionary { return [largeDict rejectWhere:MSG(hasPrefix:@"1"), nil]; } - (id)testLargeDictionary_CachedMessage { return [largeDict rejectWhere:msg2, nil]; } - (id)testLargeDictionary_objectAtIndex { int i; NSMutableDictionary *r = [NSMutableDictionary dictionary]; NSArray *keys = [largeDict allKeys]; unsigned c = [largeDict count]; NSString *str; for (i = 0; i < c; i++) { id key = [keys objectAtIndex:i]; str = [largeDict objectForKey:key]; if (![str hasPrefix:@"1"]) [r setObject:str forKey:key]; } return r; } - (id)testLargeDictionary_NSEnumerator { NSMutableDictionary *r = [NSMutableDictionary dictionary]; NSEnumerator *e = [largeDict keyEnumerator]; id key; NSString *str; while ((key = [e nextObject])) { str = [largeDict objectForKey:key]; if (![str hasPrefix:@"1"]) [r setObject:str 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] == 1U, @"The result doesn't contain one object. Result = %@", dict); DPTestAssert([[dict objectForKey:[NSNumber numberWithUnsignedInt:2]] isEqualToString:@"b"], @"The result doesn't contain 'b'. Result = %@", dict); } return [super verifyResult:dict ofTest:sel]; } @end