1 // Copyright (C) 2019,2021 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
9 #include <util/doubles.h>
10 
11 #include <gtest/gtest.h>
12 
13 using namespace std;
14 using namespace isc;
15 using namespace isc::util;
16 
17 namespace {
18 
19 // Exercises isc::util::areDoublesEquivalent().
TEST(Doubles,areDoublesEquivalent)20 TEST(Doubles, areDoublesEquivalent) {
21     std::vector<uint8_t> data;
22 
23     // Default tolerance is 0.000001
24     EXPECT_TRUE(areDoublesEquivalent( 1.0000000, 1.0000005));
25     EXPECT_FALSE(areDoublesEquivalent(1.0000000, 1.000005));
26 
27     // Check custom tolerance.
28     EXPECT_TRUE(areDoublesEquivalent( 1.000, 1.005, 0.01));
29     EXPECT_FALSE(areDoublesEquivalent(1.000, 1.005, 0.001));
30 }
31 
32 }
33