-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgauge_test.cpp
62 lines (49 loc) · 1.4 KB
/
gauge_test.cpp
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
#include <catch2/catch_all.hpp>
#include <cxxmetrics/gauge.hpp>
using namespace std;
using namespace cxxmetrics;
TEST_CASE("Primitive Gauge works", "[gauge]")
{
gauge<std::string> g("hola");
REQUIRE(g.get() == "hola");
g.set("hello");
REQUIRE(g.get() == "hello");
REQUIRE(g.snapshot() == "hello");
gauge<int> h;
REQUIRE((h = 20).get() == 20);
h.set(50);
REQUIRE(h.get() == 50);
REQUIRE(h.snapshot() == 50);
}
TEST_CASE("Functional Gauge works", "[gauge]")
{
double value = 99.810;
std::function<double()> fn = [&value]() { return value; };
gauge<decltype(fn)> g(fn);
REQUIRE(g.get() == 99.81);
value = 10000;
REQUIRE_THAT(g.get(), Catch::Matchers::WithinULP(10000.0, 1));
REQUIRE_THAT(g.snapshot().value(), Catch::Matchers::WithinULP(10000.0, 1));
}
TEST_CASE("Pointer Gauge works", "[gauge]")
{
float v = 70.0f;
gauge<float *> g(&v);
REQUIRE(g.get() == 70);
v = 500.017f;
REQUIRE_THAT(g.get(), Catch::Matchers::WithinULP(500.017f, 1));
REQUIRE_THAT(g.snapshot().value(), Catch::Matchers::WithinULP(500.017f, 1));
float x = 0;
gauge<float *> h(&x);
REQUIRE((g = h).get() == 0.0);
REQUIRE(g.snapshot() == 0.0);
}
TEST_CASE("Reference Gauge works", "[gauge]")
{
char v = 'A';
gauge<char &> g{v};
REQUIRE(g.get() == 'A');
v = 'z';
REQUIRE(g.get() == 'z');
REQUIRE(g.snapshot() == 'z');
}