15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
-
+
-
+
-
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
|
#include <string.h>
#import "OFAutoreleasePool.h"
#import "OFDictionary.h"
#import "OFString.h"
#import "OFExceptions.h"
#define TESTS 15
#define TESTS 14
int
main()
{
int i = 0;
OFDictionary *dict = [OFMutableDictionary dictionaryWithHashSize: 16];
OFDictionary *dict = [OFMutableDictionary dictionary];
OFDictionary *dict2;
OFArray *keys, *objs;
OFIterator *iter = [dict iterator];
OFIterator *iter;
of_iterator_pair_t pair[2];
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFString *key1 = [OFString stringWithCString: "key1"];
OFString *key2 = [OFString stringWithCString: "key2"];
OFString *value1 = [OFString stringWithCString: "value1"];
OFString *value2 = [OFString stringWithCString: "value2"];
OFString *key1 = [OFString stringWithString: @"key1"];
OFString *key2 = [OFString stringWithString: @"key2"];
OFString *value1 = [OFString stringWithString: @"value1"];
OFString *value2 = [OFString stringWithString: @"value2"];
[dict setObject: value1
forKey: key1];
[dict setObject: value2
forKey: key2];
[pool release];
i++;
if (strcmp([[dict objectForKey: @"key1"] cString], "value1")) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
if (strcmp([[dict objectForKey: key2] cString], "value2")) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
pair[0] = [iter nextKeyObjectPair];
pair[1] = [iter nextKeyObjectPair];
if (![pair[0].key isEqual: @"key2"] ||
![pair[0].object isEqual: @"value2"] ||
![pair[1].key isEqual: @"key1"] ||
![pair[1].object isEqual: @"value1"]) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
[dict changeHashSize: 8];
iter = [dict iterator];
pair[0] = [iter nextKeyObjectPair];
pair[1] = [iter nextKeyObjectPair];
if (![pair[0].key isEqual: @"key1"] ||
![pair[0].object isEqual: @"value1"] ||
![pair[1].key isEqual: @"key2"] ||
![pair[1].object isEqual: @"value2"]) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
if ([dict averageItemsPerBucket] != 1.0) {
if ([dict count] != 2) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
if ([iter nextKeyObjectPair].object != nil) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
if ([dict objectForKey: @"key3"] != nil) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
[dict release];
dict = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar",
@"baz", @"qux",
nil];
@"baz", @"qux",
nil];
if (![[dict objectForKey: @"foo"] isEqual: @"bar"]) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
|