File: test_unordered_map.cpp

package info (click to toggle)
bitwuzla 0.8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,292 kB
  • sloc: cpp: 94,870; python: 3,254; ansic: 1,613; sh: 50; makefile: 10
file content (98 lines) | stat: -rw-r--r-- 2,370 bytes parent folder | download
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
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
/***
 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
 *
 * Copyright (C) 2022 by the authors listed in the AUTHORS file at
 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
 *
 * This file is part of Bitwuzla under the MIT license. See COPYING for more
 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
 */

#include <gtest/gtest.h>

#include "backtrack/unordered_map.h"
#include "test.h"

namespace bzla::test {

class TestUnorderedMap : public ::testing::Test
{
};

TEST_F(TestUnorderedMap, ctor_dtor)
{
  backtrack::BacktrackManager mgr;
  backtrack::unordered_map<int, bool> map(&mgr);
}

TEST_F(TestUnorderedMap, push_pop)
{
  backtrack::BacktrackManager mgr;
  backtrack::unordered_map<int, bool> map(&mgr);
  map.emplace(0, true);
  map.emplace(1, false);
  map.emplace(2, true);
  mgr.push();
  ASSERT_EQ(map.size(), 3);
  ASSERT_FALSE(map.empty());
  map.emplace(3, true);
  map.emplace(4, true);
  map.emplace(3, true);  // duplicate
  ASSERT_EQ(map.size(), 5);
  mgr.pop();
  ASSERT_EQ(map.size(), 3);
  ASSERT_EQ(map.find(3), map.end());
  ASSERT_EQ(map.find(4), map.end());
  ASSERT_NE(map.find(0), map.end());
  ASSERT_NE(map.find(1), map.end());
  ASSERT_NE(map.find(2), map.end());
  ASSERT_DEATH_DEBUG(mgr.pop(), "d_scope_levels > 0");
}

TEST_F(TestUnorderedMap, push_pop_mgr)
{
  backtrack::BacktrackManager mgr;
  backtrack::unordered_map<int, bool> map(&mgr);
  backtrack::unordered_map<bool, int> map2(&mgr);
  map.emplace(0, true);
  map.emplace(1, false);
  map.emplace(2, true);
  mgr.push();
  ASSERT_EQ(map.size(), 3);
  ASSERT_FALSE(map.empty());
  map.emplace(3, true);
  map.emplace(4, true);
  map.emplace(3, true);  // duplicate
  ASSERT_EQ(map.size(), 5);
  mgr.pop();
  ASSERT_EQ(map.size(), 3);
  ASSERT_EQ(map.find(3), map.end());
  ASSERT_EQ(map.find(4), map.end());
  ASSERT_NE(map.find(0), map.end());
  ASSERT_NE(map.find(1), map.end());
  ASSERT_NE(map.find(2), map.end());
  ASSERT_DEATH_DEBUG(mgr.pop(), "d_scope_levels > 0");
}

TEST_F(TestUnorderedMap, stress)
{
  backtrack::BacktrackManager mgr;
  backtrack::unordered_map<size_t, size_t> map(&mgr);

  mgr.push();
  for (size_t i = 0; i < 10000000; ++i)
  {
    if (i % 100 == 0)
    {
      mgr.push();
    }
    map.emplace(i, i);
    if (i % 100 == 0)
    {
      mgr.pop();
    }
  }
  mgr.pop();
}

}  // namespace bzla::test