From b9ebc38cd9de705466dd49c012c7d9ab68e90ceb Mon Sep 17 00:00:00 2001
From: Shaun Roe <shaun.roe@cern.ch>
Date: Thu, 20 Jul 2017 14:39:43 +0200
Subject: [PATCH] Add NavigationLayerTests

---
 Core/include/ACTS/Layers/NavigationLayer.hpp |  2 +-
 Tests/Layers/CMakeLists.txt                  |  4 +-
 Tests/Layers/ConeLayerTests.cpp              |  2 +-
 Tests/Layers/CylinderLayerTests.cpp          |  2 +-
 Tests/Layers/DiscLayerTests.cpp              |  2 +-
 Tests/Layers/LayerStub.hpp                   |  8 ++
 Tests/Layers/LayerTests.cpp                  |  4 +-
 Tests/Layers/NavigationLayerTests.cpp        | 79 ++++++++++++++++++++
 Tests/Layers/PlaneLayerTests.cpp             |  2 +-
 9 files changed, 97 insertions(+), 8 deletions(-)
 create mode 100644 Tests/Layers/NavigationLayerTests.cpp

diff --git a/Core/include/ACTS/Layers/NavigationLayer.hpp b/Core/include/ACTS/Layers/NavigationLayer.hpp
index 32f4effea..10997925a 100644
--- a/Core/include/ACTS/Layers/NavigationLayer.hpp
+++ b/Core/include/ACTS/Layers/NavigationLayer.hpp
@@ -34,7 +34,7 @@ public:
   ///  Factory Constructor - the surface representation is given by pointer
   /// (ownership passed)
   ///
-  /// @param sRepresentation is the represenation for extrapolation
+  /// @param sRepresentation is the representation for extrapolation
   /// @param thickness is the thickness for the binning
   static LayerPtr
   create(std::unique_ptr<const Surface> sRepresentation, double thickness = 0.)
diff --git a/Tests/Layers/CMakeLists.txt b/Tests/Layers/CMakeLists.txt
index b12be1810..4fcca6e84 100644
--- a/Tests/Layers/CMakeLists.txt
+++ b/Tests/Layers/CMakeLists.txt
@@ -18,4 +18,6 @@ add_executable (ConeLayerTests ConeLayerTests.cpp)
 target_link_libraries (ConeLayerTests PRIVATE ACTSCore)
 add_test (NAME ConeLayerTests COMMAND ConeLayerTests)
 
-
+add_executable (NavigationLayerTests NavigationLayerTests.cpp)
+target_link_libraries (NavigationLayerTests PRIVATE ACTSCore)
+add_test (NAME NavigationLayerTests COMMAND NavigationLayerTests)
diff --git a/Tests/Layers/ConeLayerTests.cpp b/Tests/Layers/ConeLayerTests.cpp
index cae1fbe98..d37dd6941 100644
--- a/Tests/Layers/ConeLayerTests.cpp
+++ b/Tests/Layers/ConeLayerTests.cpp
@@ -88,7 +88,7 @@ namespace Test {
     }
 
     /// Unit test for testing Layer properties
