DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
testIntegerSequenceAlgorithms.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: testIntegerSequenceAlgorithms.hpp
5// Author: crdrisko
6// Date: 01/23/2021-08:09:51
7// Description: Provides ~100% unit test coverage over all std::integer_sequence<> algorithms
8
9#ifndef DRYCHEM_COMMON_UTILITIES_LIBS_META_TESTS_TESTTYPES_TESTINTEGERSEQUENCEALGORITHMS_HPP
10#define DRYCHEM_COMMON_UTILITIES_LIBS_META_TESTS_TESTTYPES_TESTINTEGERSEQUENCEALGORITHMS_HPP
11
12#include <cstddef>
13#include <type_traits>
14#include <utility>
15
16#include <common-utils/meta.hpp>
17#include <gtest/gtest.h>
18
19GTEST_TEST(testIntegerSequenceAlgorithms, theFrontListAlgorithmReturnsTheFirstElementOfAnIntegerSequence)
20{
21 using ExpectedResult = std::integral_constant<std::size_t, 5>;
22 using ActualResultSimplified = DryChem::front_list_t<std::index_sequence<5, 10, 15, 20, 25>>;
23 using ActualResultExplicit = typename DryChem::front_list<std::index_sequence<5, 10, 15, 20, 25>>::type;
24
25 static_assert((ExpectedResult {} == ActualResultSimplified {}),
26 "front_list_t did not return the first element of the index_sequence.");
27
28 static_assert((ExpectedResult {} == ActualResultExplicit {}),
29 "front_list did not return the first element of the index_sequence.");
30}
31
32GTEST_TEST(testIntegerSequenceAlgorithms, theIsEmptyAlgorithmChecksIfAnIntegerSequenceIsEmpty)
33{
34 using EmptyList = std::index_sequence<>;
35 using NonEmptyList = std::index_sequence<5, 10, 15, 20, 25>;
36
37 static_assert((!DryChem::is_empty_list_v<NonEmptyList>), "is_empty_list_v was not false on a non-empty list.");
38 static_assert((!DryChem::is_empty_list<NonEmptyList>::value), "is_empty_list was not false on a non-empty list.");
39
40 static_assert((DryChem::is_empty_list_v<EmptyList>), "is_empty_list_v was not true on an empty list.");
41 static_assert((DryChem::is_empty_list<EmptyList>::value), "is_empty_list was not true on an empty list.");
42}
43
44GTEST_TEST(testIntegerSequenceAlgorithms, thePopFrontAlgorithmRemovesAnElementFromTheFrontOfAnIntegerSequence)
45{
46 using ExpectedResult = std::index_sequence<10, 15, 20, 25>;
47 using ActualResultSimplified = DryChem::pop_front_list_t<std::index_sequence<5, 10, 15, 20, 25>>;
48 using ActualResultExplicit = typename DryChem::pop_front_list<std::index_sequence<5, 10, 15, 20, 25>>::type;
49
50 static_assert((std::is_same_v<ExpectedResult, ActualResultSimplified>),
51 "pop_front_list_t did not remove the first element of the index_sequence.");
52
53 static_assert((std::is_same_v<ExpectedResult, ActualResultExplicit>),
54 "pop_front_list did not remove the first element of the index_sequence.");
55}
56
57GTEST_TEST(testIntegerSequenceAlgorithms, thePushBackAlgorithmAddsANewElementToTheBackOfAnIntegerSequence)
58{
59 using CT30 = std::integral_constant<std::size_t, 30>;
60 using ExpectedResult = std::index_sequence<5, 10, 15, 20, 25, 30>;
61 using ActualResultSimplified = DryChem::push_back_list_t<std::index_sequence<5, 10, 15, 20, 25>, CT30>;
62 using ActualResultExplicit = typename DryChem::push_back_list<std::index_sequence<5, 10, 15, 20, 25>, CT30>::type;
63
64 static_assert((std::is_same_v<ExpectedResult, ActualResultSimplified>),
65 "push_back_list_t did not add a new element to the back of the index_sequence.");
66
67 static_assert((std::is_same_v<ExpectedResult, ActualResultExplicit>),
68 "push_back_list did not add a new element to the back of the index_sequence.");
69}
70
71GTEST_TEST(testIntegerSequenceAlgorithms, thePushFrontAlgorithmAddsANewElementToTheFrontOfAnIntegerSequence)
72{
73 using CT0 = std::integral_constant<std::size_t, 0>;
74 using ExpectedResult = std::index_sequence<0, 5, 10, 15, 20, 25>;
75 using ActualResultSimplified = DryChem::push_front_list_t<std::index_sequence<5, 10, 15, 20, 25>, CT0>;
76 using ActualResultExplicit = typename DryChem::push_front_list<std::index_sequence<5, 10, 15, 20, 25>, CT0>::type;
77
78 static_assert((std::is_same_v<ExpectedResult, ActualResultSimplified>),
79 "push_front_list_t did not add a new element to the front of the index_sequence.");
80
81 static_assert((std::is_same_v<ExpectedResult, ActualResultExplicit>),
82 "push_front_list did not add a new element to the front of the index_sequence.");
83}
84
85GTEST_TEST(testIntegerSequenceAlgorithms, theReverseAlgorithmReversesTheSuppliedIntegerSequence)
86{
87 using ExpectedResult = std::index_sequence<25, 20, 15, 10, 5>;
88 using ActualResultSimplified = DryChem::reverse_list_t<std::index_sequence<5, 10, 15, 20, 25>>;
89 using ActualResultExplicit = typename DryChem::reverse_list<std::index_sequence<5, 10, 15, 20, 25>>::type;
90
91 static_assert(
92 (std::is_same_v<ExpectedResult, ActualResultSimplified>), "reverse_list_t did not reverse the index_sequence.");
93
94 static_assert(
95 (std::is_same_v<ExpectedResult, ActualResultExplicit>), "reverse_list did not reverse the index_sequence.");
96}
97
98#endif
GTEST_TEST(testIntegerSequenceAlgorithms, theFrontListAlgorithmReturnsTheFirstElementOfAnIntegerSequence)
Definition testIntegerSequenceAlgorithms.hpp:19