Skip to content

Commit

Permalink
refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
tangs committed Jul 8, 2024
1 parent a826aa8 commit 5af289d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/724/solution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ using namespace std;

class Solution {
public:
int pivotIndex(vector<int>&& nums) {
template<typename T>
int pivotIndex(T&& nums) {
const auto len = nums.size();
nums.push_back(0);

Expand Down
74 changes: 37 additions & 37 deletions tests/3303/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
cmake_minimum_required(VERSION 3.10)
project(dp_solution_pipeline)

set(CMAKE_CXX_STANDARD 17)

set(PROBLEM_NAME 3303)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

set(SRC_ROOT_PATH ${ROOT_PATH}/src)
set(SRC_PATH ${SRC_ROOT_PATH}/${PROBLEM_NAME})
set(TESTS_PATH ${ROOT_PATH}/tests/${PROBLEM_NAME})

include_directories(
${SRC_ROOT_PATH}
${SRC_PATH}
${TESTS_PATH}
)

# test.
enable_testing()

add_executable(
test_${PROBLEM_NAME}
${TESTS_PATH}/test.cc
)
target_link_libraries(test_${PROBLEM_NAME} GTest::gtest_main)


include(GoogleTest)
gtest_discover_tests(test_${PROBLEM_NAME})
#cmake_minimum_required(VERSION 3.10)
#project(dp_solution_pipeline)
#
#set(CMAKE_CXX_STANDARD 17)
#
#set(PROBLEM_NAME 3303)
#
#include(FetchContent)
#FetchContent_Declare(
# googletest
# URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
#)
#set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
#FetchContent_MakeAvailable(googletest)
#
#set(SRC_ROOT_PATH ${ROOT_PATH}/src)
#set(SRC_PATH ${SRC_ROOT_PATH}/${PROBLEM_NAME})
#set(TESTS_PATH ${ROOT_PATH}/tests/${PROBLEM_NAME})
#
#include_directories(
# ${SRC_ROOT_PATH}
# ${SRC_PATH}
# ${TESTS_PATH}
#)
#
## test.
#enable_testing()
#
#add_executable(
# test_${PROBLEM_NAME}
# ${TESTS_PATH}/test.cc
#)
#target_link_libraries(test_${PROBLEM_NAME} GTest::gtest_main)
#
#
#include(GoogleTest)
#gtest_discover_tests(test_${PROBLEM_NAME})
15 changes: 9 additions & 6 deletions tests/724/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#include "utils/utils.h"
#include "solution.hpp"

TEST(testing, BasicAssertions) {
TEST(testing_pivotIndex, BasicAssertions) {
Solution solution;
EXPECT_EQ(solution.pivotIndex(std::vector{1, 7, 3, 6, 5, 6}), 3);
EXPECT_EQ(solution.pivotIndex({1, 2, 3}), -1);
EXPECT_EQ(solution.pivotIndex({2, 1, -1}), 0);
EXPECT_EQ(solution.pivotIndex({2, 1, -3}), -1);
EXPECT_EQ(solution.pivotIndex({-2, 2, -3}), 2);
}
EXPECT_EQ(solution.pivotIndex(std::vector{1, 2, 3}), -1);
EXPECT_EQ(solution.pivotIndex(std::vector{2, 1, -1}), 0);
EXPECT_EQ(solution.pivotIndex(std::vector{2, 1, -3}), -1);
EXPECT_EQ(solution.pivotIndex(std::vector{-2, 2, -3}), 2);
EXPECT_EQ(solution.pivotIndex(std::vector{1, 2, 3, 4, 2, 10}), 4);
auto vec = std::vector{1, 2, 3, 4, 2, 10};
EXPECT_EQ(solution.pivotIndex(vec), 4);
}

0 comments on commit 5af289d

Please sign in to comment.