about summary refs log tree commit diff homepage
path: root/unittests/DiscretePDF/DiscretePDFTest.cpp
blob: 2180360ca97671bd33206be4dbc56feb7d14b2d4 (plain) (blame)
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
#include "klee/Internal/ADT/DiscretePDF.h"
#include "gtest/gtest.h"
#include <iostream>
#include <vector>

int finished = 0;

using namespace klee;

TEST(DiscretePDFTest, Rotatation) {
  DiscretePDF<int> testTree;

  ASSERT_TRUE(testTree.empty());

  for (auto i = 0; i < 9; ++i)
    testTree.insert(i + 10, 0.1 * i);

  for (auto i = 9; i > 0; --i)
    testTree.insert(i + 100, 0.01 * i);

  ASSERT_FALSE(testTree.empty());

  ASSERT_TRUE(testTree.inTree(101));
  testTree.remove(101);
  ASSERT_FALSE(testTree.inTree(101));
  testTree.insert(101, 0.01);
  ASSERT_EQ(0.01, testTree.getWeight(101));

  ASSERT_EQ(11, testTree.choose(0.01));
  testTree.choose(0);
  testTree.choose(0.9999999);

  testTree.update(101, 0.9);

  for (auto i = 0; i < 9; ++i)
    testTree.remove(i + 10);
  for (auto i = 0; i < 50; ++i) {
    testTree.insert(50 + i, 2 * i);
  }

  for (auto i = 9; i > 0; --i)
    testTree.remove(i + 100);

  testTree.insert(1, 0);
#ifndef NDEBUG
  ASSERT_DEATH({ testTree.insert(1, 0); }, "already in tree");
#endif

  while (!testTree.empty()) {
    testTree.remove(testTree.choose(0));
  }

  testTree.insert(1, 1);
  testTree.insert(2, 2);

  ASSERT_EQ(1, testTree.getWeight(1));
  ASSERT_EQ(2, testTree.getWeight(2));
}