// // HOMNSDictionarySelectSingleWhereTests.m // HigherOrderMessaging // // Created by Ofri Wolfus on 13/10/06. // Copyright 2006 Ofri Wolfus. All rights reserved. // #import "HOMNSDictionarySelectSingleWhereTests.h" @implementation HOMNSDictionarySelectSingleWhereTests - (id)init { if ((self = [super init])) { int i; msg1 = [MSG(hasPrefix:@"b") retain]; msg2 = [MSG(hasPrefix:@"9999") retain]; } 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 selectSingleWhere:MSG(hasPrefix:@"b"), nil]; } - (id)testSmallArray_CachedMessage { return [smallDict selectSingleWhere:msg1, nil]; } - (id)testSmallDictionary_objectAtIndex { unsigned i; NSArray *keys = [smallDict allKeys]; unsigned c = [smallDict count]; for (i = 0U; i < c; i++) { id key = [keys objectAtIndex:i]; NSString *str = [smallDict objectForKey:key]; if ([str hasPrefix:@"b"]) return [NSDictionary dictionaryWithObject:str forKey:key]; } return nil; } - (id)testSmallDictionary_NSEnumerator { NSEnumerator *e = [smallDict keyEnumerator]; NSString *str; id key; while ((key = [e nextObject])) { str = [smallDict objectForKey:key]; if ([str hasPrefix:@"b"]) return [NSDictionary dictionaryWithObject:str forKey:key]; } return nil; } #pragma mark - #pragma mark Large Dictionary Tests - (id)testLargeDictionary { return [largeDict selectSingleWhere:MSG(hasPrefix:@"9999"), nil]; } - (id)testLargeDictionary_CachedMessage { return [largeDict selectSingleWhere:msg2, nil]; } - (id)testLargeDictionary_objectAtIndex { unsigned i; NSArray *keys = [largeDict allKeys]; unsigned c = [largeDict count]; for (i = 0U; i < c; i++) { id key = [keys objectAtIndex:i]; NSString *str = [largeDict objectForKey:key]; if ([str hasPrefix:@"9999"]) return [NSDictionary dictionaryWithObject:str forKey:key]; } return nil; } - (id)testLargeDictionary_NSEnumerator { NSEnumerator *e = [largeDict keyEnumerator]; NSString *str; id key; while ((key = [e nextObject])) { str = [largeDict objectForKey:key]; if ([str hasPrefix:@"9999"]) return [NSDictionary dictionaryWithObject:str forKey:key]; } return nil; } #pragma mark - #pragma mark Tests Verification - (BOOL)verifyResult:(NSDictionary *)dict ofTest:(SEL)sel { NSString *name = NSStringFromSelector(sel); if ([name hasPrefix:@"testSmallDictionary"]) { DPTestAssert([dict isEqualToDictionary:[NSDictionary dictionaryWithObject:@"b" forKey:[NSNumber numberWithUnsignedInt:2U]]] , @"The returned dictionary is not equal to the expected dictionart. Returned dict = %@", dict); } else if ([name hasPrefix:@"testLargeDictionary"]) { DPTestAssert([dict isEqualToDictionary:[NSDictionary dictionaryWithObject:@"9999" forKey:[NSNumber numberWithUnsignedInt:9999U]]] , @"The returned dictionary is not equal to the expected dictionart. Returned dict = %@", dict); } else { return [super verifyResult:dict ofTest:sel]; } return YES; } @end