TestMaxSubSequence.cxx File Reference
#include <gtest/gtest.h>
#include <max_sub_sequence.hxx>
#include <functional>
Include dependency graph for TestMaxSubSequence.cxx:

Go to the source code of this file.

Functions

 TEST (TestSearch, MaxSubSequence)
 

Function Documentation

TEST ( TestSearch  ,
MaxSubSequence   
)

Definition at line 42 of file TestMaxSubSequence.cxx.

43 {
44  // Should return <5,9> (maximal sum of 17)
45  {
46  Container kMarketPrices(RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(int));
47  const auto kMaxBeneficeIndexes = MaxSubSequence<IT>(kMarketPrices.begin(), kMarketPrices.end());
48  EXPECT_EQ(5, kMaxBeneficeIndexes.first);
49  EXPECT_EQ(9, kMaxBeneficeIndexes.second);
50  }
51 
52  // Should return <FirstPositiveIdx, idxEnd> on sorted array
53  {
54  Container kSortedArray(SortedArrayInt, SortedArrayInt + sizeof(SortedArrayInt) / sizeof(int));
55  const auto kIndexes = MaxSubSequence<IT>(kSortedArray.begin(), kSortedArray.end());
56  EXPECT_EQ(2, kIndexes.first);
57  EXPECT_EQ(static_cast<int>(kSortedArray.size()) - 1, kIndexes.second);
58  }
59 
60  // Should return <-1,-1> on insufficient array
61  {
62  Container insufficientArray = Container(1, 2);
63  const auto kIndexes = MaxSubSequence<IT>(insufficientArray.begin(), insufficientArray.end());
64  EXPECT_EQ(-1, kIndexes.first);
65  EXPECT_EQ(-1, kIndexes.second);
66  }
67 
68  // Should return <0,1> on array containing only two positive elements
69  {
70  Container twoElementArray = Container(2, 2);
71  const auto kIndexes = MaxSubSequence<IT>(twoElementArray.begin(), twoElementArray.end());
72  EXPECT_EQ(0, kIndexes.first);
73  EXPECT_EQ(1, kIndexes.second);
74  }
75 
76  // Should return <0, idxEnd> on array containing the same positive value
77  {
78  const int kSize = 10;
79  Container sameElementArray = Container(kSize, 2);
80  const auto indexes = MaxSubSequence<IT>(sameElementArray.begin(), sameElementArray.end());
81  EXPECT_EQ(0, indexes.first);
82  EXPECT_EQ(kSize - 1, indexes.second);
83  }
84 }