DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
testTupleAlgorithms.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: testTupleAlgorithms.hpp
5// Author: crdrisko
6// Date: 01/06/2021-10:57:07
7// Description: Provides ~100% unit test coverage over all tuple algorithms
8
9#ifndef DRYCHEM_COMMON_UTILITIES_LIBS_META_TESTS_TESTTYPES_TESTTUPLEALGORITHMS_HPP
10#define DRYCHEM_COMMON_UTILITIES_LIBS_META_TESTS_TESTTYPES_TESTTUPLEALGORITHMS_HPP
11
12#include <iostream>
13#include <string>
14#include <tuple>
15#include <utility>
16
17#include <common-utils/meta.hpp>
18#include <gtest/gtest.h>
19
20GTEST_TEST(testTupleAlgorithms, theFrontAlgorithmReturnsTheFirstElementOfATuple)
21{
22 std::tuple tuple {std::string {"Hello, World!"}, 12.3, 6, std::string {"A string"}, true};
23
24 auto front = DryChem::front(tuple);
25
26 ASSERT_EQ(front, std::string {"Hello, World!"});
27}
28
29GTEST_TEST(testTupleAlgorithms, theIsEmptyAlgorithmChecksIfATupleIsEmpty)
30{
31 std::tuple tuple {std::string {"Hello, World!"}, 12.3, 6, std::string {"A string"}, true};
32 std::tuple emptyTuple {};
33
34 ASSERT_TRUE(DryChem::is_empty(emptyTuple));
35 ASSERT_FALSE(DryChem::is_empty(tuple));
36}
37
38GTEST_TEST(testTupleAlgorithms, thePopFrontAlgorithmRemovesAnElementFromTheFrontOfATuple)
39{
40 std::tuple tuple {std::string {"Hello, World!"}, 12.3, 6, std::string {"A string"}, true};
41
42 auto newTuple = DryChem::pop_front(tuple);
43
44 std::tuple expectedTuple {12.3, 6, std::string {"A string"}, true};
45
46 ASSERT_EQ(newTuple, expectedTuple);
47}
48
49GTEST_TEST(testTupleAlgorithms, thePushBackAlgorithmAddsANewElementToTheBackOfATuple)
50{
51 std::tuple tuple {std::string {"Hello, World!"}, 12.3, 6, std::string {"A string"}, true};
52
53 auto newTuple = DryChem::push_back(tuple, 1.267e-4l);
54
55 std::tuple expectedTuple {std::string {"Hello, World!"}, 12.3, 6, std::string {"A string"}, true, 1.267e-4l};
56
57 ASSERT_EQ(newTuple, expectedTuple);
58}
59
60GTEST_TEST(testTupleAlgorithms, thePushFrontAlgorithmAddsANewElementToTheFrontOfATuple)
61{
62 std::tuple tuple {std::string {"Hello, World!"}, 12.3, 6, std::string {"A string"}, true};
63
64 auto newTuple = DryChem::push_front(tuple, 1.267e-4l);
65
66 std::tuple expectedTuple {1.267e-4l, std::string {"Hello, World!"}, 12.3, 6, std::string {"A string"}, true};
67
68 ASSERT_EQ(newTuple, expectedTuple);
69}
70
71GTEST_TEST(testTupleAlgorithms, theApplyNAlgorithmAppliesAFunctionToTheFirstNElementsOfATuple)
72{
73 testing::internal::CaptureStdout();
74
75 std::tuple tuple {std::string {"Hello, World!"}, 12.3, 6, std::string {"A string"}, true};
76
77 DryChem::apply_n<2>([&](auto... elem) { ((std::cout << elem << std::endl), ...); }, tuple);
78
79 std::string output = testing::internal::GetCapturedStdout();
80 ASSERT_EQ(output, "Hello, World!\n12.3\n");
81}
82
83GTEST_TEST(testTupleAlgorithms, theReverseAlgorithmReversesTheSuppliedTuple)
84{
85 std::tuple tuple {std::string {"Hello, World!"}, 12.3, 6, std::string {"A string"}, true};
86
87 auto newTuple = DryChem::reverse(tuple);
88
89 std::tuple expectedTuple {true, std::string {"A string"}, 6, 12.3, std::string {"Hello, World!"}};
90
91 ASSERT_EQ(newTuple, expectedTuple);
92}
93
94GTEST_TEST(testTupleAlgorithms, theSelectAlgorithmShufflesATupleBasedOnTheOrderingOfAnIndexList)
95{
96 std::tuple tuple {std::string {"Hello, World!"}, 12.3, 6, std::string {"A string"}, true};
97
98 auto newTuple = DryChem::select(tuple, std::index_sequence<1, 4, 0, 3> {});
99
100 std::tuple expectedTuple {12.3, true, std::string {"Hello, World!"}, std::string {"A string"}};
101
102 ASSERT_EQ(newTuple, expectedTuple);
103}
104
105#endif
GTEST_TEST(testTupleAlgorithms, theFrontAlgorithmReturnsTheFirstElementOfATuple)
Definition testTupleAlgorithms.hpp:20