OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #include "v8.h" | 30 #include "v8.h" |
31 | 31 |
32 #include "factory.h" | 32 #include "factory.h" |
33 #include "global-handles.h" | 33 #include "global-handles.h" |
34 #include "unique.h" | 34 #include "unique.h" |
35 #include "cctest.h" | 35 #include "cctest.h" |
36 | 36 |
37 using namespace v8::internal; | 37 using namespace v8::internal; |
38 | 38 |
| 39 #define MAKE_HANDLES_AND_DISALLOW_ALLOCATION \ |
| 40 Isolate* isolate = Isolate::Current(); \ |
| 41 Factory* factory = isolate->factory(); \ |
| 42 HandleScope sc(isolate); \ |
| 43 Handle<String> handles[] = { \ |
| 44 factory->InternalizeUtf8String("A"), \ |
| 45 factory->InternalizeUtf8String("B"), \ |
| 46 factory->InternalizeUtf8String("C"), \ |
| 47 factory->InternalizeUtf8String("D"), \ |
| 48 factory->InternalizeUtf8String("E"), \ |
| 49 factory->InternalizeUtf8String("F"), \ |
| 50 factory->InternalizeUtf8String("G") \ |
| 51 }; \ |
| 52 DisallowHeapAllocation _disable |
| 53 |
| 54 #define MAKE_UNIQUES_A_B_C \ |
| 55 Unique<String> A(handles[0]); \ |
| 56 Unique<String> B(handles[1]); \ |
| 57 Unique<String> C(handles[2]) |
| 58 |
| 59 #define MAKE_UNIQUES_A_B_C_D_E_F_G \ |
| 60 Unique<String> A(handles[0]); \ |
| 61 Unique<String> B(handles[1]); \ |
| 62 Unique<String> C(handles[2]); \ |
| 63 Unique<String> D(handles[3]); \ |
| 64 Unique<String> E(handles[4]); \ |
| 65 Unique<String> F(handles[5]); \ |
| 66 Unique<String> G(handles[6]) |
| 67 |
39 template <class T, class U> | 68 template <class T, class U> |
40 void CheckHashCodeEqual(Unique<T> a, Unique<U> b) { | 69 void CheckHashCodeEqual(Unique<T> a, Unique<U> b) { |
41 int64_t hasha = static_cast<int64_t>(a.Hashcode()); | 70 int64_t hasha = static_cast<int64_t>(a.Hashcode()); |
42 int64_t hashb = static_cast<int64_t>(b.Hashcode()); | 71 int64_t hashb = static_cast<int64_t>(b.Hashcode()); |
43 CHECK_NE(static_cast<int64_t>(0), hasha); | 72 CHECK_NE(static_cast<int64_t>(0), hasha); |
44 CHECK_NE(static_cast<int64_t>(0), hashb); | 73 CHECK_NE(static_cast<int64_t>(0), hashb); |
45 CHECK_EQ(hasha, hashb); | 74 CHECK_EQ(hasha, hashb); |
46 } | 75 } |
47 | 76 |
48 | 77 |
49 template <class T, class U> | 78 template <class T, class U> |
50 void CheckHashCodeNotEqual(Unique<T> a, Unique<U> b) { | 79 void CheckHashCodeNotEqual(Unique<T> a, Unique<U> b) { |
51 int64_t hasha = static_cast<int64_t>(a.Hashcode()); | 80 int64_t hasha = static_cast<int64_t>(a.Hashcode()); |
52 int64_t hashb = static_cast<int64_t>(b.Hashcode()); | 81 int64_t hashb = static_cast<int64_t>(b.Hashcode()); |
53 CHECK_NE(static_cast<int64_t>(0), hasha); | 82 CHECK_NE(static_cast<int64_t>(0), hasha); |
54 CHECK_NE(static_cast<int64_t>(0), hashb); | 83 CHECK_NE(static_cast<int64_t>(0), hashb); |
55 CHECK_NE(hasha, hashb); | 84 CHECK_NE(hasha, hashb); |
56 } | 85 } |
57 | 86 |
58 | 87 |
59 TEST(UniqueCreate) { | 88 TEST(UniqueCreate) { |
60 CcTest::InitializeVM(); | 89 CcTest::InitializeVM(); |
61 Isolate* isolate = Isolate::Current(); | 90 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
62 Factory* factory = isolate->factory(); | 91 Handle<String> A = handles[0], B = handles[1]; |
63 HandleScope sc(isolate); | |
64 | 92 |
65 Handle<String> A = factory->InternalizeUtf8String("A"); | |
66 Unique<String> HA(A); | 93 Unique<String> HA(A); |
67 | 94 |
68 CHECK(*HA.handle() == *A); | 95 CHECK(*HA.handle() == *A); |
69 CHECK_EQ(*A, *HA.handle()); | 96 CHECK_EQ(*A, *HA.handle()); |
70 | 97 |
71 Unique<String> HA2(A); | 98 Unique<String> HA2(A); |
72 | 99 |
73 CheckHashCodeEqual(HA, HA2); | 100 CheckHashCodeEqual(HA, HA2); |
74 CHECK(HA == HA2); | 101 CHECK(HA == HA2); |
75 CHECK_EQ(*HA.handle(), *HA2.handle()); | 102 CHECK_EQ(*HA.handle(), *HA2.handle()); |
76 | 103 |
77 CHECK(HA2 == HA); | 104 CHECK(HA2 == HA); |
78 CHECK_EQ(*HA2.handle(), *HA.handle()); | 105 CHECK_EQ(*HA2.handle(), *HA.handle()); |
79 | 106 |
80 Handle<String> B = factory->InternalizeUtf8String("B"); | |
81 Unique<String> HB(B); | 107 Unique<String> HB(B); |
82 | 108 |
83 CheckHashCodeNotEqual(HA, HB); | 109 CheckHashCodeNotEqual(HA, HB); |
84 CHECK(HA != HB); | 110 CHECK(HA != HB); |
85 CHECK_NE(*HA.handle(), *HB.handle()); | 111 CHECK_NE(*HA.handle(), *HB.handle()); |
86 | 112 |
87 CHECK(HB != HA); | 113 CHECK(HB != HA); |
88 CHECK_NE(*HB.handle(), *HA.handle()); | 114 CHECK_NE(*HB.handle(), *HA.handle()); |
89 | 115 |
90 // TODO(titzer): check that Unique properly survives a GC. | 116 // TODO(titzer): check that Unique properly survives a GC. |
91 } | 117 } |
92 | 118 |
93 | 119 |
94 TEST(UniqueSubsume) { | 120 TEST(UniqueSubsume) { |
95 CcTest::InitializeVM(); | 121 CcTest::InitializeVM(); |
96 Isolate* isolate = Isolate::Current(); | 122 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
97 Factory* factory = isolate->factory(); | 123 Handle<String> A = handles[0]; |
98 HandleScope sc(isolate); | |
99 | 124 |
100 Handle<String> A = factory->InternalizeUtf8String("A"); | |
101 Unique<String> HA(A); | 125 Unique<String> HA(A); |
102 | 126 |
103 CHECK(*HA.handle() == *A); | 127 CHECK(*HA.handle() == *A); |
104 CHECK_EQ(*A, *HA.handle()); | 128 CHECK_EQ(*A, *HA.handle()); |
105 | 129 |
106 Unique<Object> HO = HA; // Here comes the subsumption, boys. | 130 Unique<Object> HO = HA; // Here comes the subsumption, boys. |
107 | 131 |
108 CheckHashCodeEqual(HA, HO); | 132 CheckHashCodeEqual(HA, HO); |
109 CHECK(HA == HO); | 133 CHECK(HA == HO); |
110 CHECK_EQ(*HA.handle(), *HO.handle()); | 134 CHECK_EQ(*HA.handle(), *HO.handle()); |
111 | 135 |
112 CHECK(HO == HA); | 136 CHECK(HO == HA); |
113 CHECK_EQ(*HO.handle(), *HA.handle()); | 137 CHECK_EQ(*HO.handle(), *HA.handle()); |
114 } | 138 } |
115 | 139 |
116 | 140 |
117 TEST(UniqueSet_Add) { | 141 TEST(UniqueSet_Add) { |
118 CcTest::InitializeVM(); | 142 CcTest::InitializeVM(); |
119 Isolate* isolate = Isolate::Current(); | 143 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
120 Factory* factory = isolate->factory(); | 144 MAKE_UNIQUES_A_B_C; |
121 HandleScope sc(isolate); | |
122 | |
123 Unique<String> A(factory->InternalizeUtf8String("A")); | |
124 Unique<String> B(factory->InternalizeUtf8String("B")); | |
125 Unique<String> C(factory->InternalizeUtf8String("C")); | |
126 | 145 |
127 Zone zone(isolate); | 146 Zone zone(isolate); |
128 | 147 |
129 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); | 148 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); |
130 | 149 |
131 CHECK_EQ(0, set->size()); | 150 CHECK_EQ(0, set->size()); |
132 set->Add(A, &zone); | 151 set->Add(A, &zone); |
133 CHECK_EQ(1, set->size()); | 152 CHECK_EQ(1, set->size()); |
134 set->Add(A, &zone); | 153 set->Add(A, &zone); |
135 CHECK_EQ(1, set->size()); | 154 CHECK_EQ(1, set->size()); |
136 set->Add(B, &zone); | 155 set->Add(B, &zone); |
137 CHECK_EQ(2, set->size()); | 156 CHECK_EQ(2, set->size()); |
138 set->Add(C, &zone); | 157 set->Add(C, &zone); |
139 CHECK_EQ(3, set->size()); | 158 CHECK_EQ(3, set->size()); |
140 set->Add(C, &zone); | 159 set->Add(C, &zone); |
141 CHECK_EQ(3, set->size()); | 160 CHECK_EQ(3, set->size()); |
142 set->Add(B, &zone); | 161 set->Add(B, &zone); |
143 CHECK_EQ(3, set->size()); | 162 CHECK_EQ(3, set->size()); |
144 set->Add(A, &zone); | 163 set->Add(A, &zone); |
145 CHECK_EQ(3, set->size()); | 164 CHECK_EQ(3, set->size()); |
146 } | 165 } |
147 | 166 |
148 | 167 |
149 TEST(UniqueSet_Contains) { | 168 TEST(UniqueSet_Contains) { |
150 CcTest::InitializeVM(); | 169 CcTest::InitializeVM(); |
151 Isolate* isolate = Isolate::Current(); | 170 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
152 Factory* factory = isolate->factory(); | 171 MAKE_UNIQUES_A_B_C; |
153 HandleScope sc(isolate); | |
154 | |
155 Unique<String> A(factory->InternalizeUtf8String("A")); | |
156 Unique<String> B(factory->InternalizeUtf8String("B")); | |
157 Unique<String> C(factory->InternalizeUtf8String("C")); | |
158 | 172 |
159 Zone zone(isolate); | 173 Zone zone(isolate); |
160 | 174 |
161 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); | 175 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); |
162 | 176 |
163 CHECK_EQ(0, set->size()); | 177 CHECK_EQ(0, set->size()); |
164 set->Add(A, &zone); | 178 set->Add(A, &zone); |
165 CHECK(set->Contains(A)); | 179 CHECK(set->Contains(A)); |
166 CHECK(!set->Contains(B)); | 180 CHECK(!set->Contains(B)); |
167 CHECK(!set->Contains(C)); | 181 CHECK(!set->Contains(C)); |
168 | 182 |
169 set->Add(A, &zone); | 183 set->Add(A, &zone); |
170 CHECK(set->Contains(A)); | 184 CHECK(set->Contains(A)); |
171 CHECK(!set->Contains(B)); | 185 CHECK(!set->Contains(B)); |
172 CHECK(!set->Contains(C)); | 186 CHECK(!set->Contains(C)); |
173 | 187 |
174 set->Add(B, &zone); | 188 set->Add(B, &zone); |
175 CHECK(set->Contains(A)); | 189 CHECK(set->Contains(A)); |
176 CHECK(set->Contains(B)); | 190 CHECK(set->Contains(B)); |
177 | 191 |
178 set->Add(C, &zone); | 192 set->Add(C, &zone); |
179 CHECK(set->Contains(A)); | 193 CHECK(set->Contains(A)); |
180 CHECK(set->Contains(B)); | 194 CHECK(set->Contains(B)); |
181 CHECK(set->Contains(C)); | 195 CHECK(set->Contains(C)); |
182 } | 196 } |
183 | 197 |
184 | 198 |
185 TEST(UniqueSet_At) { | 199 TEST(UniqueSet_At) { |
186 CcTest::InitializeVM(); | 200 CcTest::InitializeVM(); |
187 Isolate* isolate = Isolate::Current(); | 201 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
188 Factory* factory = isolate->factory(); | 202 MAKE_UNIQUES_A_B_C; |
189 HandleScope sc(isolate); | |
190 | |
191 Unique<String> A(factory->InternalizeUtf8String("A")); | |
192 Unique<String> B(factory->InternalizeUtf8String("B")); | |
193 Unique<String> C(factory->InternalizeUtf8String("C")); | |
194 | 203 |
195 Zone zone(isolate); | 204 Zone zone(isolate); |
196 | 205 |
197 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); | 206 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); |
198 | 207 |
199 CHECK_EQ(0, set->size()); | 208 CHECK_EQ(0, set->size()); |
200 set->Add(A, &zone); | 209 set->Add(A, &zone); |
201 CHECK(A == set->at(0)); | 210 CHECK(A == set->at(0)); |
202 | 211 |
203 set->Add(A, &zone); | 212 set->Add(A, &zone); |
(...skipping 15 matching lines...) Expand all Loading... |
219 UniqueSet<T>* set1, UniqueSet<T>* set2, bool expected) { | 228 UniqueSet<T>* set1, UniqueSet<T>* set2, bool expected) { |
220 CHECK(set1->Equals(set1)); | 229 CHECK(set1->Equals(set1)); |
221 CHECK(set2->Equals(set2)); | 230 CHECK(set2->Equals(set2)); |
222 CHECK(expected == set1->Equals(set2)); | 231 CHECK(expected == set1->Equals(set2)); |
223 CHECK(expected == set2->Equals(set1)); | 232 CHECK(expected == set2->Equals(set1)); |
224 } | 233 } |
225 | 234 |
226 | 235 |
227 TEST(UniqueSet_Equals) { | 236 TEST(UniqueSet_Equals) { |
228 CcTest::InitializeVM(); | 237 CcTest::InitializeVM(); |
229 Isolate* isolate = Isolate::Current(); | 238 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
230 Factory* factory = isolate->factory(); | 239 MAKE_UNIQUES_A_B_C; |
231 HandleScope sc(isolate); | |
232 | |
233 Unique<String> A(factory->InternalizeUtf8String("A")); | |
234 Unique<String> B(factory->InternalizeUtf8String("B")); | |
235 Unique<String> C(factory->InternalizeUtf8String("C")); | |
236 | 240 |
237 Zone zone(isolate); | 241 Zone zone(isolate); |
238 | 242 |
239 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); | 243 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); |
240 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); | 244 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); |
241 | 245 |
242 CHECK_SETS(set1, set2, true); | 246 CHECK_SETS(set1, set2, true); |
243 | 247 |
244 set1->Add(A, &zone); | 248 set1->Add(A, &zone); |
245 | 249 |
(...skipping 16 matching lines...) Expand all Loading... |
262 CHECK_SETS(set1, set2, false); | 266 CHECK_SETS(set1, set2, false); |
263 | 267 |
264 set2->Add(B, &zone); | 268 set2->Add(B, &zone); |
265 | 269 |
266 CHECK_SETS(set1, set2, true); | 270 CHECK_SETS(set1, set2, true); |
267 } | 271 } |
268 | 272 |
269 | 273 |
270 TEST(UniqueSet_IsSubset1) { | 274 TEST(UniqueSet_IsSubset1) { |
271 CcTest::InitializeVM(); | 275 CcTest::InitializeVM(); |
272 Isolate* isolate = Isolate::Current(); | 276 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
273 Factory* factory = isolate->factory(); | 277 MAKE_UNIQUES_A_B_C; |
274 HandleScope sc(isolate); | |
275 | |
276 Unique<String> A(factory->InternalizeUtf8String("A")); | |
277 Unique<String> B(factory->InternalizeUtf8String("B")); | |
278 Unique<String> C(factory->InternalizeUtf8String("C")); | |
279 | 278 |
280 Zone zone(isolate); | 279 Zone zone(isolate); |
281 | 280 |
282 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); | 281 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); |
283 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); | 282 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); |
284 | 283 |
285 CHECK(set1->IsSubset(set2)); | 284 CHECK(set1->IsSubset(set2)); |
286 CHECK(set2->IsSubset(set1)); | 285 CHECK(set2->IsSubset(set1)); |
287 | 286 |
288 set1->Add(A, &zone); | 287 set1->Add(A, &zone); |
(...skipping 13 matching lines...) Expand all Loading... |
302 | 301 |
303 set1->Add(B, &zone); | 302 set1->Add(B, &zone); |
304 | 303 |
305 CHECK(set1->IsSubset(set2)); | 304 CHECK(set1->IsSubset(set2)); |
306 CHECK(set2->IsSubset(set1)); | 305 CHECK(set2->IsSubset(set1)); |
307 } | 306 } |
308 | 307 |
309 | 308 |
310 TEST(UniqueSet_IsSubset2) { | 309 TEST(UniqueSet_IsSubset2) { |
311 CcTest::InitializeVM(); | 310 CcTest::InitializeVM(); |
312 Isolate* isolate = Isolate::Current(); | 311 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
313 Factory* factory = isolate->factory(); | 312 MAKE_UNIQUES_A_B_C_D_E_F_G; |
314 HandleScope sc(isolate); | |
315 | |
316 Unique<String> A(factory->InternalizeUtf8String("A")); | |
317 Unique<String> B(factory->InternalizeUtf8String("B")); | |
318 Unique<String> C(factory->InternalizeUtf8String("C")); | |
319 Unique<String> D(factory->InternalizeUtf8String("D")); | |
320 Unique<String> E(factory->InternalizeUtf8String("E")); | |
321 Unique<String> F(factory->InternalizeUtf8String("F")); | |
322 Unique<String> G(factory->InternalizeUtf8String("G")); | |
323 | 313 |
324 Zone zone(isolate); | 314 Zone zone(isolate); |
325 | 315 |
326 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); | 316 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); |
327 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); | 317 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); |
328 | 318 |
329 set1->Add(A, &zone); | 319 set1->Add(A, &zone); |
330 set1->Add(C, &zone); | 320 set1->Add(C, &zone); |
331 set1->Add(E, &zone); | 321 set1->Add(E, &zone); |
332 | 322 |
(...skipping 21 matching lines...) Expand all Loading... |
354 if ((which & (1 << i)) != 0) set->Add(elements[i], zone); | 344 if ((which & (1 << i)) != 0) set->Add(elements[i], zone); |
355 } | 345 } |
356 return set; | 346 return set; |
357 } | 347 } |
358 | 348 |
359 | 349 |
360 TEST(UniqueSet_IsSubsetExhaustive) { | 350 TEST(UniqueSet_IsSubsetExhaustive) { |
361 const int kSetSize = 6; | 351 const int kSetSize = 6; |
362 | 352 |
363 CcTest::InitializeVM(); | 353 CcTest::InitializeVM(); |
364 Isolate* isolate = Isolate::Current(); | 354 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
365 Factory* factory = isolate->factory(); | 355 MAKE_UNIQUES_A_B_C_D_E_F_G; |
366 HandleScope sc(isolate); | |
367 | 356 |
368 Zone zone(isolate); | 357 Zone zone(isolate); |
369 | 358 |
370 Unique<String> A(factory->InternalizeUtf8String("A")); | |
371 Unique<String> B(factory->InternalizeUtf8String("B")); | |
372 Unique<String> C(factory->InternalizeUtf8String("C")); | |
373 Unique<String> D(factory->InternalizeUtf8String("D")); | |
374 Unique<String> E(factory->InternalizeUtf8String("E")); | |
375 Unique<String> F(factory->InternalizeUtf8String("F")); | |
376 Unique<String> G(factory->InternalizeUtf8String("G")); | |
377 | |
378 Unique<String> elements[] = { | 359 Unique<String> elements[] = { |
379 A, B, C, D, E, F, G | 360 A, B, C, D, E, F, G |
380 }; | 361 }; |
381 | 362 |
382 // Exhaustively test all sets with <= 6 elements. | 363 // Exhaustively test all sets with <= 6 elements. |
383 for (int i = 0; i < (1 << kSetSize); i++) { | 364 for (int i = 0; i < (1 << kSetSize); i++) { |
384 for (int j = 0; j < (1 << kSetSize); j++) { | 365 for (int j = 0; j < (1 << kSetSize); j++) { |
385 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); | 366 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); |
386 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); | 367 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); |
387 | 368 |
388 CHECK(((i & j) == i) == set1->IsSubset(set2)); | 369 CHECK(((i & j) == i) == set1->IsSubset(set2)); |
389 } | 370 } |
390 } | 371 } |
391 } | 372 } |
392 | 373 |
393 | 374 |
394 TEST(UniqueSet_Intersect1) { | 375 TEST(UniqueSet_Intersect1) { |
395 CcTest::InitializeVM(); | 376 CcTest::InitializeVM(); |
396 Isolate* isolate = Isolate::Current(); | 377 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
397 Factory* factory = isolate->factory(); | 378 MAKE_UNIQUES_A_B_C; |
398 HandleScope sc(isolate); | |
399 | |
400 Unique<String> A(factory->InternalizeUtf8String("A")); | |
401 Unique<String> B(factory->InternalizeUtf8String("B")); | |
402 Unique<String> C(factory->InternalizeUtf8String("C")); | |
403 | 379 |
404 Zone zone(isolate); | 380 Zone zone(isolate); |
405 | 381 |
406 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); | 382 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); |
407 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); | 383 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); |
408 UniqueSet<String>* result; | 384 UniqueSet<String>* result; |
409 | 385 |
410 CHECK(set1->IsSubset(set2)); | 386 CHECK(set1->IsSubset(set2)); |
411 CHECK(set2->IsSubset(set1)); | 387 CHECK(set2->IsSubset(set1)); |
412 | 388 |
(...skipping 19 matching lines...) Expand all Loading... |
432 | 408 |
433 CHECK_EQ(1, result->size()); | 409 CHECK_EQ(1, result->size()); |
434 CHECK(set1->Equals(result)); | 410 CHECK(set1->Equals(result)); |
435 } | 411 } |
436 | 412 |
437 | 413 |
438 TEST(UniqueSet_IntersectExhaustive) { | 414 TEST(UniqueSet_IntersectExhaustive) { |
439 const int kSetSize = 6; | 415 const int kSetSize = 6; |
440 | 416 |
441 CcTest::InitializeVM(); | 417 CcTest::InitializeVM(); |
442 Isolate* isolate = Isolate::Current(); | 418 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
443 Factory* factory = isolate->factory(); | 419 MAKE_UNIQUES_A_B_C_D_E_F_G; |
444 HandleScope sc(isolate); | |
445 | 420 |
446 Zone zone(isolate); | 421 Zone zone(isolate); |
447 | 422 |
448 Unique<String> A(factory->InternalizeUtf8String("A")); | |
449 Unique<String> B(factory->InternalizeUtf8String("B")); | |
450 Unique<String> C(factory->InternalizeUtf8String("C")); | |
451 Unique<String> D(factory->InternalizeUtf8String("D")); | |
452 Unique<String> E(factory->InternalizeUtf8String("E")); | |
453 Unique<String> F(factory->InternalizeUtf8String("F")); | |
454 Unique<String> G(factory->InternalizeUtf8String("G")); | |
455 | |
456 Unique<String> elements[] = { | 423 Unique<String> elements[] = { |
457 A, B, C, D, E, F, G | 424 A, B, C, D, E, F, G |
458 }; | 425 }; |
459 | 426 |
460 // Exhaustively test all sets with <= 6 elements. | 427 // Exhaustively test all sets with <= 6 elements. |
461 for (int i = 0; i < (1 << kSetSize); i++) { | 428 for (int i = 0; i < (1 << kSetSize); i++) { |
462 for (int j = 0; j < (1 << kSetSize); j++) { | 429 for (int j = 0; j < (1 << kSetSize); j++) { |
463 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); | 430 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); |
464 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); | 431 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); |
465 | 432 |
466 UniqueSet<String>* result = set1->Intersect(set2, &zone); | 433 UniqueSet<String>* result = set1->Intersect(set2, &zone); |
467 UniqueSet<String>* expected = MakeSet(&zone, i & j, elements); | 434 UniqueSet<String>* expected = MakeSet(&zone, i & j, elements); |
468 | 435 |
469 CHECK(result->Equals(expected)); | 436 CHECK(result->Equals(expected)); |
470 CHECK(expected->Equals(result)); | 437 CHECK(expected->Equals(result)); |
471 } | 438 } |
472 } | 439 } |
473 } | 440 } |
474 | 441 |
475 | 442 |
476 TEST(UniqueSet_Union1) { | 443 TEST(UniqueSet_Union1) { |
477 CcTest::InitializeVM(); | 444 CcTest::InitializeVM(); |
478 Isolate* isolate = Isolate::Current(); | 445 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
479 Factory* factory = isolate->factory(); | 446 MAKE_UNIQUES_A_B_C; |
480 HandleScope sc(isolate); | |
481 | |
482 Unique<String> A(factory->InternalizeUtf8String("A")); | |
483 Unique<String> B(factory->InternalizeUtf8String("B")); | |
484 Unique<String> C(factory->InternalizeUtf8String("C")); | |
485 | 447 |
486 Zone zone(isolate); | 448 Zone zone(isolate); |
487 | 449 |
488 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); | 450 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); |
489 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); | 451 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); |
490 UniqueSet<String>* result; | 452 UniqueSet<String>* result; |
491 | 453 |
492 CHECK(set1->IsSubset(set2)); | 454 CHECK(set1->IsSubset(set2)); |
493 CHECK(set2->IsSubset(set1)); | 455 CHECK(set2->IsSubset(set1)); |
494 | 456 |
(...skipping 19 matching lines...) Expand all Loading... |
514 | 476 |
515 CHECK_EQ(3, result->size()); | 477 CHECK_EQ(3, result->size()); |
516 CHECK(set2->Equals(result)); | 478 CHECK(set2->Equals(result)); |
517 } | 479 } |
518 | 480 |
519 | 481 |
520 TEST(UniqueSet_UnionExhaustive) { | 482 TEST(UniqueSet_UnionExhaustive) { |
521 const int kSetSize = 6; | 483 const int kSetSize = 6; |
522 | 484 |
523 CcTest::InitializeVM(); | 485 CcTest::InitializeVM(); |
524 Isolate* isolate = Isolate::Current(); | 486 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
525 Factory* factory = isolate->factory(); | 487 MAKE_UNIQUES_A_B_C_D_E_F_G; |
526 HandleScope sc(isolate); | |
527 | 488 |
528 Zone zone(isolate); | 489 Zone zone(isolate); |
529 | 490 |
530 Unique<String> A(factory->InternalizeUtf8String("A")); | |
531 Unique<String> B(factory->InternalizeUtf8String("B")); | |
532 Unique<String> C(factory->InternalizeUtf8String("C")); | |
533 Unique<String> D(factory->InternalizeUtf8String("D")); | |
534 Unique<String> E(factory->InternalizeUtf8String("E")); | |
535 Unique<String> F(factory->InternalizeUtf8String("F")); | |
536 Unique<String> G(factory->InternalizeUtf8String("G")); | |
537 | |
538 Unique<String> elements[] = { | 491 Unique<String> elements[] = { |
539 A, B, C, D, E, F, G | 492 A, B, C, D, E, F, G |
540 }; | 493 }; |
541 | 494 |
542 // Exhaustively test all sets with <= 6 elements. | 495 // Exhaustively test all sets with <= 6 elements. |
543 for (int i = 0; i < (1 << kSetSize); i++) { | 496 for (int i = 0; i < (1 << kSetSize); i++) { |
544 for (int j = 0; j < (1 << kSetSize); j++) { | 497 for (int j = 0; j < (1 << kSetSize); j++) { |
545 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); | 498 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); |
546 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); | 499 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); |
547 | 500 |
548 UniqueSet<String>* result = set1->Union(set2, &zone); | 501 UniqueSet<String>* result = set1->Union(set2, &zone); |
549 UniqueSet<String>* expected = MakeSet(&zone, i | j, elements); | 502 UniqueSet<String>* expected = MakeSet(&zone, i | j, elements); |
550 | 503 |
551 CHECK(result->Equals(expected)); | 504 CHECK(result->Equals(expected)); |
552 CHECK(expected->Equals(result)); | 505 CHECK(expected->Equals(result)); |
553 } | 506 } |
554 } | 507 } |
555 } | 508 } |
556 | 509 |
OLD | NEW |