Optimization to {{{-[NSString baseWritingDirection]}}} by Ofri Wolfus to use stack...
[adiumx.git] / UnitTests / TestDictionaryAdditions.m
blob91c04eb6448dbaba292468970ea2a6bcaadc74b8
1 #import "TestDictionaryAdditions.h"
3 #import <AIUtilities/AIDictionaryAdditions.h>
5 @implementation TestDictionaryAdditions
7 - (NSMutableDictionary *)startingDictionary {
8         return [NSMutableDictionary dictionaryWithObjectsAndKeys:
9                 [NSNumber numberWithUnsignedInt:0U], @"Foo",
10                 [NSNumber numberWithUnsignedInt:1U], @"Bar",
11                 [NSNumber numberWithUnsignedInt:2U], @"Baz",
12                 nil];
14 - (NSDictionary *)translation {
15         return [NSDictionary dictionaryWithObjectsAndKeys:
16                 @"Green", @"Foo",
17                 @"Red",   @"Bar",
18                 @"Blue",  @"Baz",
19                 nil];
21 - (NSDictionary *)addition {
22         return [NSDictionary dictionaryWithObjectsAndKeys:
23                 [NSNumber numberWithUnsignedInt:3U], @"Qux",
24                 [NSNumber numberWithUnsignedInt:4U], @"Quux",
25                 [NSNumber numberWithUnsignedInt:5U], @"Quuux",
26                 nil];
28 - (NSSet *)deletia {
29         return [NSSet setWithObjects:
30                 @"Foo",
31                 @"Bar",
32                 @"Baz",
33                 nil];
36 #pragma mark Test case methods
38 - (void)testTranslateAddRemove_translate {
39         NSMutableDictionary *dict = [self startingDictionary];
40         NSDictionary *translation = [self translation];
42         [dict translate:translation
43                                 add:nil
44                          remove:nil];
46         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Foo"]], @"translate:add:remove: method failed to translate %@ to %@", @"Foo", [translation objectForKey:@"Foo"]);
47         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Bar"]], @"translate:add:remove: method failed to translate %@ to %@", @"Bar", [translation objectForKey:@"Bar"]);
48         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Baz"]], @"translate:add:remove: method failed to translate %@ to %@", @"Baz", [translation objectForKey:@"Baz"]);
51 - (void)testTranslateAddRemove_add {
52         NSMutableDictionary *dict = [self startingDictionary];
54         [dict translate:nil
55                                 add:[self addition]
56                          remove:nil];
58         STAssertNotNil([dict objectForKey:@"Foo"],   @"translate:add:remove: method failed to keep %@", @"Foo");
59         STAssertNotNil([dict objectForKey:@"Bar"],   @"translate:add:remove: method failed to keep %@", @"Bar");
60         STAssertNotNil([dict objectForKey:@"Baz"],   @"translate:add:remove: method failed to keep %@", @"Baz");
61         STAssertNotNil([dict objectForKey:@"Qux"],   @"translate:add:remove: method failed to add %@", @"Qux");
62         STAssertNotNil([dict objectForKey:@"Quux"],  @"translate:add:remove: method failed to add %@", @"Quux");
63         STAssertNotNil([dict objectForKey:@"Quuux"], @"translate:add:remove: method failed to add %@", @"Quuux");
66 - (void)testTranslateAddRemove_remove {
67         NSMutableDictionary *dict = [self startingDictionary];
69         [dict translate:nil
70                                 add:nil
71                          remove:[self deletia]];
73         STAssertNil([dict objectForKey:@"Foo"], @"translate:add:remove: method failed to remove %@", @"Foo");
74         STAssertNil([dict objectForKey:@"Bar"], @"translate:add:remove: method failed to remove %@", @"Bar");
75         STAssertNil([dict objectForKey:@"Baz"], @"translate:add:remove: method failed to remove %@", @"Baz");
78 #pragma mark -
80 - (void)testTranslateAddRemove_translateAdd {
81         NSMutableDictionary *dict = [self startingDictionary];
82         NSDictionary *translation = [self translation];
84         [dict translate:translation
85                                 add:[self addition]
86                          remove:nil];
88         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Foo"]], @"translate:add:remove: method failed to translate %@ to %@", @"Foo", [translation objectForKey:@"Foo"]);
89         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Bar"]], @"translate:add:remove: method failed to translate %@ to %@", @"Bar", [translation objectForKey:@"Bar"]);
90         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Baz"]], @"translate:add:remove: method failed to translate %@ to %@", @"Baz", [translation objectForKey:@"Baz"]);
92         STAssertNotNil([dict objectForKey:@"Foo"],   @"translate:add:remove: method failed to keep %@", @"Foo");
93         STAssertNotNil([dict objectForKey:@"Bar"],   @"translate:add:remove: method failed to keep %@", @"Bar");
94         STAssertNotNil([dict objectForKey:@"Baz"],   @"translate:add:remove: method failed to keep %@", @"Baz");
95         STAssertNotNil([dict objectForKey:@"Qux"],   @"translate:add:remove: method failed to add %@", @"Qux");
96         STAssertNotNil([dict objectForKey:@"Quux"],  @"translate:add:remove: method failed to add %@", @"Quux");
97         STAssertNotNil([dict objectForKey:@"Quuux"], @"translate:add:remove: method failed to add %@", @"Quuux");
100 - (void)testTranslateAddRemove_translateRemove {
101         NSMutableDictionary *dict = [self startingDictionary];
102         NSDictionary *translation = [self translation];
104         [dict translate:translation
105                                 add:nil
106                          remove:[self deletia]];
108         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Foo"]], @"translate:add:remove: method failed to translate %@ to %@", @"Foo", [translation objectForKey:@"Foo"]);
109         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Bar"]], @"translate:add:remove: method failed to translate %@ to %@", @"Bar", [translation objectForKey:@"Bar"]);
110         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Baz"]], @"translate:add:remove: method failed to translate %@ to %@", @"Baz", [translation objectForKey:@"Baz"]);
112         STAssertNil([dict objectForKey:@"Foo"], @"translate:add:remove: method failed to remove %@", @"Foo");
113         STAssertNil([dict objectForKey:@"Bar"], @"translate:add:remove: method failed to remove %@", @"Bar");
114         STAssertNil([dict objectForKey:@"Baz"], @"translate:add:remove: method failed to remove %@", @"Baz");
117 - (void)testTranslateAddRemove_addRemove {
118         NSMutableDictionary *dict = [self startingDictionary];
120         [dict translate:nil
121                                 add:[self addition]
122                          remove:[self deletia]];
124         STAssertNotNil([dict objectForKey:@"Qux"],   @"translate:add:remove: method failed to add %@", @"Qux");
125         STAssertNotNil([dict objectForKey:@"Quux"],  @"translate:add:remove: method failed to add %@", @"Quux");
126         STAssertNotNil([dict objectForKey:@"Quuux"], @"translate:add:remove: method failed to add %@", @"Quuux");
128         STAssertNil([dict objectForKey:@"Foo"], @"translate:add:remove: method failed to remove %@", @"Foo");
129         STAssertNil([dict objectForKey:@"Bar"], @"translate:add:remove: method failed to remove %@", @"Bar");
130         STAssertNil([dict objectForKey:@"Baz"], @"translate:add:remove: method failed to remove %@", @"Baz");
133 #pragma mark -
135 - (void)testTranslateAddRemove_translateAddRemove {
136         NSMutableDictionary *dict = [self startingDictionary];
137         NSDictionary *translation = [self translation];
139         [dict translate:translation
140                                 add:[self addition]
141                          remove:[self deletia]];
143         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Foo"]], @"translate:add:remove: method failed to translate %@ to %@", @"Foo", [translation objectForKey:@"Foo"]);
144         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Bar"]], @"translate:add:remove: method failed to translate %@ to %@", @"Bar", [translation objectForKey:@"Bar"]);
145         STAssertNotNil([dict objectForKey:[translation objectForKey:@"Baz"]], @"translate:add:remove: method failed to translate %@ to %@", @"Baz", [translation objectForKey:@"Baz"]);
147         STAssertNotNil([dict objectForKey:@"Qux"],   @"translate:add:remove: method failed to add %@", @"Qux");
148         STAssertNotNil([dict objectForKey:@"Quux"],  @"translate:add:remove: method failed to add %@", @"Quux");
149         STAssertNotNil([dict objectForKey:@"Quuux"], @"translate:add:remove: method failed to add %@", @"Quuux");
151         STAssertNil([dict objectForKey:@"Foo"], @"translate:add:remove: method failed to remove %@", @"Foo");
152         STAssertNil([dict objectForKey:@"Bar"], @"translate:add:remove: method failed to remove %@", @"Bar");
153         STAssertNil([dict objectForKey:@"Baz"], @"translate:add:remove: method failed to remove %@", @"Baz");
156 @end