MCPcopy Create free account
hub / github.com/boostorg/histogram / main

Function main

test/weight_counter_test.cpp:16–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14using wcount = weight_counter<double>;
15
16int main() {
17 {
18 wcount w(1);
19 std::ostringstream os;
20 os << w;
21 BOOST_TEST_EQ(os.str(), std::string("weight_counter(1, 1)"));
22
23 BOOST_TEST_EQ(w, wcount(1));
24 BOOST_TEST_NE(w, wcount(0));
25 BOOST_TEST_EQ(1, w);
26 BOOST_TEST_EQ(w, 1);
27 BOOST_TEST_NE(2, w);
28 BOOST_TEST_NE(w, 2);
29
30 w += weight(2);
31 BOOST_TEST_EQ(w.value(), 3);
32 BOOST_TEST_EQ(w.variance(), 5);
33 BOOST_TEST_EQ(w, wcount(3, 5));
34 BOOST_TEST_NE(w, wcount(3));
35
36 w += wcount(1, 2);
37 BOOST_TEST_EQ(w.value(), 4);
38 BOOST_TEST_EQ(w.variance(), 7);
39 }
40
41 {
42 // consistency: a weighted counter increased by weight 1 multiplied
43 // by 2 must be the same as a weighted counter increased by weight 2
44 wcount u(0);
45 u += weight(1);
46 u *= 2;
47 BOOST_TEST_EQ(u, wcount(2, 4));
48
49 wcount v(0);
50 v += weight(2);
51 BOOST_TEST_EQ(u, v);
52 }
53
54 {
55 // consistency : a weight counter increased by a real number x
56 // is the same was adding x times weight(1)
57 wcount x(0);
58 x += 2;
59 BOOST_TEST_EQ(x, wcount(2, 2));
60 }
61
62 {
63 // automatic conversion to RealType
64 wcount x(1, 2);
65 BOOST_TEST_NE(x, 1);
66 BOOST_TEST_EQ(static_cast<double>(x), 1);
67 }
68
69 return boost::report_errors();
70}

Callers

nothing calls this directly

Calls 3

weightFunction · 0.85
valueMethod · 0.45
varianceMethod · 0.45

Tested by

no test coverage detected