| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 440 |
| 441 // Re-insert to the deleted slot. | 441 // Re-insert to the deleted slot. |
| 442 { | 442 { |
| 443 Set::AddResult addResult = set.add(std::move(one)); | 443 Set::AddResult addResult = set.add(std::move(one)); |
| 444 EXPECT_TRUE(addResult.isNewEntry); | 444 EXPECT_TRUE(addResult.isNewEntry); |
| 445 EXPECT_EQ(onePointer, addResult.storedValue->get()); | 445 EXPECT_EQ(onePointer, addResult.storedValue->get()); |
| 446 EXPECT_EQ(1, **addResult.storedValue); | 446 EXPECT_EQ(1, **addResult.storedValue); |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 | 449 |
| 450 bool isOneTwoThree(const HashSet<int>& set) |
| 451 { |
| 452 return set.size() == 3 && set.contains(1) && set.contains(2) && set.contains
(3); |
| 453 } |
| 454 |
| 455 HashSet<int> returnOneTwoThree() |
| 456 { |
| 457 return {1, 2, 3}; |
| 458 } |
| 459 |
| 460 TEST(HashSetTest, InitializerList) |
| 461 { |
| 462 HashSet<int> empty({}); |
| 463 EXPECT_TRUE(empty.isEmpty()); |
| 464 |
| 465 HashSet<int> one({1}); |
| 466 EXPECT_EQ(1u, one.size()); |
| 467 EXPECT_TRUE(one.contains(1)); |
| 468 |
| 469 HashSet<int> oneTwoThree({1, 2, 3}); |
| 470 EXPECT_EQ(3u, oneTwoThree.size()); |
| 471 EXPECT_TRUE(oneTwoThree.contains(1)); |
| 472 EXPECT_TRUE(oneTwoThree.contains(2)); |
| 473 EXPECT_TRUE(oneTwoThree.contains(3)); |
| 474 |
| 475 // Put some jank so we can check if the assignments later can clear them. |
| 476 empty.add(9999); |
| 477 one.add(9999); |
| 478 oneTwoThree.add(9999); |
| 479 |
| 480 empty = {}; |
| 481 EXPECT_TRUE(empty.isEmpty()); |
| 482 |
| 483 one = {1}; |
| 484 EXPECT_EQ(1u, one.size()); |
| 485 EXPECT_TRUE(one.contains(1)); |
| 486 |
| 487 oneTwoThree = {1, 2, 3}; |
| 488 EXPECT_EQ(3u, oneTwoThree.size()); |
| 489 EXPECT_TRUE(oneTwoThree.contains(1)); |
| 490 EXPECT_TRUE(oneTwoThree.contains(2)); |
| 491 EXPECT_TRUE(oneTwoThree.contains(3)); |
| 492 |
| 493 oneTwoThree = {3, 1, 1, 2, 1, 1, 3}; |
| 494 EXPECT_EQ(3u, oneTwoThree.size()); |
| 495 EXPECT_TRUE(oneTwoThree.contains(1)); |
| 496 EXPECT_TRUE(oneTwoThree.contains(2)); |
| 497 EXPECT_TRUE(oneTwoThree.contains(3)); |
| 498 |
| 499 // Other ways of construction: as a function parameter and in a return state
ment. |
| 500 EXPECT_TRUE(isOneTwoThree({1, 2, 3})); |
| 501 EXPECT_TRUE(isOneTwoThree(returnOneTwoThree())); |
| 502 } |
| 503 |
| 450 } // anonymous namespace | 504 } // anonymous namespace |
| 451 | 505 |
| 452 } // namespace WTF | 506 } // namespace WTF |
| OLD | NEW |