Skip to content

Commit 2b8916b

Browse files
committed
test_accumulated(): Restructure this.
To make it clearer and to keep the small tests more self-contained and separate.
1 parent 931d226 commit 2b8916b

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

tests/test_accumulated.cc

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace
1717
{
18+
19+
TestUtilities* util = nullptr;
1820
std::ostringstream result_stream;
1921

2022
struct arithmetic_mean_accumulator
@@ -69,33 +71,27 @@ struct A : public sigc::trackable
6971
}
7072
};
7173

72-
} // end anonymous namespace
73-
74-
int main(int argc, char* argv[])
74+
void test_empty_signal()
7575
{
76-
auto util = TestUtilities::get_instance();
77-
78-
if (!util->check_command_args(argc, argv))
79-
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
80-
81-
sigc::signal<int,int>::accumulated<arithmetic_mean_accumulator> sig;
82-
sigc::signal<int,int>::accumulated<vector_accumulator<int> > sig_vec;
76+
sigc::signal<int,int>::accumulated<arithmetic_mean_accumulator> sig;
77+
sigc::signal<int,int>::accumulated<vector_accumulator<int> > sig_vec;
8378

8479
result_stream << "Result (empty slot list): " << sig(0);
8580
util->check_result(result_stream, "Result (empty slot list): -1");
8681
result_stream << "Vector result (empty slot list): "
8782
<< (sig_vec(0).empty() ? "empty" : "not empty");
8883
util->check_result(result_stream, "Vector result (empty slot list): empty");
84+
}
85+
86+
void test_mean()
87+
{
88+
sigc::signal<int,int>::accumulated<arithmetic_mean_accumulator> sig;
8989

9090
A a;
9191
sig.connect(sigc::ptr_fun1(&foo));
9292
sig.connect(sigc::mem_fun1(a, &A::foo));
9393
sig.connect(sigc::ptr_fun1(&bar));
9494

95-
sig_vec.connect(sigc::ptr_fun1(&foo));
96-
sig_vec.connect(sigc::mem_fun1(a, &A::foo));
97-
sig_vec.connect(sigc::ptr_fun1(&bar));
98-
9995
double dres = sig(1);
10096
result_stream << "Mean accumulator: Result (i=1): "
10197
<< std::fixed << std::setprecision(3) << dres;
@@ -107,7 +103,17 @@ int main(int argc, char* argv[])
107103
<< std::fixed << std::setprecision(3) << dres;
108104
util->check_result(result_stream,
109105
"foo: 34, A::foo: 206, bar: 52, Mean accumulator: Plain Result (i=11): 97.333");
106+
}
110107

108+
void test_vector_accumulator()
109+
{
110+
sigc::signal<int,int>::accumulated<vector_accumulator<int> > sig_vec;
111+
112+
A a;
113+
sig_vec.connect(sigc::ptr_fun(&foo));
114+
sig_vec.connect(sigc::mem_fun(a, &A::foo));
115+
sig_vec.connect(sigc::ptr_fun(&bar));
116+
111117
auto res1 = sig_vec(1);
112118
result_stream << "Vector accumulator: Result (i=1): ";
113119
for (auto num : res1)
@@ -121,6 +127,20 @@ int main(int argc, char* argv[])
121127
result_stream << num << " ";
122128
util->check_result(result_stream,
123129
"foo: 10, A::foo: 46, bar: 12, Vector accumulator: Result (i=3): 10 46 12 ");
130+
}
131+
132+
} // end anonymous namespace
133+
134+
int main(int argc, char* argv[])
135+
{
136+
util = TestUtilities::get_instance();
137+
138+
if (!util->check_command_args(argc, argv))
139+
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
140+
141+
test_empty_signal();
142+
test_mean();
143+
test_vector_accumulator();
124144

125145
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
126146
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy