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

Go to the source code of this file.

Functions

 TEST (TestSearch, MaxDistances)
 

Function Documentation

TEST ( TestSearch  ,
MaxDistances   
)

Definition at line 41 of file TestMaxDistance.cxx.

42 {
43  // Should return <4,9> (largest benefice of 6)
44  {
45  Container marketPrices(RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(int));
46  const auto maxBeneficeIndexes = MaxDistance<IT>(marketPrices.begin(), marketPrices.end());
47  EXPECT_EQ(4, maxBeneficeIndexes.first);
48  EXPECT_EQ(9, maxBeneficeIndexes.second);
49  }
50 
51  // Should return <0, idxEnd> on sorted array
52  {
53  Container sortedArray(SortedArrayInt, SortedArrayInt + sizeof(SortedArrayInt) / sizeof(int));
54  const auto indexes = MaxDistance<IT>(sortedArray.begin(), sortedArray.end());
55  EXPECT_EQ(0, indexes.first);
56  EXPECT_EQ(static_cast<int>(sortedArray.size()) - 1, indexes.second);
57  }
58 
59  // Should return <-1,-1> on insufficient array
60  {
61  Container insufficientArray = Container(1, 2);
62  const auto indexes = MaxDistance<IT>(insufficientArray.begin(), insufficientArray.end());
63  EXPECT_EQ(-1, indexes.first);
64  EXPECT_EQ(-1, indexes.second);
65  }
66 
67  // Should return <0,1> on array containing only two elements
68  {
69  Container twoElementArray = Container(2, 2);
70  const auto indexes = MaxDistance<IT>(twoElementArray.begin(), twoElementArray.end());
71  EXPECT_EQ(0, indexes.first);
72  EXPECT_EQ(1, indexes.second);
73  }
74 
75  // Should return <0,1> on array containing the same value
76  {
77  Container sameElementArray = Container(10, 2);
78  const auto indexes = MaxDistance<IT>(sameElementArray.begin(), sameElementArray.end());
79  EXPECT_EQ(0, indexes.first);
80  EXPECT_EQ(1, indexes.second);
81  }
82 
83  // String - should return <1,6> as 'a', 'z' are the most distanced letter
84  {
85  const auto indexes =
86  MaxDistance<std::string::const_iterator, std::minus<char>>(RandomStr.begin(), RandomStr.end());
87  EXPECT_EQ(1, indexes.first);
88  EXPECT_EQ(6, indexes.second);
89  }
90 }