Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Черепанов Иван Александрович #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ add_compile_options(-Wall -Wextra -Werror)

add_executable(main "${SRC_DIR}/main.cpp" "${SRC_DIR}/two-sum.cpp")

find_package(GTest REQUIRED)
add_executable(two-sum-test "${TEST_DIR}/test.cpp" "${SRC_DIR}/two-sum.cpp")
target_link_libraries(two-sum-test PRIVATE gtest::gtest)
target_compile_options(two-sum-test PRIVATE "-fsanitize=address,undefined")
target_link_options(two-sum-test PRIVATE "-fsanitize=address,undefined")
add_test(NAME two-sum-test COMMAND two-sum-test)
include(GoogleTest)
gtest_discover_tests(two-sum-test)
#find_package(GTest REQUIRED)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не надо было это коммитить и пушить, сейчас из-за этого не заработают тесты в GitHub Actions

#add_executable(two-sum-test "${TEST_DIR}/test.cpp" "${SRC_DIR}/two-sum.cpp")
#target_link_libraries(two-sum-test PRIVATE gtest::gtest)
#target_compile_options(two-sum-test PRIVATE "-fsanitize=address,undefined")
#target_link_options(two-sum-test PRIVATE "-fsanitize=address,undefined")
#add_test(NAME two-sum-test COMMAND two-sum-test)
#include(GoogleTest)S
#gtest_discover_tests(two-sum-test)
28 changes: 28 additions & 0 deletions src/two-sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include "two-sum.hpp"

using namespace std;
bool two_sum(
const int nums[ARRAY_SIZE],
const int target,
size_t& index0,
size_t& index1)
{
bool answer = false;
for(size_t i = 0; i < ARRAY_SIZE - 1; i ++) {
for(size_t j = i + 1; j < ARRAY_SIZE; j++){
if(nums[i] + nums[j] == target) {
if(nums[i] < nums[j]){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем нужна эта проверка?

index0 = nums[i];
index1 = nums[j];
}
else{
index0 = nums[j];
index1 = nums[i];
}
answer = true;
}
}
}
return answer;
}