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
|
#include <string.h>
#import "OFAutoreleasePool.h"
#import "OFDictionary.h"
#import "OFString.h"
#import "OFExceptions.h"
int
main()
{
OFDictionary *dict = [OFMutableDictionary dictionaryWithHashSize: 16];
OFDictionary *dict2;
OFIterator *iter = [dict iterator];
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"];
[dict set: key1
to: value1];
[dict set: key2
to: value2];
[pool release];
if (strcmp([[dict get: @"key1"] cString], "value1")) {
puts("\033[K\033[1;31mTest 1/9 failed!\033[m");
return 1;
}
if (strcmp([[dict get: key2] cString], "value2")) {
puts("\033[K\033[1;31mTest 2/9 failed!\033[m");
return 1;
}
if (![[iter nextObject] isEqual: @"key2"] ||
![[iter nextObject] isEqual: @"value2"] ||
![[iter nextObject] isEqual: @"key1"] ||
![[iter nextObject] isEqual: @"value1"]) {
puts("\033[K\033[1;31mTest 3/9 failed!\033[m");
return 1;
}
[dict changeHashSize: 8];
iter = [dict iterator];
if (![[iter nextObject] isEqual: @"key1"] ||
![[iter nextObject] isEqual: @"value1"] ||
![[iter nextObject] isEqual: @"key2"] ||
![[iter nextObject] isEqual: @"value2"]) {
puts("\033[K\033[1;31mTest 4/9 failed!\033[m");
return 1;
}
if ([dict averageItemsPerBucket] != 1.0) {
puts("\033[K\033[1;31mTest 5/9 failed!\033[m");
return 1;
}
if ([iter nextObject] != nil) {
puts("\033[K\033[1;31mTest 6/9 failed!\033[m");
return 1;
}
if ([dict get: @"key3"] != nil) {
puts("\033[K\033[1;31mTest 7/9 failed!\033[m");
return 1;
}
dict2 = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar",
@"baz", @"qux",
nil];
if (![[dict2 get: @"foo"] isEqual: @"bar"]) {
puts("\033[K\033[1;31mTest 8/9 failed!\033[m");
return 1;
}
if (![[dict2 get: @"baz"] isEqual: @"qux"]) {
puts("\033[K\033[1;31mTest 9/9 failed!\033[m");
return 1;
}
puts("\033[1;32mTests successful: 9/9\033[0m");
return 0;
}
|
>
>
>
>
<
>
|
>
|
>
|
>
|
>
>
>
>
>
>
>
|
|
>
|
|
|
<
<
<
|
|
|
|
>
>
>
>
>
>
>
>
>
>
|
|
|
|
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
113
114
115
116
117
118
119
120
121
122
123
|
#include <string.h>
#import "OFAutoreleasePool.h"
#import "OFDictionary.h"
#import "OFString.h"
#import "OFExceptions.h"
#define TESTS 10
int
main()
{
int i = 0;
OFDictionary *dict = [OFMutableDictionary dictionaryWithHashSize: 16];
OFIterator *iter = [dict iterator];
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"];
[dict set: key1
to: value1];
[dict set: key2
to: value2];
[pool release];
i++;
if (strcmp([[dict get: @"key1"] cString], "value1")) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
if (strcmp([[dict get: key2] cString], "value2")) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
if (![[iter nextObject] isEqual: @"key2"] ||
![[iter nextObject] isEqual: @"value2"] ||
![[iter nextObject] isEqual: @"key1"] ||
![[iter nextObject] 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];
if (![[iter nextObject] isEqual: @"key1"] ||
![[iter nextObject] isEqual: @"value1"] ||
![[iter nextObject] isEqual: @"key2"] ||
![[iter nextObject] isEqual: @"value2"]) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
if ([dict averageItemsPerBucket] != 1.0) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
if ([iter nextObject] != nil) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
if ([dict get: @"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];
if (![[dict get: @"foo"] isEqual: @"bar"]) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
if (![[dict get: @"baz"] isEqual: @"qux"]) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
i++;
[dict release];
dict = [OFDictionary dictionaryWithKey: @"foo"
andObject: @"bar"];
if (![[dict get: @"foo"] isEqual: @"bar"]) {
printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
return 1;
}
printf("\033[1;32mTests successful: %d/%d\033[0m\n", i, TESTS);
return 0;
}
|