Bläddra i källkod

make gtest to be optional

Konstantin Ladutenko 2 år sedan
förälder
incheckning
f388c33c71
3 ändrade filer med 65 tillägg och 58 borttagningar
  1. 22 19
      .github/workflows/cmake.yml
  2. 2 1
      src/mesomie.hpp
  3. 41 38
      tests/CMakeLists.txt

+ 22 - 19
.github/workflows/cmake.yml

@@ -2,9 +2,9 @@ name: CMake
 
 on:
   push:
-    branches: [ "master" ]
+    branches: ["master"]
   pull_request:
-    branches: [ "master" ]
+    branches: ["master"]
 
 env:
   # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
@@ -18,20 +18,23 @@ jobs:
     runs-on: ubuntu-latest
 
     steps:
-    - uses: actions/checkout@v3
-
-    - name: Configure CMake
-      # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
-      # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
-      run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-
-    - name: Build
-      # Build your program with the given configuration
-      run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
-
-    - name: Test
-      working-directory: ${{github.workspace}}/build
-      # Execute tests defined by the CMake configuration.  
-      # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
-      run: ctest -C ${{env.BUILD_TYPE}}
-      
+      - uses: actions/checkout@v3
+
+      # without GTest and Boost
+      - name: Install Python NumPy
+        run: apt install python-numpy python-all-dev python-numpy-dev pybind11
+
+      - name: Configure CMake
+        # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
+        # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
+        run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
+
+      - name: Build
+        # Build your program with the given configuration
+        run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
+
+      - name: Test
+        working-directory: ${{github.workspace}}/build
+        # Execute tests defined by the CMake configuration.
+        # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
+        run: ctest -C ${{env.BUILD_TYPE}}

+ 2 - 1
src/mesomie.hpp

@@ -89,7 +89,8 @@ void MesoMie<FloatType>::calc_ab(FloatType R,
                                  std::complex<FloatType> d_parallel,
                                  std::complex<FloatType> d_perp) {
   x_ = R;
-  int nmax = std::round(x_ + 11 * std::pow(x_, (1.0 / 3.0)) + 1);
+  double xx = static_cast<double>(x_);
+  int nmax = std::round(xx + 11 * std::pow(xx, (1.0 / 3.0)) + 1);
   an_.resize(nmax + 1, static_cast<FloatType>(0.0));
   bn_.resize(nmax + 1, static_cast<FloatType>(0.0));
   std::vector<std::complex<FloatType>>      //

+ 41 - 38
tests/CMakeLists.txt

@@ -1,52 +1,55 @@
 cmake_minimum_required(VERSION 3.15)
 project(scattnlay_tests C CXX)
+
 # -- Dependency (Google Test)
-find_package(GTest REQUIRED)
-include_directories(${GTEST_INCLUDE_DIRS})
-set(LIBS ${LIBS} ${GTEST_LIBRARIES})
-set(LIBS ${LIBS} pthread)
+find_package(GTest)
+
+if(GTest_FOUND)
+    include_directories(${GTEST_INCLUDE_DIRS})
+    set(LIBS ${LIBS} ${GTEST_LIBRARIES})
+    set(LIBS ${LIBS} pthread)
 
-add_compile_options(-D_GLIBCXX_DEBUG)
-# -- Output tests in directory
+    add_compile_options(-D_GLIBCXX_DEBUG)
 
-add_executable("test_near_field"
+    # -- Output tests in directory
+    add_executable("test_near_field"
         test_near_field.cc)
-target_link_libraries("test_near_field" ${LIBS})
-add_test(NAME "test_near_field"
+    target_link_libraries("test_near_field" ${LIBS})
+    add_test(NAME "test_near_field"
         COMMAND "test_near_field")
 
-
-
-# In included file test_spec_functions_data.hpp there are results of multiple
-# precision computation that may overflow double precision at compile time.
-set_source_files_properties(test_Riccati_Bessel_logarithmic_derivative.cc
-        PROPERTIES COMPILE_FLAGS -Wno-overflow)
-add_executable("test_Riccati_Bessel_logarithmic_derivative"
+    # In included file test_spec_functions_data.hpp there are results of multiple
+    # precision computation that may overflow double precision at compile time.
+    set_source_files_properties(test_Riccati_Bessel_logarithmic_derivative.cc
+        PROPERTIES COMPILE_FLAGS "-Wno-overflow -Wno-literal-range")
+    add_executable("test_Riccati_Bessel_logarithmic_derivative"
         test_Riccati_Bessel_logarithmic_derivative.cc)
-target_link_libraries("test_Riccati_Bessel_logarithmic_derivative" ${LIBS})
-add_test(NAME "test_Riccati_Bessel_logarithmic_derivative"
+    target_link_libraries("test_Riccati_Bessel_logarithmic_derivative" ${LIBS})
+    add_test(NAME "test_Riccati_Bessel_logarithmic_derivative"
         COMMAND "test_Riccati_Bessel_logarithmic_derivative")
 
-#TODO remove -Wno
-set_source_files_properties(test_bulk_sphere.cc
+    # TODO remove -Wno
+    set_source_files_properties(test_bulk_sphere.cc
         PROPERTIES COMPILE_FLAGS "-Wno-overflow -Wno-unused-parameter")
-add_executable("test_bulk_sphere" test_bulk_sphere.cc)
-target_link_libraries("test_bulk_sphere" ${LIBS})
-add_test(NAME "test_bulk_sphere"
+    add_executable("test_bulk_sphere" test_bulk_sphere.cc)
+    target_link_libraries("test_bulk_sphere" ${LIBS})
+    add_test(NAME "test_bulk_sphere"
         COMMAND "test_bulk_sphere")
 
-
-add_executable("test_bulk_sphere_multi_precision" test_bulk_sphere.cc)
-target_compile_options("test_bulk_sphere_multi_precision"
-        PRIVATE -DMULTI_PRECISION=100)
-target_link_libraries("test_bulk_sphere_multi_precision" ${LIBS})
-add_test(NAME "test_bulk_sphere_multi_precision"
-        COMMAND "test_bulk_sphere_multi_precision")
-
-add_executable("test_near_field_multi_precision"
-        test_near_field.cc)
-target_compile_options("test_near_field_multi_precision"
-        PRIVATE -DMULTI_PRECISION=100)
-target_link_libraries("test_near_field_multi_precision" ${LIBS})
-add_test(NAME "test_near_field_multi_precision"
-        COMMAND "test_near_field_multi_precision")
+    if(Boost_FOUND)
+        add_executable("test_bulk_sphere_multi_precision" test_bulk_sphere.cc)
+        target_compile_options("test_bulk_sphere_multi_precision"
+            PRIVATE -DMULTI_PRECISION=100)
+        target_link_libraries("test_bulk_sphere_multi_precision" ${LIBS})
+        add_test(NAME "test_bulk_sphere_multi_precision"
+            COMMAND "test_bulk_sphere_multi_precision")
+
+        add_executable("test_near_field_multi_precision"
+            test_near_field.cc)
+        target_compile_options("test_near_field_multi_precision"
+            PRIVATE -DMULTI_PRECISION=100)
+        target_link_libraries("test_near_field_multi_precision" ${LIBS})
+        add_test(NAME "test_near_field_multi_precision"
+            COMMAND "test_near_field_multi_precision")
+    endif()
+endif()