Parcourir la source

skip long tests for MP in CI

Konstantin Ladutenko il y a 2 ans
Parent
commit
7a6e28a649
5 fichiers modifiés avec 131 ajouts et 101 suppressions
  1. 21 0
      .github/workflows/cmake.yml
  2. 5 0
      CMakeLists.txt
  3. 4 2
      tests/test_bulk_sphere.cc
  4. 24 28
      tests/test_cases.hpp
  5. 77 71
      tests/test_near_field.cc

+ 21 - 0
.github/workflows/cmake.yml

@@ -59,3 +59,24 @@ jobs:
         # 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}}
+
+      ##################################################################
+      # Do just the same but now with Boost multiprecision
+      ##################################################################
+      - name: install Google Test
+        run: sudo apt install libboost-all-dev
+
+      - 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}} -DSKIP_LONG_TESTS=ON
+
+      - 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}}

+ 5 - 0
CMakeLists.txt

@@ -55,6 +55,11 @@ if (Boost_FOUND)
         include_directories(${Boost_INCLUDE_DIRS})
     endif ()
 endif()
+OPTION(SKIP_LONG_TESTS "Skip some tests (usefull for multiprecision)" OFF)
+if (SKIP_LONG_TESTS) 
+    message("Skipping long tests for GTest...")
+    add_definitions(-DSKIP_LONG_TESTS)
+endif()
 
 #Find Python, NumPy and PyBind11
 find_package(Python COMPONENTS Interpreter Development)

+ 4 - 2
tests/test_bulk_sphere.cc

@@ -45,16 +45,18 @@ std::vector<std::tuple<double, std::complex<double>, double, double, char> >
         {0.099, {0.75, 0}, 7.417859e-06, 7.417859e-06, 'a'},
         {0.101, {0.75, 0}, 8.033538e-06, 8.033538e-06, 'b'},
         {10, {0.75, 0}, 2.232265, 2.232265, 'c'},
-        {100, {1.33, 1e-5}, 2.101321, 2.096594, 'e'},
         {0.055, {1.5, 1}, 0.10149104, 1.131687e-05, 'g'},
         {0.056, {1.5, 1}, 0.1033467, 1.216311e-05, 'h'},
-        {100, {1.5, 1}, 2.097502, 1.283697, 'i'},
         {1, {10, 10}, 2.532993, 2.049405, 'k'},
+#ifdef SKIP_LONG_TESTS
+        {100, {1.33, 1e-5}, 2.101321, 2.096594, 'e'},
+        {100, {1.5, 1}, 2.097502, 1.283697, 'i'},
         {1000, {0.75, 0}, 1.997908, 1.997908, 'd'},
         {100, {10, 10}, 2.071124, 1.836785, 'l'},
         {10000, {1.33, 1e-5}, 2.004089, 1.723857, 'f'},
         {10000, {1.5, 1}, 2.004368, 1.236574, 'j'},
         {10000, {10, 10}, 2.005914, 1.795393, 'm'},
