// // HOMNSDictionaryRejectSingleWhereTests.m // HigherOrderMessaging // // Created by Ofri Wolfus on 13/10/06. // Copyright 2006 Ofri Wolfus. All rights reserved. // #import "HOMNSDictionaryRejectSingleWhereTests.h" @implementation HOMNSDictionaryRejectSingleWhereTests - (id)init { if ((self = [super init])) { unsigned i; msg1 = [MSG(hasPrefix:@"b") retain]; msg2 = [MSG(hasPrefix:@"9999") retain]; for (i = 0; i < 9999; i++) [largeDictResult setObject:[NSString stringWithFormat:@"%u", i] 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 rejectSingleWhere:MSG(hasPrefix:@"b"), nil]; } - (id)testSmallDictionary_CachedMessage { return [smallDict rejectSingleWhere:msg1, nil]; } - (id)testSmallDictionary_objectAtIndex { unsigned i; NSArray *arr = [smallDict allKeys]; NSMutableDictionary *r = [smallDict mutableCopy]; unsigned c = [smallDict count]; for (i = 0U; i < c; i++) { id key = [arr objectAtIndex:i]; NSString *str = [smallDict objectForKey:key]; if ([str hasPrefix:@"b"]) { [r removeObjectForKey:key]; break; } } return [r autorelease]; } - (id)testSmallDictionary_NSEnumerator { NSMutableDictionary *r = [smallDict mutableCopy]; NSEnumerator *e = [smallDict keyEnumerator]; NSString *str; id key; while ((key = [e nextObject])) { str = [smallDict objectForKey:key]; if ([str hasPrefix:@"b"]) { [r removeObjectForKey:key]; break; } } return [r autorelease]; } #pragma mark - #pragma mark Large Dictionary Tests - (id)testLargeDictionary { return [largeDict rejectSingleWhere:MSG(hasPrefix:@"9999"), nil]; } - (id)testLargeDictionary_CachedMessage { return [largeDict rejectSingleWhere:msg2, nil]; } - (id)testLargeDictionary_objectAtIndex { unsigned i; NSArray *arr = [largeDict allKeys]; NSMutableDictionary *r = [largeDict mutableCopy]; unsigned c = [largeDict count]; for (i = 0U; i < c; i++) { id key = [arr objectAtIndex:i]; NSString *str = [largeDict objectForKey:key]; if ([str hasPrefix:@"9999"]) { [r removeObjectForKey:key]; break; } } return [r autorelease]; } - (id)testLargeDictionary_NSEnumerator { NSMutableDictionary *r = [largeDict mutableCopy]; NSEnumerator *e = [largeDict keyEnumerator]; NSString *str; id key; while ((key = [e nextObject])) { str = [largeDict objectForKey:key]; if ([str hasPrefix:@"9999"]) { [r removeObjectForKey:key]; break; } } return [r autorelease]; } #pragma mark - #pragma mark Tests Verification - (BOOL)verifyResult:(NSDictionary *)dict ofTest:(SEL)sel { NSString *name = NSStringFromSelector(sel); if ([name hasPrefix:@"testSmallDictionary"]) { DPTestAssert([dict count] == 2U, @"The result doesn't contain 2 objects. Result = %@", dict); DPTestAssert([[dict objectForKey:[NSNumber numberWithUnsignedInt:1]] isEqualToString:@"a"], @"The result doesn't contain 'a'. Result = %@", dict); DPTestAssert([[dict objectForKey:[NSNumber numberWithUnsignedInt:3]] isEqualToString:@"abc"], @"The result doesn't contain 'abc'. Result = %@", dict); } return [super verifyResult:dict ofTest:sel]; } @end