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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 CHECK(HO == HA); | 136 CHECK(HO == HA); |
137 CHECK_EQ(*HO.handle(), *HA.handle()); | 137 CHECK_EQ(*HO.handle(), *HA.handle()); |
138 } | 138 } |
139 | 139 |
140 | 140 |
141 TEST(UniqueSet_Add) { | 141 TEST(UniqueSet_Add) { |
142 CcTest::InitializeVM(); | 142 CcTest::InitializeVM(); |
143 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 143 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
144 MAKE_UNIQUES_A_B_C; | 144 MAKE_UNIQUES_A_B_C; |
145 | 145 |
146 Zone zone(isolate); | 146 Zone zone; |
147 | 147 |
148 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); | 148 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); |
149 | 149 |
150 CHECK_EQ(0, set->size()); | 150 CHECK_EQ(0, set->size()); |
151 set->Add(A, &zone); | 151 set->Add(A, &zone); |
152 CHECK_EQ(1, set->size()); | 152 CHECK_EQ(1, set->size()); |
153 set->Add(A, &zone); | 153 set->Add(A, &zone); |
154 CHECK_EQ(1, set->size()); | 154 CHECK_EQ(1, set->size()); |
155 set->Add(B, &zone); | 155 set->Add(B, &zone); |
156 CHECK_EQ(2, set->size()); | 156 CHECK_EQ(2, set->size()); |
157 set->Add(C, &zone); | 157 set->Add(C, &zone); |
158 CHECK_EQ(3, set->size()); | 158 CHECK_EQ(3, set->size()); |
159 set->Add(C, &zone); | 159 set->Add(C, &zone); |
160 CHECK_EQ(3, set->size()); | 160 CHECK_EQ(3, set->size()); |
161 set->Add(B, &zone); | 161 set->Add(B, &zone); |
162 CHECK_EQ(3, set->size()); | 162 CHECK_EQ(3, set->size()); |
163 set->Add(A, &zone); | 163 set->Add(A, &zone); |
164 CHECK_EQ(3, set->size()); | 164 CHECK_EQ(3, set->size()); |
165 } | 165 } |
166 | 166 |
167 | 167 |
168 TEST(UniqueSet_Remove) { | 168 TEST(UniqueSet_Remove) { |
169 CcTest::InitializeVM(); | 169 CcTest::InitializeVM(); |
170 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 170 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
171 MAKE_UNIQUES_A_B_C; | 171 MAKE_UNIQUES_A_B_C; |
172 | 172 |
173 Zone zone(isolate); | 173 Zone zone; |
174 | 174 |
175 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); | 175 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); |
176 | 176 |
177 set->Add(A, &zone); | 177 set->Add(A, &zone); |
178 set->Add(B, &zone); | 178 set->Add(B, &zone); |
179 set->Add(C, &zone); | 179 set->Add(C, &zone); |
180 CHECK_EQ(3, set->size()); | 180 CHECK_EQ(3, set->size()); |
181 | 181 |
182 set->Remove(A); | 182 set->Remove(A); |
183 CHECK_EQ(2, set->size()); | 183 CHECK_EQ(2, set->size()); |
(...skipping 19 matching lines...) Expand all Loading... |
203 CHECK(!set->Contains(B)); | 203 CHECK(!set->Contains(B)); |
204 CHECK(!set->Contains(C)); | 204 CHECK(!set->Contains(C)); |
205 } | 205 } |
206 | 206 |
207 | 207 |
208 TEST(UniqueSet_Contains) { | 208 TEST(UniqueSet_Contains) { |
209 CcTest::InitializeVM(); | 209 CcTest::InitializeVM(); |
210 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 210 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
211 MAKE_UNIQUES_A_B_C; | 211 MAKE_UNIQUES_A_B_C; |
212 | 212 |
213 Zone zone(isolate); | 213 Zone zone; |
214 | 214 |
215 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); | 215 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); |
216 | 216 |
217 CHECK_EQ(0, set->size()); | 217 CHECK_EQ(0, set->size()); |
218 set->Add(A, &zone); | 218 set->Add(A, &zone); |
219 CHECK(set->Contains(A)); | 219 CHECK(set->Contains(A)); |
220 CHECK(!set->Contains(B)); | 220 CHECK(!set->Contains(B)); |
221 CHECK(!set->Contains(C)); | 221 CHECK(!set->Contains(C)); |
222 | 222 |
223 set->Add(A, &zone); | 223 set->Add(A, &zone); |
(...skipping 10 matching lines...) Expand all Loading... |
234 CHECK(set->Contains(B)); | 234 CHECK(set->Contains(B)); |
235 CHECK(set->Contains(C)); | 235 CHECK(set->Contains(C)); |
236 } | 236 } |
237 | 237 |
238 | 238 |
239 TEST(UniqueSet_At) { | 239 TEST(UniqueSet_At) { |
240 CcTest::InitializeVM(); | 240 CcTest::InitializeVM(); |
241 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 241 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
242 MAKE_UNIQUES_A_B_C; | 242 MAKE_UNIQUES_A_B_C; |
243 | 243 |
244 Zone zone(isolate); | 244 Zone zone; |
245 | 245 |
246 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); | 246 UniqueSet<String>* set = new(&zone) UniqueSet<String>(); |
247 | 247 |
248 CHECK_EQ(0, set->size()); | 248 CHECK_EQ(0, set->size()); |
249 set->Add(A, &zone); | 249 set->Add(A, &zone); |
250 CHECK(A == set->at(0)); | 250 CHECK(A == set->at(0)); |
251 | 251 |
252 set->Add(A, &zone); | 252 set->Add(A, &zone); |
253 CHECK(A == set->at(0)); | 253 CHECK(A == set->at(0)); |
254 | 254 |
(...skipping 16 matching lines...) Expand all Loading... |
271 CHECK(expected == set1->Equals(set2)); | 271 CHECK(expected == set1->Equals(set2)); |
272 CHECK(expected == set2->Equals(set1)); | 272 CHECK(expected == set2->Equals(set1)); |
273 } | 273 } |
274 | 274 |
275 | 275 |
276 TEST(UniqueSet_Equals) { | 276 TEST(UniqueSet_Equals) { |
277 CcTest::InitializeVM(); | 277 CcTest::InitializeVM(); |
278 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 278 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
279 MAKE_UNIQUES_A_B_C; | 279 MAKE_UNIQUES_A_B_C; |
280 | 280 |
281 Zone zone(isolate); | 281 Zone zone; |
282 | 282 |
283 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); | 283 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); |
284 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); | 284 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); |
285 | 285 |
286 CHECK_SETS(set1, set2, true); | 286 CHECK_SETS(set1, set2, true); |
287 | 287 |
288 set1->Add(A, &zone); | 288 set1->Add(A, &zone); |
289 | 289 |
290 CHECK_SETS(set1, set2, false); | 290 CHECK_SETS(set1, set2, false); |
291 | 291 |
(...skipping 17 matching lines...) Expand all Loading... |
309 | 309 |
310 CHECK_SETS(set1, set2, true); | 310 CHECK_SETS(set1, set2, true); |
311 } | 311 } |
312 | 312 |
313 | 313 |
314 TEST(UniqueSet_IsSubset1) { | 314 TEST(UniqueSet_IsSubset1) { |
315 CcTest::InitializeVM(); | 315 CcTest::InitializeVM(); |
316 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 316 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
317 MAKE_UNIQUES_A_B_C; | 317 MAKE_UNIQUES_A_B_C; |
318 | 318 |
319 Zone zone(isolate); | 319 Zone zone; |
320 | 320 |
321 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); | 321 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); |
322 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); | 322 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); |
323 | 323 |
324 CHECK(set1->IsSubset(set2)); | 324 CHECK(set1->IsSubset(set2)); |
325 CHECK(set2->IsSubset(set1)); | 325 CHECK(set2->IsSubset(set1)); |
326 | 326 |
327 set1->Add(A, &zone); | 327 set1->Add(A, &zone); |
328 | 328 |
329 CHECK(!set1->IsSubset(set2)); | 329 CHECK(!set1->IsSubset(set2)); |
(...skipping 14 matching lines...) Expand all Loading... |
344 CHECK(set1->IsSubset(set2)); | 344 CHECK(set1->IsSubset(set2)); |
345 CHECK(set2->IsSubset(set1)); | 345 CHECK(set2->IsSubset(set1)); |
346 } | 346 } |
347 | 347 |
348 | 348 |
349 TEST(UniqueSet_IsSubset2) { | 349 TEST(UniqueSet_IsSubset2) { |
350 CcTest::InitializeVM(); | 350 CcTest::InitializeVM(); |
351 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 351 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
352 MAKE_UNIQUES_A_B_C_D_E_F_G; | 352 MAKE_UNIQUES_A_B_C_D_E_F_G; |
353 | 353 |
354 Zone zone(isolate); | 354 Zone zone; |
355 | 355 |
356 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); | 356 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); |
357 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); | 357 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); |
358 | 358 |
359 set1->Add(A, &zone); | 359 set1->Add(A, &zone); |
360 set1->Add(C, &zone); | 360 set1->Add(C, &zone); |
361 set1->Add(E, &zone); | 361 set1->Add(E, &zone); |
362 | 362 |
363 set2->Add(A, &zone); | 363 set2->Add(A, &zone); |
364 set2->Add(B, &zone); | 364 set2->Add(B, &zone); |
(...skipping 22 matching lines...) Expand all Loading... |
387 } | 387 } |
388 | 388 |
389 | 389 |
390 TEST(UniqueSet_IsSubsetExhaustive) { | 390 TEST(UniqueSet_IsSubsetExhaustive) { |
391 const int kSetSize = 6; | 391 const int kSetSize = 6; |
392 | 392 |
393 CcTest::InitializeVM(); | 393 CcTest::InitializeVM(); |
394 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 394 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
395 MAKE_UNIQUES_A_B_C_D_E_F_G; | 395 MAKE_UNIQUES_A_B_C_D_E_F_G; |
396 | 396 |
397 Zone zone(isolate); | 397 Zone zone; |
398 | 398 |
399 Unique<String> elements[] = { | 399 Unique<String> elements[] = { |
400 A, B, C, D, E, F, G | 400 A, B, C, D, E, F, G |
401 }; | 401 }; |
402 | 402 |
403 // Exhaustively test all sets with <= 6 elements. | 403 // Exhaustively test all sets with <= 6 elements. |
404 for (int i = 0; i < (1 << kSetSize); i++) { | 404 for (int i = 0; i < (1 << kSetSize); i++) { |
405 for (int j = 0; j < (1 << kSetSize); j++) { | 405 for (int j = 0; j < (1 << kSetSize); j++) { |
406 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); | 406 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); |
407 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); | 407 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); |
408 | 408 |
409 CHECK(((i & j) == i) == set1->IsSubset(set2)); | 409 CHECK(((i & j) == i) == set1->IsSubset(set2)); |
410 } | 410 } |
411 } | 411 } |
412 } | 412 } |
413 | 413 |
414 | 414 |
415 TEST(UniqueSet_Intersect1) { | 415 TEST(UniqueSet_Intersect1) { |
416 CcTest::InitializeVM(); | 416 CcTest::InitializeVM(); |
417 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 417 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
418 MAKE_UNIQUES_A_B_C; | 418 MAKE_UNIQUES_A_B_C; |
419 | 419 |
420 Zone zone(isolate); | 420 Zone zone; |
421 | 421 |
422 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); | 422 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); |
423 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); | 423 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); |
424 UniqueSet<String>* result; | 424 UniqueSet<String>* result; |
425 | 425 |
426 CHECK(set1->IsSubset(set2)); | 426 CHECK(set1->IsSubset(set2)); |
427 CHECK(set2->IsSubset(set1)); | 427 CHECK(set2->IsSubset(set1)); |
428 | 428 |
429 set1->Add(A, &zone); | 429 set1->Add(A, &zone); |
430 | 430 |
(...skipping 20 matching lines...) Expand all Loading... |
451 } | 451 } |
452 | 452 |
453 | 453 |
454 TEST(UniqueSet_IntersectExhaustive) { | 454 TEST(UniqueSet_IntersectExhaustive) { |
455 const int kSetSize = 6; | 455 const int kSetSize = 6; |
456 | 456 |
457 CcTest::InitializeVM(); | 457 CcTest::InitializeVM(); |
458 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 458 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
459 MAKE_UNIQUES_A_B_C_D_E_F_G; | 459 MAKE_UNIQUES_A_B_C_D_E_F_G; |
460 | 460 |
461 Zone zone(isolate); | 461 Zone zone; |
462 | 462 |
463 Unique<String> elements[] = { | 463 Unique<String> elements[] = { |
464 A, B, C, D, E, F, G | 464 A, B, C, D, E, F, G |
465 }; | 465 }; |
466 | 466 |
467 // Exhaustively test all sets with <= 6 elements. | 467 // Exhaustively test all sets with <= 6 elements. |
468 for (int i = 0; i < (1 << kSetSize); i++) { | 468 for (int i = 0; i < (1 << kSetSize); i++) { |
469 for (int j = 0; j < (1 << kSetSize); j++) { | 469 for (int j = 0; j < (1 << kSetSize); j++) { |
470 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); | 470 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); |
471 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); | 471 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); |
472 | 472 |
473 UniqueSet<String>* result = set1->Intersect(set2, &zone); | 473 UniqueSet<String>* result = set1->Intersect(set2, &zone); |
474 UniqueSet<String>* expected = MakeSet(&zone, i & j, elements); | 474 UniqueSet<String>* expected = MakeSet(&zone, i & j, elements); |
475 | 475 |
476 CHECK(result->Equals(expected)); | 476 CHECK(result->Equals(expected)); |
477 CHECK(expected->Equals(result)); | 477 CHECK(expected->Equals(result)); |
478 } | 478 } |
479 } | 479 } |
480 } | 480 } |
481 | 481 |
482 | 482 |
483 TEST(UniqueSet_Union1) { | 483 TEST(UniqueSet_Union1) { |
484 CcTest::InitializeVM(); | 484 CcTest::InitializeVM(); |
485 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 485 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
486 MAKE_UNIQUES_A_B_C; | 486 MAKE_UNIQUES_A_B_C; |
487 | 487 |
488 Zone zone(isolate); | 488 Zone zone; |
489 | 489 |
490 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); | 490 UniqueSet<String>* set1 = new(&zone) UniqueSet<String>(); |
491 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); | 491 UniqueSet<String>* set2 = new(&zone) UniqueSet<String>(); |
492 UniqueSet<String>* result; | 492 UniqueSet<String>* result; |
493 | 493 |
494 CHECK(set1->IsSubset(set2)); | 494 CHECK(set1->IsSubset(set2)); |
495 CHECK(set2->IsSubset(set1)); | 495 CHECK(set2->IsSubset(set1)); |
496 | 496 |
497 set1->Add(A, &zone); | 497 set1->Add(A, &zone); |
498 | 498 |
(...skipping 20 matching lines...) Expand all Loading... |
519 } | 519 } |
520 | 520 |
521 | 521 |
522 TEST(UniqueSet_UnionExhaustive) { | 522 TEST(UniqueSet_UnionExhaustive) { |
523 const int kSetSize = 6; | 523 const int kSetSize = 6; |
524 | 524 |
525 CcTest::InitializeVM(); | 525 CcTest::InitializeVM(); |
526 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; | 526 MAKE_HANDLES_AND_DISALLOW_ALLOCATION; |
527 MAKE_UNIQUES_A_B_C_D_E_F_G; | 527 MAKE_UNIQUES_A_B_C_D_E_F_G; |
528 | 528 |
529 Zone zone(isolate); | 529 Zone zone; |
530 | 530 |
531 Unique<String> elements[] = { | 531 Unique<String> elements[] = { |
532 A, B, C, D, E, F, G | 532 A, B, C, D, E, F, G |
533 }; | 533 }; |
534 | 534 |
535 // Exhaustively test all sets with <= 6 elements. | 535 // Exhaustively test all sets with <= 6 elements. |
536 for (int i = 0; i < (1 << kSetSize); i++) { | 536 for (int i = 0; i < (1 << kSetSize); i++) { |
537 for (int j = 0; j < (1 << kSetSize); j++) { | 537 for (int j = 0; j < (1 << kSetSize); j++) { |
538 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); | 538 UniqueSet<String>* set1 = MakeSet(&zone, i, elements); |
539 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); | 539 UniqueSet<String>* set2 = MakeSet(&zone, j, elements); |
540 | 540 |
541 UniqueSet<String>* result = set1->Union(set2, &zone); | 541 UniqueSet<String>* result = set1->Union(set2, &zone); |
542 UniqueSet<String>* expected = MakeSet(&zone, i | j, elements); | 542 UniqueSet<String>* expected = MakeSet(&zone, i | j, elements); |
543 | 543 |
544 CHECK(result->Equals(expected)); | 544 CHECK(result->Equals(expected)); |
545 CHECK(expected->Equals(result)); | 545 CHECK(expected->Equals(result)); |
546 } | 546 } |
547 } | 547 } |
548 } | 548 } |
OLD | NEW |