aboutsummaryrefslogtreecommitdiff
path: root/tests/common/FlatSet.cpp
blob: a0c50a62a45056b3c9d6162867405947adccb5a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
/*
 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "tc_catch2.h"

#include "FlatSet.h"

TEST_CASE("Insertion", "[FlatSet]")
{
    Trinity::Containers::FlatSet<int> flat;

    REQUIRE(flat.insert(5).second == true);
    REQUIRE(flat.insert(3).second == true);
    REQUIRE(flat.insert(9).second == true);
    REQUIRE(flat.insert(7).second == true);

    REQUIRE(flat.insert(5).second == false);
    REQUIRE(flat.insert(3).second == false);
    REQUIRE(flat.insert(9).second == false);
    REQUIRE(flat.insert(7).second == false);

    REQUIRE(flat.size() == 4);

    auto itr = flat.begin();
    REQUIRE(*itr == 3);
    ++itr;
    REQUIRE(*itr == 5);
    ++itr;
    REQUIRE(*itr == 7);
    ++itr;
    REQUIRE(*itr == 9);
    ++itr;
    REQUIRE(itr == flat.end());
}

TEST_CASE("Erase", "[FlatSet]")
{
    Trinity::Containers::FlatSet<int> flat;
    flat.insert(3);
    flat.insert(5);
    flat.insert(7);
    flat.insert(9);

    REQUIRE(flat.erase(7) == 1);
    REQUIRE(flat.size() == 3);
}