1 | #ifndef _theplu_yat_test_suite_ |
---|
2 | #define _theplu_yat_test_suite_ |
---|
3 | |
---|
4 | // $Id: Suite.h 1304 2008-05-14 20:11:57Z 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 | \return b |
---|
49 | */ |
---|
50 | bool add(bool b); |
---|
51 | |
---|
52 | /** |
---|
53 | \return In verbose mode std::cerr, else a ofstream to "/dev/null". |
---|
54 | */ |
---|
55 | std::ostream& err(void) const; |
---|
56 | |
---|
57 | /** |
---|
58 | \return true if \f$ |a-b| <= N * \epsilon * min(|a|,|b|) \f$ |
---|
59 | where \f$ \epsilon \f$ is std::numeric_limits<double>().epsilon() |
---|
60 | */ |
---|
61 | bool equal(double a, double b, unsigned long int N=1); |
---|
62 | |
---|
63 | /** |
---|
64 | \return true if \f$ |a-b| <= N * sqrt(\epsilon) * min(|a|,|b|) \f$ |
---|
65 | where \f$ \epsilon \f$ is std::numeric_limits<double>().epsilon() |
---|
66 | */ |
---|
67 | bool equal_sqrt(double a, double b, unsigned long int N=1); |
---|
68 | |
---|
69 | template<typename Iterator1, typename Iterator2> |
---|
70 | bool equal_range(Iterator1 first1, Iterator1 last1, Iterator2 first2, |
---|
71 | unsigned int N=1); |
---|
72 | |
---|
73 | /** |
---|
74 | \return true if test is ok |
---|
75 | */ |
---|
76 | bool ok(void) const; |
---|
77 | |
---|
78 | /** |
---|
79 | \return In verbose mode std::cout, else a ofstream to "/dev/null". |
---|
80 | */ |
---|
81 | std::ostream& out(void) const; |
---|
82 | |
---|
83 | /** |
---|
84 | In verbose mode a final message is sent to std::cout. |
---|
85 | |
---|
86 | If ok() is true: "Test is ok." otherwise |
---|
87 | "Test failed." |
---|
88 | |
---|
89 | \return 0 if ok. |
---|
90 | */ |
---|
91 | int return_value(void) const; |
---|
92 | |
---|
93 | private: |
---|
94 | bool verbose_; |
---|
95 | bool ok_; |
---|
96 | std::ofstream* dev_null_; |
---|
97 | |
---|
98 | }; |
---|
99 | |
---|
100 | /** |
---|
101 | \return absolute path to file |
---|
102 | \param local_path path relative to srcdir |
---|
103 | */ |
---|
104 | std::string filename(const std::string& local_path); |
---|
105 | |
---|
106 | template<typename Iterator1, typename Iterator2> |
---|
107 | bool Suite::equal_range(Iterator1 first1, Iterator1 last1, Iterator2 first2, |
---|
108 | unsigned int N) |
---|
109 | { |
---|
110 | while (first1!=last1){ |
---|
111 | if (!this->equal(*first1, *first2, N) ) { |
---|
112 | return false; |
---|
113 | } |
---|
114 | ++first1; |
---|
115 | ++first2; |
---|
116 | } |
---|
117 | return true; |
---|
118 | } |
---|
119 | |
---|
120 | }}} |
---|
121 | |
---|
122 | #endif |
---|