1 // 2 // TestDictionary.m 3 // ST4 4 // 5 // Created by Alan Condit on 4/20/11. 6 // Copyright 2011 Alan Condit. All rights reserved. 7 // 8 9 #import "TestDictionary.h" 10 #import "AMutableDictionary.h" 11 12 @implementation TestDictionary 13 14 - (void)setUp 15 { 16 [super setUp]; 17 18 // Set-up code here. 19 } 20 21 - (void)tearDown 22 { 23 // Tear-down code here. 24 25 [super tearDown]; 26 } 27 28 - (void) test01add 29 { 30 AMutableDictionary *testDict; 31 NSString *key1 = @"a101"; 32 NSString *obj1 = @"obj101"; 33 34 testDict = [AMutableDictionary newDictionary]; 35 [testDict setObject:obj1 forKey:key1]; 36 NSString *expected = obj1; 37 NSString *result = [testDict objectForKey:key1]; 38 STAssertTrue( [expected isEqualTo:result], @"Expected \"%@\" but got \"%@\"", expected, result ); 39 } 40 41 - (void) test02add 42 { 43 AMutableDictionary *testDict; 44 NSString *key1 = @"a101"; 45 NSString *obj1 = @"obj101"; 46 NSString *key2 = @"a102"; 47 NSString *obj2 = @"obj102"; 48 49 testDict = [AMutableDictionary newDictionary]; 50 [testDict setObject:obj1 forKey:key1]; 51 [testDict setObject:obj2 forKey:key2]; 52 NSString *expected = obj1; 53 NSString *result = [testDict objectForKey:key1]; 54 STAssertTrue( [expected isEqualTo:result], @"Expected \"%@\" but got \"%@\"", expected, result ); 55 } 56 57 - (void) test03add 58 { 59 AMutableDictionary *testDict; 60 NSString *key1 = @"a101"; 61 NSString *obj1 = @"obj101"; 62 63 testDict = [AMutableDictionary newDictionary]; 64 [testDict setObject:obj1 forKey:key1]; 65 [testDict setObject:@"obj102" forKey:@"a102"]; 66 [testDict setObject:@"obj103" forKey:@"a103"]; 67 [testDict setObject:@"obj104" forKey:@"a104"]; 68 [testDict setObject:@"obj105" forKey:@"a105"]; 69 [testDict setObject:@"obj106" forKey:@"a106"]; 70 [testDict setObject:@"obj107" forKey:@"a107"]; 71 [testDict setObject:@"obj108" forKey:@"a108"]; 72 [testDict setObject:@"obj109" forKey:@"a109"]; 73 [testDict setObject:@"obj110" forKey:@"a110"]; 74 [testDict setObject:@"obj111" forKey:@"a111"]; 75 [testDict setObject:@"obj112" forKey:@"a112"]; 76 NSString *expected = @"obj106"; 77 NSString *result = [testDict objectForKey:@"a106"]; 78 STAssertTrue( [expected isEqualTo:result], @"Expected \"%@\" but got \"%@\"", expected, result ); 79 } 80 81 - (void) test04removefromLo 82 { 83 AMutableDictionary *testDict; 84 NSString *key1 = @"a101"; 85 NSString *obj1 = @"obj101"; 86 87 testDict = [AMutableDictionary newDictionary]; 88 [testDict setObject:obj1 forKey:key1]; 89 [testDict setObject:@"obj107" forKey:@"a107"]; 90 [testDict setObject:@"obj108" forKey:@"a108"]; 91 [testDict setObject:@"obj109" forKey:@"a109"]; 92 [testDict setObject:@"obj110" forKey:@"a110"]; 93 [testDict setObject:@"obj111" forKey:@"a111"]; 94 [testDict setObject:@"obj112" forKey:@"a112"]; 95 [testDict setObject:@"obj102" forKey:@"a102"]; 96 [testDict setObject:@"obj103" forKey:@"a103"]; 97 [testDict setObject:@"obj104" forKey:@"a104"]; 98 [testDict setObject:@"obj105" forKey:@"a105"]; 99 [testDict setObject:@"obj106" forKey:@"a106"]; 100 NSString *expected = @"obj105"; 101 NSString *result = [testDict objectForKey:@"a105"]; 102 STAssertTrue( [expected isEqualTo:result], @"Expected \"%@\" but got \"%@\"", expected, result ); 103 [testDict removeObjectForKey:@"a104"]; 104 result = [testDict objectForKey:@"a106"]; 105 expected = @"obj106"; 106 STAssertTrue( [expected isEqualTo:result], @"Expected \"%@\" but got \"%@\"", expected, result ); 107 } 108 109 - (void) test05removefromHi 110 { 111 AMutableDictionary *testDict; 112 NSString *key1 = @"a101"; 113 NSString *obj1 = @"obj101"; 114 115 testDict = [AMutableDictionary newDictionary]; 116 [testDict setObject:obj1 forKey:key1]; 117 [testDict setObject:@"obj107" forKey:@"a107"]; 118 [testDict setObject:@"obj108" forKey:@"a108"]; 119 [testDict setObject:@"obj109" forKey:@"a109"]; 120 [testDict setObject:@"obj110" forKey:@"a110"]; 121 [testDict setObject:@"obj111" forKey:@"a111"]; 122 [testDict setObject:@"obj112" forKey:@"a112"]; 123 [testDict setObject:@"obj102" forKey:@"a102"]; 124 [testDict setObject:@"obj103" forKey:@"a103"]; 125 [testDict setObject:@"obj104" forKey:@"a104"]; 126 [testDict setObject:@"obj105" forKey:@"a105"]; 127 [testDict setObject:@"obj106" forKey:@"a106"]; 128 NSString *expected = @"obj105"; 129 NSString *result = [testDict objectForKey:@"a105"]; 130 STAssertTrue( [expected isEqualTo:result], @"Expected \"%@\" but got \"%@\"", expected, result ); 131 [testDict removeObjectForKey:@"a108"]; 132 result = [testDict objectForKey:@"a110"]; 133 expected = @"obj110"; 134 STAssertTrue( [expected isEqualTo:result], @"Expected \"%@\" but got \"%@\"", expected, result ); 135 } 136 137 @end 138