-
Notifications
You must be signed in to change notification settings - Fork 4
/
cleanup.cc
70 lines (61 loc) · 1.89 KB
/
cleanup.cc
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
#include <gtest/gtest.h>
#include "scientist.hh"
TEST(Cleanup, Cleanup)
{
bool published = false;
Scientist<int>::Science("test", [&](ExperimentInterface<int>& e)
{
e.Use([]() { return 42;});
e.Try([]() { return 1;});
e.Publish([&](const Observation<int>& o)
{
published = true;
ASSERT_FALSE(o.Success());
ASSERT_EQ(o.ControlResult(), 84);
ASSERT_EQ(o.CandidateResult(), 2);
});
e.Cleanup([](const int& value ) { return 2 * value; });
});
ASSERT_TRUE(published);
}
struct Data
{
int Field;
};
TEST(Cleanup, CleanupClass)
{
bool published = false;
Scientist<Data, int>::Science("test", [&](ExperimentInterface<Data, int>& e)
{
e.Use([]() { return Data { 42 };});
e.Try([]() { return Data { 1 };});
e.Publish([&](const Observation<int>& o)
{
published = true;
ASSERT_FALSE(o.Success());
ASSERT_EQ(o.ControlResult(), 42);
ASSERT_EQ(o.CandidateResult(), 1);
});
e.Cleanup([](const Data& d ) { return d.Field; });
e.Compare([](const Data& a, const Data& b) { return a.Field == b.Field;});
});
ASSERT_TRUE(published);
}
TEST(Cleanup, CleanupRequiredButMissingDoesNotCrash)
{
bool published = false;
Scientist<Data, int>::Science("test", [&](ExperimentInterface<Data, int>& e)
{
e.Use([]() { return Data { 42 };});
e.Try([]() { return Data { 1 };});
e.Publish([&](const Observation<int>& o)
{
published = true;
ASSERT_FALSE(o.Success());
ASSERT_EQ(o.ControlResult(), 0 /* default value for int */);
ASSERT_EQ(o.CandidateResult(), 0 /* default value for int */);
});
e.Compare([](const Data& a, const Data& b) { return a.Field == b.Field;});
});
ASSERT_TRUE(published);
}