TestIsInterleaved.cxx
Go to the documentation of this file.
1 /*===========================================================================================================
2  *
3  * HUC - Hurna Core
4  *
5  * Copyright (c) Michael Jeulin-Lagarrigue
6  *
7  * Licensed under the MIT License, you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * https://github.com/Hurna/Hurna-Core/blob/master/LICENSE
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License is
13  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and limitations under the License.
15  *
16  * The above copyright notice and this permission notice shall be included in all copies or
17  * substantial portions of the Software.
18  *
19  *=========================================================================================================*/
20 #include <gtest/gtest.h>
21 #include <is_interleaved.hxx>
22 
23 using namespace huc::combinatory;
24 
25 #ifndef DOXYGEN_SKIP
26 namespace {
27  const int kSequenceAInt[] = {4, 3, 5}; // Simple random array of integers with negative values
28  const int kSequenceBInt[] = {-2, 3, 5, 4}; // Simple random array of integers with negative values
29  const int kSequenceCInt[] = {5, -2, 4, 3, 4, 5, 3}; // Interleave of Sequence A and Sequence B
30  const int kSequenceDInt[] = {-2, 3}; // Simple random array of integers with negative values
31  const std::string kSequenceAStr = "acegm"; // Random string
32  const std::string kSequenceBStr = "xacvgeze"; // Random string
33  const std::string kSequenceCStr = "axaemgccvgeze"; // Interleave of Sequence A and Sequence B
34 
35  typedef std::vector<int> Container;
36  typedef Container::value_type Value;
37  typedef Container::iterator IT;
38 }
39 #endif /* DOXYGEN_SKIP */
40 
41 // Test interleaves
42 TEST(TestIsInterleaved, Interleaved)
43 {
44  // Null interleave on empty sequences - empty interleave expected
45  {
46  Container empty = Container();
47  EXPECT_TRUE(IsInterleaved<IT>
48  (empty.begin(), empty.end(), empty.begin(), empty.end(), empty.begin(), empty.end()));
49  }
50 
51  // interleave with one empty sequence (first) - same sequence expected as interleave
52  {
53  Container sequenceA(kSequenceAInt, kSequenceAInt + sizeof(kSequenceAInt) / sizeof(Value));
54  EXPECT_TRUE(IsInterleaved<IT>(sequenceA.begin(), sequenceA.end(), sequenceA.end(),
55  sequenceA.end(), sequenceA.begin(), sequenceA.end()));
56  }
57 
58  // interleave with one empty sequence (second) - same sequence expected as interleave
59  {
60  Container sequenceA(kSequenceAInt, kSequenceAInt + sizeof(kSequenceAInt) / sizeof(Value));
61  EXPECT_TRUE(IsInterleaved<IT>(sequenceA.end(), sequenceA.end(), sequenceA.begin(),
62  sequenceA.end(), sequenceA.begin(), sequenceA.end()));
63  }
64 
65  // interleave with same sequence - same sequence cannot be interleave of both
66  {
67  Container sequenceA(kSequenceAInt, kSequenceAInt + sizeof(kSequenceAInt) / sizeof(Value));
68  EXPECT_FALSE(IsInterleaved<IT>(sequenceA.begin(), sequenceA.end(), sequenceA.begin(),
69  sequenceA.end(), sequenceA.begin(), sequenceA.end()));
70  }
71 
72  // Normal run with interleave
73  {
74  Container sequenceA(kSequenceAInt, kSequenceAInt + sizeof(kSequenceAInt) / sizeof(Value));
75  Container sequenceB(kSequenceBInt, kSequenceBInt + sizeof(kSequenceBInt) / sizeof(Value));
76  Container sequenceC(kSequenceCInt, kSequenceCInt + sizeof(kSequenceCInt) / sizeof(Value));
77  EXPECT_TRUE(IsInterleaved<IT>(sequenceA.begin(), sequenceA.end(), sequenceB.begin(),
78  sequenceB.end(), sequenceC.begin(), sequenceC.end()));
79  }
80 
81  // Normal run with interleave on strings
82  {
83  std::string aStr = kSequenceAStr;
84  std::string bStr = kSequenceBStr;
85  std::string cStr = kSequenceCStr;
86  EXPECT_TRUE(IsInterleaved<std::string::iterator>(aStr.begin(), aStr.end(), bStr.begin(),
87  bStr.end(), cStr.begin(), cStr.end()));
88  }
89 
90  // Run with extra letter on FullStr
91  {
92  std::string aStr = kSequenceAStr;
93  std::string bStr = kSequenceBStr;
94  std::string cStr = kSequenceCStr + 'a';
95  EXPECT_FALSE(IsInterleaved<std::string::iterator>(aStr.begin(), aStr.end(), bStr.begin(),
96  bStr.end(), cStr.begin(), cStr.end()));
97  }
98 }
TEST(TestIsInterleaved, Interleaved)