source: branches/profile/UNIT_TESTER/test_helpers.h

Last change on this file was 7423, checked in by westram, 13 years ago

merged from dev [7320] [7418] [7419] [7420]

  • BasePosition
    • uses int instead of size_t
    • allow empty sequences (gap-only)
    • allow to index just a part of a sequence
    • use new class CharPredicate to initialize custom gaps
  • moved safeCharIndex() to dupstr.h
  • unit tests
    • collectIntFunResults (allowed range)
    • slow test
File size: 1.8 KB
Line 
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
19template<typename FUN>
20inline 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}
26template<typename FUN>
27inline 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
36template<typename FUN>
37inline 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
Note: See TracBrowser for help on using the repository browser.