1 | // ============================================================= // |
---|
2 | // // |
---|
3 | // File : test_helpers.h // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in March 2011 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // ============================================================= // |
---|
11 | |
---|
12 | #ifndef TEST_HELPERS_H |
---|
13 | #define TEST_HELPERS_H |
---|
14 | |
---|
15 | #ifndef ARB_STRBUF_H |
---|
16 | #include <arb_strbuf.h> |
---|
17 | #endif |
---|
18 | |
---|
19 | template<typename FUN> |
---|
20 | inline void streamIntFunResults(GBS_strstruct& out, FUN fun, int start, int end, int width) { |
---|
21 | for (int i = start; i <= end; ++i) { |
---|
22 | int res = fun(i); |
---|
23 | out.nprintf(20, "%*i", width, res); |
---|
24 | } |
---|
25 | } |
---|
26 | template<typename FUN> |
---|
27 | inline void streamIntFunResultsInBrackets(GBS_strstruct& out, FUN fun, int start, int end, int width) { |
---|
28 | for (int i = start; i <= end; ++i) { |
---|
29 | int res = fun(i); |
---|
30 | char buffer[30]; |
---|
31 | sprintf(buffer, "[%i]", res); |
---|
32 | out.nprintf(30, "%*s", width+2, buffer); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | template<typename FUN> |
---|
37 | inline char *collectIntFunResults(FUN fun, int start, int end, int width, int try_underflow, int try_overflow) { |
---|
38 | GBS_strstruct out(1000); |
---|
39 | if (try_underflow) streamIntFunResultsInBrackets(out, fun, start-try_underflow, start-1, width); |
---|
40 | streamIntFunResults(out, fun, start, end, width); |
---|
41 | if (try_overflow) streamIntFunResultsInBrackets(out, fun, end+1, end+try_overflow, width); |
---|
42 | return out.release(); |
---|
43 | } |
---|
44 | |
---|
45 | #else |
---|
46 | #error test_helpers.h included twice |
---|
47 | #endif // TEST_HELPERS_H |
---|