1 | #ifndef _theplu_yat_test_suite_ |
---|
2 | #define _theplu_yat_test_suite_ |
---|
3 | |
---|
4 | // $Id: Suite.h 1247 2008-03-17 14:54:10Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2008 Peter Johansson |
---|
8 | |
---|
9 | This file is part of the yat library, http://trac.thep.lu.se/yat |
---|
10 | |
---|
11 | The yat library is free software; you can redistribute it and/or |
---|
12 | modify it under the terms of the GNU General Public License as |
---|
13 | published by the Free Software Foundation; either version 2 of the |
---|
14 | License, or (at your option) any later version. |
---|
15 | |
---|
16 | The yat library is distributed in the hope that it will be useful, |
---|
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
19 | General Public License for more details. |
---|
20 | |
---|
21 | You should have received a copy of the GNU General Public License |
---|
22 | along with this program; if not, write to the Free Software |
---|
23 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
24 | 02111-1307, USA. |
---|
25 | */ |
---|
26 | |
---|
27 | #include <fstream> |
---|
28 | |
---|
29 | namespace theplu { |
---|
30 | namespace yat { |
---|
31 | namespace test { |
---|
32 | |
---|
33 | /** |
---|
34 | \internal utility class for tests |
---|
35 | */ |
---|
36 | class Suite |
---|
37 | { |
---|
38 | public: |
---|
39 | Suite(int argc, char* argv[]); |
---|
40 | |
---|
41 | /** |
---|
42 | */ |
---|
43 | ~Suite(void); |
---|
44 | |
---|
45 | /** |
---|
46 | set ok to 'b && ok' |
---|
47 | */ |
---|
48 | void add(bool b); |
---|
49 | |
---|
50 | /** |
---|
51 | \return In verbose mode std::cerr, else a ofstream to "/dev/null". |
---|
52 | */ |
---|
53 | std::ostream& err(void) const; |
---|
54 | |
---|
55 | /** |
---|
56 | \return true if \f$ |a-b| <= N * \epsilon * min(|a|,|b|) \f$ |
---|
57 | where \f$ \epsilon \f$ is std::numeric_limits<double>().epsilon() |
---|
58 | */ |
---|
59 | bool equal(double a, double b, unsigned long int N=1); |
---|
60 | |
---|
61 | /** |
---|
62 | \return true if \f$ |a-b| <= N * sqrt(\epsilon) * min(|a|,|b|) \f$ |
---|
63 | where \f$ \epsilon \f$ is std::numeric_limits<double>().epsilon() |
---|
64 | */ |
---|
65 | bool equal_sqrt(double a, double b, unsigned long int N=1); |
---|
66 | |
---|
67 | template<typename Iterator1, typename Iterator2> |
---|
68 | bool equal_range(Iterator1 first1, Iterator1 last1, Iterator2 first2, |
---|
69 | unsigned int N=1); |
---|
70 | |
---|
71 | /** |
---|
72 | \return true if test is ok |
---|
73 | */ |
---|
74 | bool ok(void) const; |
---|
75 | |
---|
76 | /** |
---|
77 | \return In verbose mode std::cout, else a ofstream to "/dev/null". |
---|
78 | */ |
---|
79 | std::ostream& out(void) const; |
---|
80 | |
---|
81 | /** |
---|
82 | In verbose mode a final message is sent to std::cout. |
---|
83 | |
---|
84 | If ok() is true: "Test is ok." otherwise |
---|
85 | "Test failed." |
---|
86 | |
---|
87 | \return 0 if ok. |
---|
88 | */ |
---|
89 | int return_value(void) const; |
---|
90 | |
---|
91 | private: |
---|
92 | bool verbose_; |
---|
93 | bool ok_; |
---|
94 | std::ofstream* dev_null_; |
---|
95 | |
---|
96 | }; |
---|
97 | |
---|
98 | template<typename Iterator1, typename Iterator2> |
---|
99 | bool Suite::equal_range(Iterator1 first1, Iterator1 last1, Iterator2 first2, |
---|
100 | unsigned int N) |
---|
101 | { |
---|
102 | while (first1!=last1){ |
---|
103 | if (!this->equal(*first1, *first2, N) ) { |
---|
104 | return false; |
---|
105 | } |
---|
106 | ++first1; |
---|
107 | ++first2; |
---|
108 | } |
---|
109 | return true; |
---|
110 | } |
---|
111 | |
---|
112 | }}} |
---|
113 | |
---|
114 | #endif |
---|