ProteoWizard
almost_equal_test.cpp
Go to the documentation of this file.
1//
2// $Id$
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"
27
28
29using namespace pwiz::util;
30
31
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
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
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
66
67
68int 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
86}
87
88
int main(int argc, char *argv[])
void test_multiplier()
void test_default_float()
void test()
void test_default_double()
bool almost_equal(float_type a, float_type b, int multiplier=1)
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175