Bin search
This commit is contained in:
@@ -6,22 +6,28 @@ TEST(Problem34, Case1) {
|
||||
vector<int> nums{5, 7, 7, 8, 8, 10};
|
||||
int target{8};
|
||||
vector<int> o{3, 4};
|
||||
Solution solution;
|
||||
EXPECT_EQ(solution.searchRange(nums, target), o);
|
||||
Solution1 solution1;
|
||||
Solution2 solution2;
|
||||
EXPECT_EQ(solution1.searchRange(nums, target), o);
|
||||
EXPECT_EQ(solution2.searchRange(nums, target), o);
|
||||
}
|
||||
|
||||
TEST(Problem34, Case2) {
|
||||
vector<int> nums{5, 7, 7, 8, 8, 10};
|
||||
int target{6};
|
||||
vector<int> o{-1, -1};
|
||||
Solution solution;
|
||||
EXPECT_EQ(solution.searchRange(nums, target), o);
|
||||
Solution1 solution1;
|
||||
Solution2 solution2;
|
||||
EXPECT_EQ(solution1.searchRange(nums, target), o);
|
||||
EXPECT_EQ(solution2.searchRange(nums, target), o);
|
||||
}
|
||||
|
||||
TEST(Problem34, Case3) {
|
||||
vector<int> nums{};
|
||||
int target{0};
|
||||
vector<int> o{-1, -1};
|
||||
Solution solution;
|
||||
EXPECT_EQ(solution.searchRange(nums, target), o);
|
||||
Solution1 solution1;
|
||||
Solution2 solution2;
|
||||
EXPECT_EQ(solution1.searchRange(nums, target), o);
|
||||
EXPECT_EQ(solution2.searchRange(nums, target), o);
|
||||
}
|
||||
|
@@ -6,22 +6,28 @@ TEST(Problem35, Case1) {
|
||||
vector<int> nums{1, 3, 5, 6};
|
||||
int target{5};
|
||||
int o{2};
|
||||
Solution solution;
|
||||
EXPECT_EQ(solution.searchInsert(nums, target), o);
|
||||
Solution1 solution1;
|
||||
Solution2 solution2;
|
||||
EXPECT_EQ(solution1.searchInsert(nums, target), o);
|
||||
EXPECT_EQ(solution2.searchInsert(nums, target), o);
|
||||
}
|
||||
|
||||
TEST(Problem35, Case2) {
|
||||
vector<int> nums{1, 3, 5, 6};
|
||||
int target{2};
|
||||
int o{1};
|
||||
Solution solution;
|
||||
EXPECT_EQ(solution.searchInsert(nums, target), o);
|
||||
Solution1 solution1;
|
||||
Solution2 solution2;
|
||||
EXPECT_EQ(solution1.searchInsert(nums, target), o);
|
||||
EXPECT_EQ(solution2.searchInsert(nums, target), o);
|
||||
}
|
||||
|
||||
TEST(Problem35, Case3) {
|
||||
vector<int> nums{1, 3, 5, 6};
|
||||
int target{7};
|
||||
int o{4};
|
||||
Solution solution;
|
||||
EXPECT_EQ(solution.searchInsert(nums, target), o);
|
||||
Solution1 solution1;
|
||||
Solution2 solution2;
|
||||
EXPECT_EQ(solution1.searchInsert(nums, target), o);
|
||||
EXPECT_EQ(solution2.searchInsert(nums, target), o);
|
||||
}
|
||||
|
23
tests/s0704_binary_search.cpp
Normal file
23
tests/s0704_binary_search.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "s0704_binary_search.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Problem704, Case1) {
|
||||
vector<int> nums{-1, 0, 3, 5, 9, 12};
|
||||
int target{9};
|
||||
int o{4};
|
||||
Solution1 solution1;
|
||||
Solution2 solution2;
|
||||
EXPECT_EQ(solution1.binSearch(nums, target), o);
|
||||
EXPECT_EQ(solution2.binSearch(nums, target), o);
|
||||
}
|
||||
|
||||
TEST(Problem704, Case2) {
|
||||
vector<int> nums{-1, 0, 3, 5, 9, 12};
|
||||
int target{2};
|
||||
int o{-1};
|
||||
Solution1 solution1;
|
||||
Solution2 solution2;
|
||||
EXPECT_EQ(solution1.binSearch(nums, target), o);
|
||||
EXPECT_EQ(solution2.binSearch(nums, target), o);
|
||||
}
|
Reference in New Issue
Block a user