Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[NEW] Tests for NSDictionary Each/Inject/Select

  • Loading branch information...
commit 9f01030f8d10cb69f8e6e274a94f590f19d87d3b 1 parent 8f3c3b0
@crafterm authored
View
22 Tests/NSDictionary+Each+Test.m
@@ -0,0 +1,22 @@
+//
+// NSDictionary+Each+Test.m
+// MRCEnumerable
+//
+// Created by Marcus Crafter on 18/11/10.
+// Copyright 2010 Red Artisan. All rights reserved.
+//
+
+@interface NSDictionary_Each_Test : GHTestCase
+@end
+
+@implementation NSDictionary_Each_Test
+
+- (void)testEachShouldCallTheBlockOverEachElement {
+ NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:@"dog", @"animal", nil];
+ [dict each:^(id key, id obj) {
+ GHAssertEquals(@"dog", obj, @"should be equal");
+ GHAssertEquals(@"animal", key, @"should be equal");
+ }];
+}
+
+@end
View
24 Tests/NSDictionary+Inject+Test.m
@@ -0,0 +1,24 @@
+//
+// NSDictionary+Inject+Test.m
+// MRCEnumerable
+//
+// Created by Marcus Crafter on 18/11/10.
+// Copyright 2010 Red Artisan. All rights reserved.
+//
+
+@interface NSDictionary_Inject_Test : GHTestCase
+@end
+
+@implementation NSDictionary_Inject_Test
+
+// it should call the block over each element, passing the results of previous block to the next
+
+- (void)testInjectShouldCallTheBlockOverEachElementPassingPreviousResultToNext {
+ NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:@"dog", @"animal", nil];
+ NSString * result = [dict inject:@"" :^(id m, id key, id obj) {
+ return (id)[m stringByAppendingFormat:@"%@ %@", key, obj];
+ }];
+ GHAssertEqualObjects(@"animal dog", result, @"should be equal");
+}
+
+@end
View
23 Tests/NSDictionary+Select+Test.m
@@ -0,0 +1,23 @@
+//
+// NSDictionary+Select+Test.m
+// MRCEnumerable
+//
+// Created by Marcus Crafter on 18/11/10.
+// Copyright 2010 Red Artisan. All rights reserved.
+//
+
+@interface NSDictionary_Select_Test : GHTestCase
+@end
+
+@implementation NSDictionary_Select_Test
+
+- (void)testSelectShouldCollectElementsReturningTrueWithTheSuppliedBlock {
+ NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:@"dog", @"pet", @"jack", @"car", nil];
+ NSDictionary * results = [dict select:^(id key, id obj) {
+ return (BOOL)([key length] == [obj length]);
+ }];
+ NSDictionary * expected = [NSDictionary dictionaryWithObjectsAndKeys:@"dog", @"pet", nil];
+ GHAssertEqualObjects(expected, results, @"should be equal");
+}
+
+@end
View
3  Tests_Prefix.pch
@@ -3,7 +3,6 @@
#import <GHUnit/GHUnit.h>
-#import "NSArray+Utilities.h"
-#import "NSArray+Enumerable.h"
+#import "MRCEnumerable.h"
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.