-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-in-mountain-array-test.cpp
63 lines (52 loc) · 1.55 KB
/
find-in-mountain-array-test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (c) 2018 Christopher Friedt
*
* SPDX-License-Identifier: MIT
*/
#include <vector>
#include <gtest/gtest.h>
using namespace std;
class MountainArray {
public:
explicit MountainArray(const vector<int> &A) : nQueries(0), A(A) {}
int get(int index) {
if (nQueries == 100) {
throw runtime_error("no more guesses left :(");
}
nQueries++;
return A[index];
}
int length() { return int(A.size()); }
protected:
size_t nQueries;
const vector<int> A;
};
#include "find-in-mountain-array.cpp"
TEST(FindInMountainArray, Test_1_2_3_4_5_3_1__3) {
MountainArray mountainArr(vector<int>{{1, 2, 3, 4, 5, 3, 1}});
int target = 3;
int expected_int = 2;
int actual_int = Solution().findInMountainArray(target, mountainArr);
EXPECT_EQ(actual_int, expected_int);
}
TEST(FindInMountainArray, Test_0_1_2_4_2_1__3) {
MountainArray mountainArr(vector<int>{{0, 1, 2, 4, 2, 1}});
int target = 3;
int expected_int = -1;
int actual_int = Solution().findInMountainArray(target, mountainArr);
EXPECT_EQ(actual_int, expected_int);
}
TEST(FindInMountainArray, Test_0_5_3_1__1) {
MountainArray mountainArr(vector<int>{{0, 5, 3, 1}});
int target = 1;
int expected_int = 3;
int actual_int = Solution().findInMountainArray(target, mountainArr);
EXPECT_EQ(actual_int, expected_int);
}
TEST(FindInMountainArray, Test_0_1_0__1) {
MountainArray mountainArr(vector<int>{{0, 1, 0}});
int target = 1;
int expected_int = 1;
int actual_int = Solution().findInMountainArray(target, mountainArr);
EXPECT_EQ(actual_int, expected_int);
}