From de3c9eda959c67949ea043af40706ed7c07b4aa3 Mon Sep 17 00:00:00 2001
From: Armin Co <armin.co@hs-bochum.de>
Date: Thu, 23 Apr 2020 22:07:41 +0200
Subject: [PATCH] Cleanup

---
 CMakeLists.txt               | 12 +++++++-----
 Jenkinsfile                  |  0
 gtk_qpong_app/CMakeLists.txt | 14 ++++++++++----
 gtk_qpong_app/QWindow.cpp    |  4 ++--
 qpong_core/CMakeLists.txt    |  6 ++++--
 qpong_core/Common.hpp        |  4 ++--
 qpong_core/Particle.hpp      | 25 +++++++++++++------------
 tests/CMakeLists.txt         |  4 +++-
 tests/test_qpong.cpp         | 22 +++++++++++++---------
 9 files changed, 54 insertions(+), 37 deletions(-)
 delete mode 100644 Jenkinsfile

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 68aeb2f..acd22c9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,23 +5,25 @@ cmake_minimum_required(VERSION 3.2)
 
 
 ## Options
-option(test "Build all tests." OFF)
+option(create_test "Build all tests." OFF)
 option(release_type "Set the type of the releas (Debug/Release)." Release)
 
 
 ## Use modern C++!
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_BUILD_TYPE Release)
+
+
+## PkgConfig
 find_package(PkgConfig REQUIRED)
-message(" - Build type is set to ${CMAKE_BUILD_TYPE}")
 
 
 # @todo Check versions of glib etc. librarys.
 # On Ubuntu 19.10 there are warnings which are not present in Ubuntu 18.04
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
+# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
 
 
-# Add qpong lib
+# Add qpong lib for core qpong functionality
 add_subdirectory(qpong_core)
 include_directories(qpong_core)
 
@@ -32,7 +34,7 @@ add_subdirectory(gtk_qpong_app)
 
 # Add some unit tests
 # not many yet ^^
-if (test)
+if (create_test)
     add_subdirectory(libs/googletest)
     add_subdirectory(tests)
 endif()
diff --git a/Jenkinsfile b/Jenkinsfile
deleted file mode 100644
index e69de29..0000000
diff --git a/gtk_qpong_app/CMakeLists.txt b/gtk_qpong_app/CMakeLists.txt
index ca6bf86..bafe30a 100644
--- a/gtk_qpong_app/CMakeLists.txt
+++ b/gtk_qpong_app/CMakeLists.txt
@@ -1,20 +1,26 @@
- 
+# Specific settings for macOS
 if(APPLE)
     link_directories("/usr/local/lib")
     message("ATTENTION: You probably have to export the PKG_CONFIG_PATH.")
     message("For example: export PKG_CONFIG_PATH=\"/usr/local/lib:/usr/local/opt/zlib/lib/pkgconfig\"")
 endif()
 
+
+# Setup GTK configuration
 pkg_check_modules(GTKMM gtkmm-3.0)
 link_directories(${GTKMM_LIBRARY_DIRS})
 
 
 # get all GTKMM dependencies and configuration
 include_directories(${GTKMM_INCLUDE_DIRS})
-include_directories(/usr/local/include)
+
+if(APPLE)
+    include_directories(/usr/local/include)
+endif()
+
 
 # create the application
