From 51d20067c6aa6ddef6f428808159e070fa35b322 Mon Sep 17 00:00:00 2001 From: Eero Holmala Date: Tue, 27 Jun 2023 11:53:21 +0300 Subject: [PATCH] Save App --- App/.vscode/settings.json | 3 ++- App/App/src/App.cpp | 2 +- App/AppLib/include/AppLib/Algorithm.cpp | 26 +++++++++++++++++++++++++ App/AppLib/include/AppLib/Algorithm.hh | 16 +++++++++++++++ App/Tests/AlgoTest.cpp | 17 ++++++++++++++++ App/Tests/AllTests.cpp | 7 +++++++ App/Tests/CMakeLists.txt | 8 +++++++- App/Tests/Helpers.hh | 21 ++++++++++++++++++++ App/Tests/MathTest.cpp | 7 +------ App/Tests/MockAlgorithm.hh | 14 +++++++++++++ 10 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 App/AppLib/include/AppLib/Algorithm.cpp create mode 100644 App/AppLib/include/AppLib/Algorithm.hh create mode 100644 App/Tests/AlgoTest.cpp create mode 100644 App/Tests/AllTests.cpp create mode 100644 App/Tests/Helpers.hh create mode 100644 App/Tests/MockAlgorithm.hh diff --git a/App/.vscode/settings.json b/App/.vscode/settings.json index a7cb670..e08ab1c 100644 --- a/App/.vscode/settings.json +++ b/App/.vscode/settings.json @@ -70,7 +70,8 @@ "xlocbuf": "cpp", "xlocmes": "cpp", "xlocmon": "cpp", - "xloctime": "cpp" + "xloctime": "cpp", + "array": "cpp" }, "cmake.configureOnOpen": true } \ No newline at end of file diff --git a/App/App/src/App.cpp b/App/App/src/App.cpp index 157a688..bcf9e4d 100644 --- a/App/App/src/App.cpp +++ b/App/App/src/App.cpp @@ -92,7 +92,7 @@ namespace App opengl_shader_compile_source(fs, fs_source); m_prog = glCreateProgram(); - opengl_shader_link_program(m_prog, vs, fs); + // opengl_shader_link_program(m_prog, vs, fs); GLint uniform_angle = glGetUniformLocation(m_prog, "angle"); diff --git a/App/AppLib/include/AppLib/Algorithm.cpp b/App/AppLib/include/AppLib/Algorithm.cpp new file mode 100644 index 0000000..dae6689 --- /dev/null +++ b/App/AppLib/include/AppLib/Algorithm.cpp @@ -0,0 +1,26 @@ +#include "Algorithm.hh" +namespace Core +{ + +vector Algorithm::selection_sort(vector &arr) +{ + vector ret = vector(); + + int sorted_index = 0; + + if(arr.size() == 0 || arr.size() == 1) + { + return arr; + } + + for (int elem : arr) + { + + } + + + return arr; +} + +} // namespace Core + diff --git a/App/AppLib/include/AppLib/Algorithm.hh b/App/AppLib/include/AppLib/Algorithm.hh new file mode 100644 index 0000000..5796a25 --- /dev/null +++ b/App/AppLib/include/AppLib/Algorithm.hh @@ -0,0 +1,16 @@ +// https://www.interviewcake.com/sorting-algorithm-cheat-sheet +#pragma once + +#include + +using std::vector; + +namespace Core { + +class Algorithm +{ +public: + static vector selection_sort(vector &arr); +private: +}; +} // namespace Core \ No newline at end of file diff --git a/App/Tests/AlgoTest.cpp b/App/Tests/AlgoTest.cpp new file mode 100644 index 0000000..b5548e8 --- /dev/null +++ b/App/Tests/AlgoTest.cpp @@ -0,0 +1,17 @@ +#include +#include + +#include "Helpers.hh" + +using namespace Core; +using std::vector; + +TEST(Algo, selection_sort) +{ + EXPECT_CALL(turtle, PenDown()) // #3 + .Times(AtLeast(1)); + vector vec1 = vector{3,2,1,35,24}; + vector vec2 = Algorithm::selection_sort(vec1); + ASSERT_TRUE(Helpers::is_sorted(vec2) == true); + +} \ No newline at end of file diff --git a/App/Tests/AllTests.cpp b/App/Tests/AllTests.cpp new file mode 100644 index 0000000..8608288 --- /dev/null +++ b/App/Tests/AllTests.cpp @@ -0,0 +1,7 @@ +#include + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/App/Tests/CMakeLists.txt b/App/Tests/CMakeLists.txt index e6a18df..819731e 100644 --- a/App/Tests/CMakeLists.txt +++ b/App/Tests/CMakeLists.txt @@ -4,9 +4,14 @@ enable_testing() add_executable( AppTest + AllTests.cpp MathTest.cpp + AlgoTest.cpp + Helpers.hh + MockAlgorithm.hh ) + target_include_directories(App PUBLIC "${CMAKE_SOURCE_DIR}/AppLib/include/AppLib") find_package(GTest CONFIG REQUIRED) @@ -25,4 +30,5 @@ endif() include(GoogleTest) gtest_discover_tests(AppTest) -add_test(MathTest AppTest) \ No newline at end of file +add_test(AppTest AppTest) +# add_test(MathTest AppTest) \ No newline at end of file diff --git a/App/Tests/Helpers.hh b/App/Tests/Helpers.hh new file mode 100644 index 0000000..2282dd8 --- /dev/null +++ b/App/Tests/Helpers.hh @@ -0,0 +1,21 @@ +#include + + +class Helpers { +public: + static bool is_sorted(std::vector &arr) + { + int index = 0; + for (auto e : arr) + { + if(index == 0) + index++; + continue; + if(e < arr[index-1]) + return false; + index++; + } + return true; + + } +}; diff --git a/App/Tests/MathTest.cpp b/App/Tests/MathTest.cpp index f23f638..0bd6816 100644 --- a/App/Tests/MathTest.cpp +++ b/App/Tests/MathTest.cpp @@ -21,9 +21,4 @@ TEST(Math, Vector2_Add) } //TODO (Eero): Add tests for Vector2 -//TODO (Eero): Add tests for Vector3 -int main(int argc, char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} \ No newline at end of file +//TODO (Eero): Add tests for Vector3 \ No newline at end of file diff --git a/App/Tests/MockAlgorithm.hh b/App/Tests/MockAlgorithm.hh new file mode 100644 index 0000000..54759d7 --- /dev/null +++ b/App/Tests/MockAlgorithm.hh @@ -0,0 +1,14 @@ +#include +#include +#include "Algorithm.hh" + +using std:: vector; + +namespace Core +{ +class MockAlgorithm : Algorithm +{ +public: + MOCK_METHOD(vector, selection_sort, (vector arr&), ()); +}; +} \ No newline at end of file