File: test_inthashmap.cpp

package info (click to toggle)
boolector 3.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 20,744 kB
  • sloc: ansic: 83,136; cpp: 18,159; sh: 3,668; python: 2,889; makefile: 210
file content (79 lines) | stat: -rw-r--r-- 2,491 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
/*  Boolector: Satisfiability Modulo Theories (SMT) solver.
 *
 *  Copyright (C) 2007-2021 by the authors listed in the AUTHORS file.
 *
 *  This file is part of Boolector.
 *  See COPYING for more information on using this software.
 */

#include "test.h"

extern "C" {
#include "utils/btorhashint.h"
#include "utils/btorhashptr.h"
}

class TestIntHashMap : public TestMm
{
 protected:
  void SetUp () override
  {
    TestMm::SetUp ();
    d_htable = btor_hashint_map_new (d_mm);
  }

  void TearDown () override
  {
    if (d_htable)
    {
      btor_hashint_map_delete (d_htable);
      d_htable = nullptr;
    }
    TestMm::TearDown ();
  }

  BtorIntHashTable *d_htable = nullptr;
};

TEST_F (TestIntHashMap, new_delete)
{
  size_t allocated     = d_mm->allocated;
  BtorIntHashTable *ht = btor_hashint_map_new (d_mm);
  btor_hashint_map_delete (ht);
  ASSERT_EQ (allocated, d_mm->allocated);
}

TEST_F (TestIntHashMap, add)
{
  size_t i;
  BtorHashTableData d;
  int32_t items[] = {
      123,       -1,     17,      5,       32,       64,      -1023,    101231,
      10,        11,     12,      13,      14,       -25,     43,       57,
      75,        51,     86,      -210,    1349,     1084,    -5860,    -1948,
      19548,     45802,  489501,  5810,    -85901,   4885,    28040,    -54801,
      185018,    -43019, 5801,    50185,   18501,    -60154,  105,      195,
      192,       1941,   -148702, -182491, 109581,   -51883,  12840918, -189203,
      -19128348, 129481, 184022,  875092,  19824192, 4913823, 0};
  int32_t data[] = {
      123,       -1,     17,      5,       32,       64,      -1023,    101231,
      10,        11,     12,      13,      14,       -25,     43,       57,
      75,        51,     86,      -210,    1349,     1084,    -5860,    -1948,
      19548,     45802,  489501,  5810,    -85901,   4885,    28040,    -54801,
      185018,    -43019, 5801,    50185,   18501,    -60154,  105,      195,
      192,       1941,   -148702, -182491, 109581,   -51883,  12840918, -189203,
      -19128348, 129481, 184022,  875092,  19824192, 4913823, 0};

  for (i = 0; items[i] != 0; i++)
    btor_hashint_map_add (d_htable, items[i])->as_int = data[i];

  for (i = 0; items[i] != 0; i++)
    ASSERT_TRUE (btor_hashint_map_contains (d_htable, items[i]));

  for (i = 0; items[i] != 0; i++)
  {
    btor_hashint_map_remove (d_htable, items[i], &d);
    ASSERT_EQ (d.as_int, data[i]);
    ASSERT_FALSE (btor_hashint_map_contains (d_htable, items[i]));
  }
}