ARB
test_helpers.h
Go to the documentation of this file.
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  GBS_strnprintf(out, 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  GBS_strnprintf(out, 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 = GBS_stropen(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 GBS_strclose(out);
43 }
44 
45 #else
46 #error test_helpers.h included twice
47 #endif // TEST_HELPERS_H
char * collectIntFunResults(FUN fun, int start, int end, int width, int try_underflow, int try_overflow)
Definition: test_helpers.h:37
void GBS_strnprintf(GBS_strstruct *strstr, long maxlen, const char *templat,...)
Definition: arb_strbuf.cxx:113
void streamIntFunResults(GBS_strstruct *out, FUN fun, int start, int end, int width)
Definition: test_helpers.h:20
char buffer[MESSAGE_BUFFERSIZE]
Definition: seq_search.cxx:34
static HelixNrInfo * start
GBS_strstruct * GBS_stropen(long init_size)
Definition: arb_strbuf.cxx:39
void streamIntFunResultsInBrackets(GBS_strstruct *out, FUN fun, int start, int end, int width)
Definition: test_helpers.h:27
char * GBS_strclose(GBS_strstruct *strstr)
Definition: arb_strbuf.cxx:69