Skip to content
Closed
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
2 changes: 1 addition & 1 deletion homework/inner-product/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions homework/inner-product/arithmeticAverage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "arithmeticAverage.hpp"
#include <algorithm>
#include <cmath>
#include <numeric>

#include <iostream>

float ArithmeticAverage(const std::vector<int>& v1, const std::vector<int>& 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<int>& v1, const std::vector<int>& 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);
}
5 changes: 5 additions & 0 deletions homework/inner-product/arithmeticAverage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include <vector>

float ArithmeticAverage(const std::vector<int>& v1, const std::vector<int>& v2);
float Distance(const std::vector<int>& v1, const std::vector<int>& v2);
9 changes: 9 additions & 0 deletions homework/inner-product/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RMDIR build /S /Q
mkdir build
cd build
cmake -G "MinGW Makefiles" ..
MinGW32-make

arithmeticAverage-ut.exe

cd ..