-add_executable(qpong.app 
+add_executable( qpong.app 
     main.cpp 
     QWindow.cpp
     QDrawingArea.cpp
@@ -27,7 +33,7 @@ find_package(Threads)
 
 
 # link all necessary libs to the target
-target_link_libraries(qpong.app 
+target_link_libraries( qpong.app 
     qpong_core
     ${CMAKE_THREAD_LIBS_INIT}
     ${GTKMM_LIBRARIES}
diff --git a/gtk_qpong_app/QWindow.cpp b/gtk_qpong_app/QWindow.cpp
index f48201d..2943cbe 100644
--- a/gtk_qpong_app/QWindow.cpp
+++ b/gtk_qpong_app/QWindow.cpp
@@ -41,7 +41,7 @@ void QWindow::simulation()
         // Limit the speed of the simulation.
         auto dt = std::chrono::system_clock::now() - start;
         auto dtMillis = std::chrono::duration_cast<std::chrono::milliseconds>(dt).count();
-        constexpr int propTime = 60;
+        constexpr int propTime = 6;
         if (dtMillis < propTime)
         {
             std::this_thread::sleep_for(std::chrono::milliseconds(propTime - dtMillis));
@@ -58,7 +58,7 @@ void render(QWindow *w)
     {
         using namespace std::chrono_literals;
         auto start = std::chrono::system_clock::now();
-        std::this_thread::sleep_for(20ms);
+        std::this_thread::sleep_for(15ms);
         w->updateView();
         renderRate = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start).count();
     } while (true);
diff --git a/qpong_core/CMakeLists.txt b/qpong_core/CMakeLists.txt
index f91805b..72fb06b 100644
--- a/qpong_core/CMakeLists.txt
+++ b/qpong_core/CMakeLists.txt
@@ -1,8 +1,10 @@
-include_directories(/usr/local/include)
+if(APPLE)
+    include_directories(/usr/local/include)
+endif()
 
 ## library for the app should be GTK independent
 ##
-add_library(qpong_core
+add_library( qpong_core
     Particle.cpp
     ImageBuffer.cpp
     Player.cpp
diff --git a/qpong_core/Common.hpp b/qpong_core/Common.hpp
index 38e2963..61b8638 100644
--- a/qpong_core/Common.hpp
+++ b/qpong_core/Common.hpp
@@ -9,8 +9,8 @@
 namespace QPong
 {
 
-constexpr int arrayWidth = 256;
-constexpr int arrayHeight = 256;
+constexpr int arrayWidth = 384;
+constexpr int arrayHeight = 384;
 constexpr int numberOfThreads = 8;
 
 constexpr unsigned arraySize = arrayWidth * arrayHeight;
diff --git a/qpong_core/Particle.hpp b/qpong_core/Particle.hpp
index c0540e9..3af6f5a 100644
--- a/qpong_core/Particle.hpp
+++ b/qpong_core/Particle.hpp
@@ -1,7 +1,6 @@
 ///
 /// @file       Particle.hpp
 /// @author     Armin Co
-///
 /// @brief      Particle class header.
 ///
 
@@ -50,17 +49,6 @@ public:
 
 
 private:
-    std::complex<double> *m_psi;
-    fftw_plan m_planForward;
-    fftw_plan m_planBackward;
-    bool m_ready;
-
-    std::map<Player::Id, std::shared_ptr<Player>> m_players;
-
-    ImageBuffer *m_bufPositionRepresentation;
-    ImageBuffer *m_bufMomentumRepresentation;
-
-
     /// @brief Update the array at the ArrayCanvas
     ///
     void updateMomentumImage();
@@ -83,6 +71,19 @@ private:
     double removeParticle(int index, double cx);
 
 
+    std::complex<double> *m_psi;
+    fftw_plan m_planForward;
+    fftw_plan m_planBackward;
+    bool m_ready;
+
+    std::map<Player::Id, std::shared_ptr<Player>> m_players;
+
+    ImageBuffer *m_bufPositionRepresentation;
+    ImageBuffer *m_bufMomentumRepresentation;
+
+
+
+
     Particle() = delete;
 };
 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a7a3d1a..96d720a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,7 +1,9 @@
 
 enable_testing()
+
 include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
 add_executable(runUnitTests test_qpong.cpp)
+
 target_link_libraries(runUnitTests gtest gtest_main)
 target_link_libraries(runUnitTests qpong_core)
-add_test(NAME a-test COMMAND runUnitTests)
+add_test(NAME a-test COMMAND ./tests/runUnitTests)
diff --git a/tests/test_qpong.cpp b/tests/test_qpong.cpp
index c91a248..e3b1982 100644
--- a/tests/test_qpong.cpp
+++ b/tests/test_qpong.cpp
@@ -43,16 +43,20 @@ TEST(ImageBuffer, getValue)
 }
 
 
-TEST(addInts, addNumbers)
+TEST(addInts, positiveValues)
 {
-    int a{ 1 };
-    int b{ 3 };
-
-    EXPECT_EQ(4, addInts(a,b));
-    EXPECT_EQ(4, addInts(a,b));
-    EXPECT_EQ(4, addInts(a,b));
-    EXPECT_EQ(4, addInts(a,b));
-    EXPECT_EQ(4, addInts(a,b));
+    int a {1};
+    int b {3};
+
+    ASSERT_EQ(addInts(a, b), 4);
 }
 
+TEST(addInts, shouldBreak)
+{
+    EXPECT_NE(3+1, 0) << "Yes yes, because it is just a test!";
+}
 
+TEST(addInts, negativeValues)
+{
+    ASSERT_EQ(-3 + -5, -8);
+}
\ No newline at end of file
-- 
GitLab