diff --git a/homework/inner-product/CMakeLists.txt b/homework/inner-product/CMakeLists.txt index 29883dae0..64ab8a18f 100644 --- a/homework/inner-product/CMakeLists.txt +++ b/homework/inner-product/CMakeLists.txt @@ -18,7 +18,7 @@ FetchContent_MakeAvailable(googletest) project(arithmeticAverage) enable_testing() -add_executable(${PROJECT_NAME} main.cpp arithmeticAverage.cpp) +# add_executable(${PROJECT_NAME} main.cpp arithmeticAverage.cpp) add_executable(${PROJECT_NAME}-ut test.cpp arithmeticAverage.cpp) target_link_libraries(${PROJECT_NAME}-ut gtest_main) diff --git a/homework/inner-product/arithmeticAverage.cpp b/homework/inner-product/arithmeticAverage.cpp new file mode 100644 index 000000000..696fa29df --- /dev/null +++ b/homework/inner-product/arithmeticAverage.cpp @@ -0,0 +1,28 @@ +#include "arithmeticAverage.hpp" +#include +#include +#include + +#include + +float ArithmeticAverage(const std::vector& v1, const std::vector& v2) { + float sum = 0; + sum = std::accumulate(v1.begin(), v1.end(), sum); + sum = std::accumulate(v2.begin(), v2.end(), sum); + + return (sum / (v1.size() + v2.size())); +} + +float Distance(const std::vector& v1, const std::vector& v2) { + float sum_squared = 0.0; + + if (v1.size() == v2.size()) { + auto it1 = v1.begin(); + auto it2 = v2.begin(); + for (; it1 != v1.end(); it1++, it2++) { + sum_squared += pow(*it1 - *it2, 2); + } + } + + return sqrt(sum_squared); +} \ No newline at end of file diff --git a/homework/inner-product/arithmeticAverage.hpp b/homework/inner-product/arithmeticAverage.hpp new file mode 100644 index 000000000..9398c7bf0 --- /dev/null +++ b/homework/inner-product/arithmeticAverage.hpp @@ -0,0 +1,5 @@ +#pragma once +#include + +float ArithmeticAverage(const std::vector& v1, const std::vector& v2); +float Distance(const std::vector& v1, const std::vector& v2); \ No newline at end of file diff --git a/homework/inner-product/build.bat b/homework/inner-product/build.bat new file mode 100644 index 000000000..a16f3b98a --- /dev/null +++ b/homework/inner-product/build.bat @@ -0,0 +1,9 @@ +RMDIR build /S /Q +mkdir build +cd build +cmake -G "MinGW Makefiles" .. +MinGW32-make + +arithmeticAverage-ut.exe + +cd ..