ProteoWizard
pwiz
utility
misc
almost_equal_test.cpp
Go to the documentation of this file.
1
//
2
// $Id: almost_equal_test.cpp 6141 2014-05-05 21:03:47Z chambm $
3
//
4
//
5
// Original author: Darren Kessner <darren@proteowizard.org>
6
//
7
// Copyright 2009 Center for Applied Molecular Medicine
8
// University of Southern California, Los Angeles, California
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License");
11
// you may not use this file except in compliance with the License.
12
// You may obtain a copy of the License at
13
//
14
// http://www.apache.org/licenses/LICENSE-2.0
15
//
16
// Unless required by applicable law or agreed to in writing, software
17
// distributed under the License is distributed on an "AS IS" BASIS,
18
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
// See the License for the specific language governing permissions and
20
// limitations under the License.
21
//
22
23
24
#include "
Std.hpp
"
25
#include "
almost_equal.hpp
"
26
#include "
pwiz/utility/misc/unit.hpp
"
27
28
29
using namespace
pwiz::util
;
30
31
32
void
test_default_float
()
33
{
34
float
a = 2.0f;
35
a +=
numeric_limits<float>::epsilon
();
36
a *= 10.0f;
37
unit_assert
(
almost_equal
(a, 20.0f));
38
}
39
40
41
void
test_default_double
()
42
{
43
double
a = 2.0;
44
a +=
numeric_limits<double>::epsilon
();
45
a *= 10.0;
46
unit_assert
(
almost_equal
(a, 20.0));
47
}
48
49
50
void
test_multiplier
()
51
{
52
float
a = 1.0f;
53
a +=
numeric_limits<float>::epsilon
() * 2;
54
a *= 10.0f;
55
unit_assert
(!
almost_equal
(a, 10.0f));
56
unit_assert
(
almost_equal
(a, 10.0f, 2));
57
}
58
59
60
void
test
()
61
{
62
test_default_float
();
63
test_default_double
();
64
test_multiplier
();
65
}
66
67
68
int
main
(
int
argc,
char
* argv[])
69
{
70
TEST_PROLOG
(argc, argv)
71
72
try
73
{
74
test
();
75
}
76
catch
(exception& e)
77
{
78
TEST_FAILED
(e.what())
79
}
80
catch
(...)
81
{
82
TEST_FAILED
(
"Caught unknown exception."
)
83
}
84
85
TEST_EPILOG
86
}
87
88
almost_equal.hpp
epsilon
const double epsilon
Definition:
DiffTest.cpp:41
TEST_EPILOG
#define TEST_EPILOG
Definition:
unit.hpp:182
pwiz::util::almost_equal
bool almost_equal(float_type a, float_type b, int multiplier=1)
Definition:
almost_equal.hpp:37
Std.hpp
test_multiplier
void test_multiplier()
Definition:
almost_equal_test.cpp:50
unit.hpp
pwiz::util
Definition:
almost_equal.hpp:33
test
void test()
Definition:
almost_equal_test.cpp:60
test_default_float
void test_default_float()
Definition:
almost_equal_test.cpp:32
test_default_double
void test_default_double()
Definition:
almost_equal_test.cpp:41
TEST_FAILED
#define TEST_FAILED(x)
Definition:
unit.hpp:176
main
int main(int argc, char *argv[])
Definition:
almost_equal_test.cpp:68
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition:
unit.hpp:174
unit_assert
#define unit_assert(x)
Definition:
unit.hpp:85
Generated by
1.8.12