+#endif
     };
 //******************************************************************************
 TEST(BulkSphere, DISABLED_HandlesInput) {

+ 24 - 28
tests/test_cases.hpp

@@ -2,35 +2,31 @@
 #define SCATTNLAY_TESTS_TEST_CASES_HPP_
 //
 //
-#include <vector>
-#include <tuple>
-#include <string>
 #include <complex>
+#include <string>
+#include <tuple>
+#include <vector>
 
-
-std::vector< std::tuple< double, std::complex<double>, std::string > >
-parameters_bulk_sphere
-{
-// x, {Re(m), Im(m)}, test_name
-{0.099, {0.75,0}, "Hong Du testcase:a"},
-{0.101, {0.75,0}, "Hong Du testcase:b"},
-{10,    {0.75,0}, "Hong Du testcase:c"},
-{100,   {1.33,1e-5}, "Hong Du testcase:e"},
-{0.055, {1.5, 1},    "Hong Du testcase:g"},
-{0.056, {1.5, 1}, "Hong Du testcase:h"},
-{100,   {1.5, 1}, "Hong Du testcase:i"},
-{1,     {10,  10},   "Hong Du testcase:k"},
-{1000,  {0.75,0}, "Hong Du testcase:d"},
-//{10000, {1.33,1e-5}, "Hong Du testcase:f"}, // passes but takes too long
-//{100,   {10,  10,},  "Hong Du testcase:l"}, // fails in any precision, TODO fixme
-//{10000, {1.5, 1},    "Hong Du testcase:j"},
-//{10000, {10,  10},   "Hong Du testcase:m"},
-#ifdef MULTI_PRECISION
-//{10000, {1.33,1e-5}, "Hong Du testcase:f"}, // passes but takes too long
-//{100,   {10,  10,},  "Hong Du testcase:l"}, // fails in any precision
-//{10000, {1.5, 1},    "Hong Du testcase:j"},
-//{10000, {10,  10},   "Hong Du testcase:m"},
+std::vector<std::tuple<double, std::complex<double>, std::string> >
+    parameters_bulk_sphere{
+        // x, {Re(m), Im(m)}, test_name
+        {0.099, {0.75, 0}, "Hong Du testcase:a"},
+        {0.101, {0.75, 0}, "Hong Du testcase:b"},
+        {10, {0.75, 0}, "Hong Du testcase:c"},
+        {100, {1.33, 1e-5}, "Hong Du testcase:e"},
+        {0.055, {1.5, 1}, "Hong Du testcase:g"},
+        {0.056, {1.5, 1}, "Hong Du testcase:h"},
+        {1, {10, 10}, "Hong Du testcase:k"},
+#ifdef SKIP_LONG_TESTS
+        {100, {1.5, 1}, "Hong Du testcase:i"},
+        {1000, {0.75, 0}, "Hong Du testcase:d"},
+        // passes but takes too long
+        {10000, {1.33, 1e-5}, "Hong Du testcase:f"},
+        // fails in any precision, TODO fixme
+        {100, {10, 10}, "Hong Du testcase:l"},
+        {10000, {1.5, 1}, "Hong Du testcase:j"},
+        {10000, {10, 10}, "Hong Du testcase:m"},
 #endif
-};
+    };
 
-#endif //SCATTNLAY_TESTS_TEST_CASES_HPP_
+#endif  // SCATTNLAY_TESTS_TEST_CASES_HPP_

+ 77 - 71
tests/test_near_field.cc

@@ -1,76 +1,74 @@
-#include "gtest/gtest.h"
 #include "../src/nmie-basic.hpp"
 #include "../src/nmie-nearfield.hpp"
+#include "gtest/gtest.h"
 #include "test_cases.hpp"
 
-//TEST(RunFieldCalculationCartesian, DISABLED_HandlesInput) {
+// TEST(RunFieldCalculationCartesian, DISABLED_HandlesInput) {
 TEST(RunFieldCalculationCartesian, HandlesInput) {
   nmie::MultiLayerMie<nmie::FloatType> nmie;
-//  EXPECT_THROW(nmie.RunFieldCalculationPolar(0), std::invalid_argument);
-//  EXPECT_THROW(nmie.RunFieldCalculationPolar(1,1,10,5), std::invalid_argument);
-  nmie::FloatType total_r = 2*nmie::PI_*1000/532;
-//  double r = 1500;
-  nmie.SetLayersSize({total_r/2, total_r});
-  nmie.SetLayersIndex({ {1.330,0}, {1.33,0}});
+  //  EXPECT_THROW(nmie.RunFieldCalculationPolar(0), std::invalid_argument);
+  //  EXPECT_THROW(nmie.RunFieldCalculationPolar(1,1,10,5),
+  //  std::invalid_argument);
+  nmie::FloatType total_r = 2 * nmie::PI_ * 1000 / 532;
+  //  double r = 1500;
+  nmie.SetLayersSize({total_r / 2, total_r});
+  nmie.SetLayersIndex({{1.330, 0}, {1.33, 0}});
   nmie.RunMieCalculation();
   double relative_max_distance = 1e-10;
-//  nmie.SetModeNmaxAndType(3,-1);
-//  int nmax = 21;
-  nmie.RunFieldCalculationCartesian(2, 5, relative_max_distance, nmie::Planes::kEk,
-                                    1.0, 0, 0, false,3);
+  //  nmie.SetModeNmaxAndType(3,-1);
+  //  int nmax = 21;
+  nmie.RunFieldCalculationCartesian(2, 5, relative_max_distance,
+                                    nmie::Planes::kEk, 1.0, 0, 0, false, 3);
   auto Eabs = nmie.GetFieldEabs();
   auto E = nmie.GetFieldE();
-  std::cout<<std::endl;
+  std::cout << std::endl;
   {
     // Eabs points are located near the sphere outer border
     //
     //    0   1   2   3   4
     //    ----- border ----
     //    5   6   7   8   9
-    // distance between points (0) and (4) is relative_max_distance*total_r, initial
-    // value used for the test was 1e-10*total_r, so we expect good linear dependence
-    // for points from 0 to 4 and 5 to 9. In the asserts we check, that the slope doesn't
-    // change too fast inside the curve. While writing this, the test was failing.
-    // The value of z-coordinates of 2 and 7 points = 0
+    // distance between points (0) and (4) is relative_max_distance*total_r,
+    // initial value used for the test was 1e-10*total_r, so we expect good
+    // linear dependence for points from 0 to 4 and 5 to 9. In the asserts we
+    // check, that the slope doesn't change too fast inside the curve. While
+    // writing this, the test was failing. The value of z-coordinates of 2 and 7
+    // points = 0
     using nmie::nmm::abs;
-    EXPECT_TRUE(
-        ( abs(Eabs[0] - Eabs[1]) + abs(Eabs[3] - Eabs[4]) ) >= abs(Eabs[1] - Eabs[2])
-        );
-    EXPECT_TRUE(
-        ( abs(Eabs[5] - Eabs[6]) + abs(Eabs[8] - Eabs[9]) ) >= abs(Eabs[6] - Eabs[7])
-    );
+    EXPECT_TRUE((abs(Eabs[0] - Eabs[1]) + abs(Eabs[3] - Eabs[4])) >=
+                abs(Eabs[1] - Eabs[2]));
+    EXPECT_TRUE((abs(Eabs[5] - Eabs[6]) + abs(Eabs[8] - Eabs[9])) >=
+                abs(Eabs[6] - Eabs[7]));
   }
 
-
-//  nmie.RunFieldCalculationCartesian(2, 2, 2, nmie::Planes::kHk,
-//                                    0, 0, 0, true);
-//  nmie.RunFieldCalculationCartesian(2, 2, 2, nmie::Planes::kEH,
-//                                    0, 0, 0, true);
+  //  nmie.RunFieldCalculationCartesian(2, 2, 2, nmie::Planes::kHk,
+  //                                    0, 0, 0, true);
+  //  nmie.RunFieldCalculationCartesian(2, 2, 2, nmie::Planes::kEH,
+  //                                    0, 0, 0, true);
   // TODO add check of E and H symmetry for X and Y axis inversion
 
-//  EXPECT_EQ(1, nmie.GetMaxTerms());
-//  EXPECT_FALSE(nmie.GetFieldConvergence());
-//  auto Eabs = nmie.GetFieldEabs();
-//  EXPECT_TRUE(std::isnan(static_cast<double>(Eabs[0])));
-
+  //  EXPECT_EQ(1, nmie.GetMaxTerms());
+  //  EXPECT_FALSE(nmie.GetFieldConvergence());
+  //  auto Eabs = nmie.GetFieldEabs();
+  //  EXPECT_TRUE(std::isnan(static_cast<double>(Eabs[0])));
 }
-
+#ifdef SKIP_LONG_TESTS
 TEST(LargeBubbleSpectrum, DISABLED_HandlesInput) {
-//TEST(LargeBubbleSpectrum, HandlesInput) { // TODO fix fail...
+  // TEST(LargeBubbleSpectrum, HandlesInput) { // TODO fix fail...
   nmie::MultiLayerMie<nmie::FloatType> nmie;
-  nmie::FloatType core_r  = 2*nmie::PI_*100;
-  nmie::FloatType shell_r = 2*nmie::PI_*(100+0.1);
-  nmie.SetLayersIndex({ {1,0}, {1.33,0}});
+  nmie::FloatType core_r = 2 * nmie::PI_ * 100;
+  nmie::FloatType shell_r = 2 * nmie::PI_ * (100 + 0.1);
+  nmie.SetLayersIndex({{1, 0}, {1.33, 0}});
   double central_WL = 0.7007;
   double relative_distance = 1e-10;
-  double dWL = central_WL*relative_distance;
+  double dWL = central_WL * relative_distance;
   std::vector<double> Qsca(5);
   for (int i = 0; i < 5; ++i) {
-    auto WL = static_cast<nmie::FloatType>(central_WL +(i - 2)*dWL);
-    nmie.SetLayersSize({core_r/WL, shell_r/WL});
+    auto WL = static_cast<nmie::FloatType>(central_WL + (i - 2) * dWL);
+    nmie.SetLayersSize({core_r / WL, shell_r / WL});
     nmie.RunMieCalculation();
     Qsca[i] = static_cast<double>(nmie.GetQsca());
-    std::cout<<"Qsca["<<i<<"]="<<Qsca[i]<<std::endl;
+    std::cout << "Qsca[" << i << "]=" << Qsca[i] << std::endl;
   }
 
   {
@@ -78,61 +76,69 @@ TEST(LargeBubbleSpectrum, DISABLED_HandlesInput) {
     //
     //    0   1   2   3   4
     //    ------- WL ------>
-    // distance between points (0) and (4) is 5*relative_distance*central_WL, initial
-    // value used for the test was 5*1e-10*0.7007, so we expect good linear dependence
-    // for points from 0 to 4. In the asserts we check, that the slope doesn't
-    // change too fast inside the curve.
+    // distance between points (0) and (4) is 5*relative_distance*central_WL,
+    // initial value used for the test was 5*1e-10*0.7007, so we expect good
+    // linear dependence for points from 0 to 4. In the asserts we check, that
+    // the slope doesn't change too fast inside the curve.
     using std::abs;
-    EXPECT_TRUE(
-        ( abs(Qsca[0] - Qsca[1]) + abs(Qsca[3] - Qsca[4]) ) >= abs(Qsca[1] - Qsca[2])
-    );
+    EXPECT_TRUE((abs(Qsca[0] - Qsca[1]) + abs(Qsca[3] - Qsca[4])) >=
+                abs(Qsca[1] - Qsca[2]));
   }
 }
+#endif
 
-//TEST(RunFieldCalculationPolar, DISABLED_HandlesInput) {
+// TEST(RunFieldCalculationPolar, DISABLED_HandlesInput) {
 TEST(RunFieldCalculationPolar, HandlesInput) {
   nmie::MultiLayerMie<nmie::FloatType> nmie;
   EXPECT_THROW(nmie.RunFieldCalculationPolar(0), std::invalid_argument);
-  EXPECT_THROW(nmie.RunFieldCalculationPolar(1,1,10,5), std::invalid_argument);
+  EXPECT_THROW(nmie.RunFieldCalculationPolar(1, 1, 10, 5),
+               std::invalid_argument);
   double r = 60;
-//  double r = 1500;
-  nmie.SetLayersSize({r/2, r});
-  nmie.SetLayersIndex({ {1.33,0}, {1.33,0}});
+  //  double r = 1500;
+  nmie.SetLayersSize({r / 2, r});
+  nmie.SetLayersIndex({{1.33, 0}, {1.33, 0}});
   nmie.RunMieCalculation();
-  nmie.RunFieldCalculationPolar(1, 1,
-                                0.5145*r,
-                                r*0.5148,
-                                0, 3.14, 0, 0, true, 1);
+  nmie.RunFieldCalculationPolar(1, 1, 0.5145 * r, r * 0.5148, 0, 3.14, 0, 0,
+                                true, 1);
   EXPECT_EQ(1, nmie.GetMaxTerms());
   EXPECT_FALSE(nmie.GetFieldConvergence());
   auto Eabs = nmie.GetFieldEabs();
   EXPECT_TRUE(std::isnan(static_cast<double>(Eabs[0])));
-
 }
 //#ifndef MULTI_PRECISION
-//TEST(BulkSphere, DISABLED_HandlesInput) {
+// TEST(BulkSphere, DISABLED_HandlesInput) {
 TEST(BulkSphere, HandlesInput) {
   nmie::MultiLayerMie<nmie::FloatType> nmie;
-  for (const auto &data : parameters_bulk_sphere) {
+  for (const auto& data : parameters_bulk_sphere) {
     auto x = std::get<0>(data);
     auto m = std::get<1>(data);
     nmie.SetLayersSize({x});
     nmie.SetLayersIndex({m});
     nmie.SetMaxTerms(-1);
-//    nmie.RunMieCalculation();
-//    std::cout<<" test case: "<<std::get<2>(data)<<" Qsca="<<nmie.GetQsca()<<std::endl;
-    nmie.RunFieldCalculationPolar(4,3,x,x*3, 0, static_cast<double>(nmie::PI_), 0, static_cast<double>(nmie::PI_),true, -1);
+    //    nmie.RunMieCalculation();
+    //    std::cout<<" test case: "<<std::get<2>(data)<<"
+    //    Qsca="<<nmie.GetQsca()<<std::endl;
+    nmie.RunFieldCalculationPolar(4, 3, x, x * 3, 0,
+                                  static_cast<double>(nmie::PI_), 0,
+                                  static_cast<double>(nmie::PI_), true, -1);
     auto Eabs = nmie.GetFieldEabs();
-    for (auto &E:Eabs) E=nmie::pow2(E);
-//    print(Eabs)
-    EXPECT_TRUE(nmie.GetFieldConvergence())<<"Outside test for x="<<x<<" m="<<m<<" test case: "<<std::get<2>(data)<<std::endl;
-    nmie.RunFieldCalculationPolar(4,10,x*0.01,x, 0, static_cast<double>(nmie::PI_), 0, static_cast<double>(nmie::PI_),true, -1);
-    EXPECT_TRUE(nmie.GetFieldConvergence())<<"Inside test for x="<<x<<" m="<<m<<" test case: "<<std::get<2>(data)<<std::endl;
+    for (auto& E : Eabs)
+      E = nmie::pow2(E);
+    //    print(Eabs)
+    EXPECT_TRUE(nmie.GetFieldConvergence())
+        << "Outside test for x=" << x << " m=" << m
+        << " test case: " << std::get<2>(data) << std::endl;
+    nmie.RunFieldCalculationPolar(4, 10, x * 0.01, x, 0,
+                                  static_cast<double>(nmie::PI_), 0,
+                                  static_cast<double>(nmie::PI_), true, -1);
+    EXPECT_TRUE(nmie.GetFieldConvergence())
+        << "Inside test for x=" << x << " m=" << m
+        << " test case: " << std::get<2>(data) << std::endl;
   }
 }
 //#endif
 
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
   testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();
 }