-    BOOST_AUTO_TEST_CASE(LayerProperties /*, *utf::expected_failures(1)*/)
+    BOOST_AUTO_TEST_CASE(ConeLayerProperties /*, *utf::expected_failures(1)*/)
     {
       Translation3D translation{0., 1., 2.};
       auto pTransform = std::make_shared<const Transform3D>(translation);
diff --git a/Tests/Layers/CylinderLayerTests.cpp b/Tests/Layers/CylinderLayerTests.cpp
index 3ec9b53a4..8f4cc40c6 100644
--- a/Tests/Layers/CylinderLayerTests.cpp
+++ b/Tests/Layers/CylinderLayerTests.cpp
@@ -86,7 +86,7 @@ namespace Test {
     }
 
     /// Unit test for testing Layer properties
-    BOOST_AUTO_TEST_CASE(LayerProperties /*, *utf::expected_failures(1)*/)
+    BOOST_AUTO_TEST_CASE(CylinderLayerProperties /*, *utf::expected_failures(1)*/)
     {
       Translation3D translation{0., 1., 2.};
       auto pTransform = std::make_shared<const Transform3D>(translation);
diff --git a/Tests/Layers/DiscLayerTests.cpp b/Tests/Layers/DiscLayerTests.cpp
index 55ce86296..8d9dd5c96 100644
--- a/Tests/Layers/DiscLayerTests.cpp
+++ b/Tests/Layers/DiscLayerTests.cpp
@@ -86,7 +86,7 @@ namespace Test {
     }
 
     /// Unit test for testing Layer properties
-    BOOST_AUTO_TEST_CASE(LayerProperties /*, *utf::expected_failures(1)*/)
+    BOOST_AUTO_TEST_CASE(DiscLayerProperties /*, *utf::expected_failures(1)*/)
     {
       Translation3D translation{0., 1., 2.};
       auto pTransform = std::make_shared<const Transform3D>(translation);
diff --git a/Tests/Layers/LayerStub.hpp b/Tests/Layers/LayerStub.hpp
index afdec4a74..8b7fa990a 100644
--- a/Tests/Layers/LayerStub.hpp
+++ b/Tests/Layers/LayerStub.hpp
@@ -13,6 +13,8 @@
 
 namespace Acts {
 /// Layer derived class stub
+///Note: Layer classes in general have a static 'create' factory method, but nothing
+///in the baseclasses mandates this.
 class LayerStub : virtual public SurfaceStub, public Layer
 {
 public:
@@ -50,6 +52,12 @@ public:
   {
     return (*this);
   }
+  
+  /// simply return true to show a method can be called on the constructed object
+  bool
+  constructedOk() const {
+    return true;
+  }
 
   /// Other methods have implementation in baseclass
   /// templated 'onLayer()' from baseclass ?
diff --git a/Tests/Layers/LayerTests.cpp b/Tests/Layers/LayerTests.cpp
index 639978309..6972e5e08 100644
--- a/Tests/Layers/LayerTests.cpp
+++ b/Tests/Layers/LayerTests.cpp
@@ -43,7 +43,7 @@ namespace Test {
       //
       /// Minimum possible construction (default constructor is deleted)
       LayerStub minallyConstructed(nullptr);
-      BOOST_TEST(minallyConstructed.layerType() == passive);
+      BOOST_TEST(minallyConstructed.constructedOk());
       /// Need an approach descriptor for the next level of complexity:
       const std::vector<const Surface*> aSurfaces{new SurfaceStub(),
                                                   new SurfaceStub()};
@@ -53,7 +53,7 @@ namespace Test {
       LayerStub    approachDescriptorConstructed(
           nullptr, thickness, std::move(ad));
       /// Construction with (minimal) approach descriptor
-      BOOST_TEST(approachDescriptorConstructed.layerType() == passive);
+      BOOST_TEST(approachDescriptorConstructed.constructedOk());
       // Copy construction is deleted
     }
 
diff --git a/Tests/Layers/NavigationLayerTests.cpp b/Tests/Layers/NavigationLayerTests.cpp
new file mode 100644
index 000000000..86bb8b698
--- /dev/null
+++ b/Tests/Layers/NavigationLayerTests.cpp
@@ -0,0 +1,79 @@
+// This file is part of the ACTS project.
+//
+// Copyright (C) 2016 ACTS project team
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#define BOOST_TEST_MODULE Layer Tests
+
+#include <boost/test/included/unit_test.hpp>
+// leave blank line
+
+#include <boost/test/data/test_case.hpp>
+// leave blank line
+
+#include <boost/test/output_test_stream.hpp>
+// leave blank line
+
+//#include <limits>
+#include "ACTS/Layers/NavigationLayer.hpp"
+#include "ACTS/Surfaces/ConeBounds.hpp"
+//#include "ACTS/Utilities/Definitions.hpp"
+#include "ACTS/EventData/SingleTrackParameters.hpp"
+#include "ACTS/Layers/GenericApproachDescriptor.hpp"
+#include "ACTS/Tools/SurfaceArrayCreator.hpp"
+#include "ACTS/Volumes/CuboidVolumeBounds.hpp"
+#include "LayerStub.hpp"
+
+using boost::test_tools::output_test_stream;
+namespace utf = boost::unit_test;
+
+namespace Acts {
+
+namespace Test {
+  namespace Layers {
+    BOOST_AUTO_TEST_SUITE(Layers);
+
+    /// Unit test for creating compliant/non-compliant NavigationLayer object
+    BOOST_AUTO_TEST_CASE(NavigationLayerConstruction)
+    {
+      // default constructor, copy and assignment are all deleted
+      auto         pSurface = std::unique_ptr<const Surface> (new SurfaceStub());   
+      auto         pNavigationLayer = NavigationLayer::create(std::move(pSurface));
+      BOOST_TEST(pNavigationLayer->layerType() == LayerType::navigation);
+      // next level: with thickness
+      const double thickness=0.1;
+      auto         pSurface2 = std::unique_ptr<const Surface> (new SurfaceStub());
+      auto         pThickNavigationLayer = NavigationLayer::create(std::move(pSurface2),thickness);
+      BOOST_TEST(pThickNavigationLayer->layerType() == LayerType::navigation);
+    }
+
+    /// Unit test for testing NavigationLayer properties
+    BOOST_AUTO_TEST_CASE(NavigationLayerProperties,  *utf::expected_failures(1))
+    {
+      const double thickness=0.1;
+      auto         pSurface = std::unique_ptr<const Surface> (new SurfaceStub());
+      auto rawSurfacePtr = pSurface.get();
+      auto         pNavigationLayer = NavigationLayer::create(std::move(pSurface),thickness);
+      BinningValue b{BinningValue::binZ};
+      Vector3D origin{0.,0.,0.};
+      //binningPosition(), needs a better test
+      BOOST_TEST(pNavigationLayer->binningPosition(b) == origin);
+      //surfaceRepresentation() [looks dangerous]
+      BOOST_TEST(rawSurfacePtr == &(pNavigationLayer->surfaceRepresentation()));
+      //isOnLayer()
+      BOOST_CHECK(pNavigationLayer->isOnLayer(origin,true));
+      //isOnLayer()
+      Vector3D crazyPosition{1000.,10000.,std::nan("")};
+      BOOST_CHECK(pNavigationLayer->isOnLayer(crazyPosition,true) == false);
+      //resolve()
+      BOOST_CHECK(pNavigationLayer->resolve(true, true, true) == false);
+    }
+
+    BOOST_AUTO_TEST_SUITE_END();
+  }  // end of namespace Layers
+}  // end of namespace Test
+
+}  // end of namespace Acts
diff --git a/Tests/Layers/PlaneLayerTests.cpp b/Tests/Layers/PlaneLayerTests.cpp
index 807773a46..fd625da48 100644
--- a/Tests/Layers/PlaneLayerTests.cpp
+++ b/Tests/Layers/PlaneLayerTests.cpp
@@ -87,7 +87,7 @@ namespace Test {
     }
 
     /// Unit test for testing Layer properties
-    BOOST_AUTO_TEST_CASE(LayerProperties /*, *utf::expected_failures(1)*/)
+    BOOST_AUTO_TEST_CASE(PlaneLayerProperties /*, *utf::expected_failures(1)*/)
     {
       Translation3D translation{0., 1., 2.};
       auto pTransform = std::make_shared<const Transform3D>(translation);
-- 
GitLab