]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (C) Copyright Gennadiy Rozental 2001. |
2 | // Distributed under the Boost Software License, Version 1.0. | |
3 | // (See accompanying file LICENSE_1_0.txt or copy at | |
4 | // http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | // See http://www.boost.org/libs/test for the library home page. | |
7 | // | |
8 | // File : $RCSfile$ | |
9 | // | |
10 | // Version : $Revision: 74248 $ | |
11 | // | |
12 | // Description : FPC tools tolerance holder | |
13 | // *************************************************************************** | |
14 | ||
15 | #ifndef BOOST_TEST_TOOLS_FPC_TOLERANCE_HPP_121612GER | |
16 | #define BOOST_TEST_TOOLS_FPC_TOLERANCE_HPP_121612GER | |
17 | ||
18 | // Boost Test | |
19 | #include <boost/test/tree/decorator.hpp> | |
20 | #include <boost/test/tools/floating_point_comparison.hpp> | |
21 | ||
22 | #include <boost/test/detail/suppress_warnings.hpp> | |
23 | ||
24 | //____________________________________________________________________________// | |
25 | ||
26 | namespace boost { | |
27 | namespace test_tools { | |
28 | ||
29 | namespace fpc = math::fpc; | |
30 | ||
31 | // ************************************************************************** // | |
32 | // ************** floating point comparison tolerance ************** // | |
33 | // ************************************************************************** // | |
34 | ||
35 | template<typename FPT> | |
36 | inline FPT& | |
37 | fpc_tolerance() | |
38 | { | |
39 | static FPT s_value = 0; | |
40 | return s_value; | |
41 | } | |
42 | ||
43 | //____________________________________________________________________________// | |
44 | ||
45 | template<typename FPT> | |
46 | struct local_fpc_tolerance { | |
47 | local_fpc_tolerance( FPT fraction_tolerance ) : m_old_tolerance( fpc_tolerance<FPT>() ) | |
48 | { | |
49 | fpc_tolerance<FPT>() = fraction_tolerance; | |
50 | } | |
51 | ||
52 | ~local_fpc_tolerance() | |
53 | { | |
54 | if( m_old_tolerance != (FPT)-1 ) | |
55 | fpc_tolerance<FPT>() = m_old_tolerance; | |
56 | } | |
57 | ||
58 | private: | |
59 | // Data members | |
60 | FPT m_old_tolerance; | |
61 | }; | |
62 | ||
63 | //____________________________________________________________________________// | |
64 | ||
65 | } // namespace test_tools | |
66 | ||
67 | // ************************************************************************** // | |
68 | // ************** decorator::tolerance ************** // | |
69 | // ************************************************************************** // | |
70 | ||
71 | namespace unit_test { | |
72 | namespace decorator { | |
73 | ||
74 | template<typename FPT> | |
75 | inline fixture_t | |
76 | tolerance( FPT v ) | |
77 | { | |
78 | return fixture_t( test_unit_fixture_ptr( | |
79 | new unit_test::class_based_fixture<test_tools::local_fpc_tolerance<FPT>,FPT>( v ) ) ); | |
80 | } | |
81 | ||
82 | //____________________________________________________________________________// | |
83 | ||
84 | template<typename FPT> | |
85 | inline fixture_t | |
86 | tolerance( test_tools::fpc::percent_tolerance_t<FPT> v ) | |
87 | { | |
88 | return fixture_t( test_unit_fixture_ptr( | |
89 | new unit_test::class_based_fixture<test_tools::local_fpc_tolerance<FPT>,FPT>( boost::math::fpc::fpc_detail::fraction_tolerance<FPT>( v ) ) ) ); | |
90 | } | |
91 | ||
92 | //____________________________________________________________________________// | |
93 | ||
94 | } // namespace decorator | |
95 | ||
96 | using decorator::tolerance; | |
97 | ||
98 | } // namespace unit_test | |
99 | } // namespace boost | |
100 | ||
101 | #include <boost/test/detail/enable_warnings.hpp> | |
102 | ||
103 | #endif // BOOST_TEST_TOOLS_FPC_TOLERANCE_HPP_121612GER |