From 6499cddce8d4be60d6dcd60914f196e472b7f439 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Thu, 31 Oct 2019 14:36:32 +0100
Subject: [PATCH] Add CFunctionEmbedderTable unit tests

---
 tests/CMakeLists.txt                  |  1 +
 tests/test_CFunctionEmbedderTable.cpp | 32 +++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 tests/test_CFunctionEmbedderTable.cpp

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index ed9f5564d..04efe7836 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -37,6 +37,7 @@ add_executable (unit_tests
   test_BinaryExpressionProcessor_logic.cpp
   test_BiCGStab.cpp
   test_CFunctionEmbedder.cpp
+  test_CFunctionEmbedderTable.cpp
   test_ContinueProcessor.cpp
   test_ConcatExpressionProcessor.cpp
   test_CRSMatrix.cpp
diff --git a/tests/test_CFunctionEmbedderTable.cpp b/tests/test_CFunctionEmbedderTable.cpp
new file mode 100644
index 000000000..28d15ce0e
--- /dev/null
+++ b/tests/test_CFunctionEmbedderTable.cpp
@@ -0,0 +1,32 @@
+#include <catch2/catch.hpp>
+
+#include <CFunctionEmbedder.hpp>
+#include <CFunctionEmbedderTable.hpp>
+
+TEST_CASE("CFunctionEmbedderTable", "[language]")
+{
+  rang::setControlMode(rang::control::Off);
+
+  CFunctionEmbedderTable table;
+
+  REQUIRE(table.size() == 0);
+
+  std::shared_ptr<ICFunctionEmbedder> embedded_sin = std::make_shared<CFunctionEmbedder<double, double>>(
+    std::function<double(double)>{[](double x) -> double { return std::sin(x); }});
+  table.add(embedded_sin);
+
+  REQUIRE(table.size() == 1);
+
+  std::shared_ptr<ICFunctionEmbedder> embedded_greater = std::make_shared<CFunctionEmbedder<bool, int, int>>(
+    std::function<bool(int, int)>{[](int i, int j) -> bool { return i > j; }});
+  table.add(embedded_greater);
+
+  REQUIRE(table.size() == 2);
+
+  REQUIRE(table[0] == embedded_sin);
+  REQUIRE(table[1] == embedded_greater);
+
+#ifndef NDEBUG
+  REQUIRE_THROWS_AS(table[2], AssertError);
+#endif   // NDEBUG
+}
-- 
GitLab