OmniSciDB  04ee39c94c
ExperimentalTest.cpp
Go to the documentation of this file.
1 #include "../Shared/ConstExprLib.h"
2 #include "../Shared/ExperimentalTypeUtilities.h"
3 #include "TestHelpers.h"
4 
5 #include <gtest/gtest.h>
6 #include <exception>
7 
8 using namespace Experimental;
9 
11  ConstExprPair<int, int> default_construct1, default_construct2(1, 2);
12  if (!(default_construct1.first == 0 && default_construct1.second == 0)) {
13  throw std::runtime_error("Faulty construction");
14  }
15  default_construct1.swap(default_construct2);
16  if (!(default_construct1.first == 1 && default_construct1.second == 2)) {
17  throw std::runtime_error("Faulty swap");
18  }
19  ConstExprPair<int, int> component_construct1(1, 1), component_construct2(2, 2);
20  component_construct1 = component_construct2;
21  if (!(component_construct1.first == 2 && component_construct1.second == 2)) {
22  throw std::runtime_error("Faulty construction");
23  }
24  ConstExprPair<int, int> component_construct3(component_construct2);
25  if (!(component_construct3.first == 2 && component_construct3.second == 2)) {
26  throw std::runtime_error("Faulty component construction");
27  }
28 
29  return component_construct3;
30 }
31 
32 TEST(ExperimentalTest, ConstExprLib_Pair) {
33  // Verify run-time use
34  ConstExprPair<int, int> default_construct1, default_construct2(1, 2);
35  ASSERT_EQ(default_construct1.first, 0);
36  ASSERT_EQ(default_construct1.second, 0);
37 
38  default_construct1.swap(default_construct2);
39  ASSERT_EQ(default_construct1.first, 1);
40  ASSERT_EQ(default_construct1.second, 2);
41 
42  ConstExprPair<int, int> component_construct1(1, 1), component_construct2(2, 2);
43  component_construct1 = component_construct2;
44  ASSERT_EQ(component_construct1.first, 2);
45  ASSERT_EQ(component_construct1.second, 2);
46 
47  ConstExprPair<int, int> component_construct3(component_construct2);
48  ASSERT_EQ(component_construct3.first, 2);
49  ASSERT_EQ(component_construct3.second, 2);
50 
51  // Verify compile time use
52  constexpr auto compile_time_verify = yield_test_constexpr_pair();
53  ASSERT_EQ(compile_time_verify.first, 2);
54  ASSERT_EQ(compile_time_verify.second, 2);
55 }
56 
57 int main(int argc, char* argv[]) {
59  ::testing::InitGoogleTest(&argc, argv);
60 
61  int err{0};
62  try {
63  err = RUN_ALL_TESTS();
64  } catch (const std::exception& e) {
65  LOG(ERROR) << e.what();
66  }
67  return err;
68 }
#define LOG(tag)
Definition: Logger.h:182
constexpr ConstExprPair< int, int > yield_test_constexpr_pair()
void init_logger_stderr_only(int argc, char const *const *argv)
Definition: TestHelpers.h:194
TEST(ExperimentalTest, ConstExprLib_Pair)
int main(int argc, char *argv[])
constexpr void swap(ConstExprPair &other) noexcept
Definition: ConstExprLib.h:25