DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
testComparisonOperators.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2025 Cody R. Drisko. All rights reserved.
2// Licensed under the MIT License. See the LICENSE file in the project root for more information.
3//
4// Name: testComparisonOperators.hpp
5// Author: crdrisko
6// Date: 09/17/2020-09:42:58
7// Description: Provides ~100% unit test coverage over all comparison functions and traits
8
9#ifndef DRYCHEM_CPP_UNITS_TESTS_TESTOPERATORS_TESTCOMPARISONOPERATORS_HPP
10#define DRYCHEM_CPP_UNITS_TESTS_TESTOPERATORS_TESTCOMPARISONOPERATORS_HPP
11
12#include <type_traits>
13
14#include <gtest/gtest.h>
15
17
18using namespace CppUnits;
19using namespace CppUnits::Literals;
20
21GTEST_TEST(testComparisonOperators, overloadedComparsionOperatorsPerformComparisonsOnMagnitude)
22{
23 DimensionlessQuantity value1 = 1.0_;
24 DimensionlessQuantity value2 = 2.0_;
25 DimensionlessQuantity value3 = 1.0_;
26
27 ASSERT_TRUE(value1 == value3);
28 ASSERT_FALSE(value1 == value2);
29
30 ASSERT_TRUE(value1 < value2);
31 ASSERT_FALSE(value2 < value1);
32
33 // Length value4 = 2.0_m;
34 // ASSERT_TRUE(value2 == value4); // Error: no operator "==" matches these operands
35 // ASSERT_TRUE(value1 < value4); // Error: no operator "<" matches these operands
36}
37
38GTEST_TEST(testComparisonOperators, physicalQuantitiesInheritAndImplementAllComparisonOperators)
39{
40 DimensionlessQuantity value1 = 1.0_;
41 DimensionlessQuantity value2 = 2.0_;
42 DimensionlessQuantity value3 = 5.0_;
43 DimensionlessQuantity value4 = 1.0_;
44
45 ASSERT_TRUE(value3 != value2);
46 ASSERT_FALSE(value4 != value1);
47
48 ASSERT_TRUE(value1 <= value2);
49 ASSERT_FALSE(value2 <= value1);
50
51 ASSERT_TRUE(value3 > value2);
52 ASSERT_FALSE(value2 > value3);
53
54 ASSERT_TRUE(value3 >= value2);
55 ASSERT_FALSE(value2 >= value3);
56}
57
58GTEST_TEST(testComparisonOperators, physicalQuantitiesAreOnlyCompletelyComparableWithTheSameTypeOfPhysicalQuantity)
59{
60 ASSERT_TRUE((std::is_base_of_v<DryChem::CompletelyComparable<Length>, Length>));
61 ASSERT_FALSE((std::is_base_of_v<DryChem::CompletelyComparable<Length>, DimensionlessQuantity>));
62}
63
64#endif
GTEST_TEST(testComparisonOperators, overloadedComparsionOperatorsPerformComparisonsOnMagnitude)
Definition testComparisonOperators.hpp:21
Definition physicalQuantities.hpp:94
Definition basicMath.hpp:17
PhysicalQuantity< Dimensionality<> > DimensionlessQuantity
Definition physicalQuantities.hpp:22
PhysicalQuantity< Dimensionality< 1, 0, 0 > > Length
Definition physicalQuantities.hpp:37