ProteoWizard
Main Page
Namespaces
Classes
Files
File List
File Members
pwiz
utility
misc
almost_equal_test.cpp
Go to the documentation of this file.
1
//
2
// $Id: almost_equal_test.cpp 4129 2012-11-20 00:05:37Z 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,
const
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
Generated on Mon Nov 26 2012 18:05:49 for ProteoWizard by
1.8.1.1