Molassembler  2.0.1
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
LogicalOperatorTests.h
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_MOLASSEMBLER_TEMPLE_CONSTEXPR_LOGICAL_OPERATOR_TESTS_H
13 #define INCLUDE_MOLASSEMBLER_TEMPLE_CONSTEXPR_LOGICAL_OPERATOR_TESTS_H
14 
16 
17 #include <iostream>
18 
19 namespace Scine {
20 namespace Molassembler {
21 namespace Temple {
22 
24 template<typename T>
25 constexpr bool testLogicalOperators(const T& a, const T& b) {
26  return (
27  Math::XOR( // only one of the following three cases may be true at any time
28  a < b && b > a && a != b,
29  b < a && a > b && a != b,
30  !(a < b) && !(a > b) && a == b
31  ) && Math::XOR( // ensure == and != are correct
32  a == b,
33  a != b
34  )
35  );
36 }
37 
39 template<typename T>
40 constexpr bool testOperatorSmaller(const T& a, const T& b) {
41  return Math::XOR(
42  a < b,
43  b < a,
44  !(a < b) && !(b < a) // a != b expressed with < only
45  );
46 }
47 
48 namespace dynamic {
49 
51 template<typename T>
52 void explainLogicalOperatorFailures(const T& a, const T& b) {
53  if(
54  !Math::XOR(
55  a < b && b > a && a != b,
56  b < a && a > b && a != b,
57  !(a < b) && !(a > b) && a == b
58  )
59  ) {
60  std::cout << "operator < is inconsistent:\n" << std::boolalpha
61  << " a < b && b > a && a != b -> "
62  << (a < b) << " && " << (b > a) << " && " << (a != b) << " -> "
63  << (a < b && b > a && a != b) << "\n"
64  << " b < a && a > b && a != b -> "
65  << (b < a) << " && " << (a > b) << " && " << (a != b) << " -> "
66  << (b < a && a > b && a != b) << "\n"
67  << " !(a < b) && !(a > b) && a == b -> "
68  << !(a < b) << " && " << !(a > b) << " && " << (a == b) << " -> "
69  << (!(a < b) && !(a > b) && a == b) << "\n";
70  }
71 
72  if(
73  !Math::XOR(
74  a == b,
75  a != b
76  )
77  ) {
78  std::cout << "operator == is inconsistent:\n" << std::boolalpha
79  << " a == b -> " << (a == b) << "\n"
80  << " a != b -> " << (a != b) << "\n";
81  }
82 }
83 
84 } // namespace dynamic
85 } // namespace Temple
86 } // namespace Molassembler
87 } // namespace Scine
88 
89 #endif
constexpr math implementations
constexpr bool testLogicalOperators(const T &a, const T &b)
For any two types, check consistency of their logical operators.
Definition: LogicalOperatorTests.h:25
constexpr bool testOperatorSmaller(const T &a, const T &b)
Limited variant of testLogicalOperators.
Definition: LogicalOperatorTests.h:40