Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add tests for the Unfolding object
authorMaxwell Pirtle <maxwellpirtle@gmail.com>
Tue, 21 Feb 2023 09:35:37 +0000 (10:35 +0100)
committerMaxwell Pirtle <maxwellpirtle@gmail.com>
Tue, 21 Feb 2023 09:35:37 +0000 (10:35 +0100)
The Unfolding object currently doesn't have much functionality,
so there is not much that needs to be tested with it. It is
effectively a wrapper around a collection of std::unique_ptr.
Eventually, more functionality may be added when more of the
implementation of UDPOR is added, although its use will still
be quite limited even later

src/mc/explo/udpor/Unfolding.cpp
src/mc/explo/udpor/Unfolding_test.cpp

index 68fff48..abe9f26 100644 (file)
@@ -21,7 +21,7 @@ void Unfolding::insert(std::unique_ptr<UnfoldingEvent> e)
 {
   UnfoldingEvent* handle = e.get();
   auto loc               = this->global_events_.find(handle);
-  if (loc == this->global_events_.end()) {
+  if (loc != this->global_events_.end()) {
     // This is bad: someone wrapped the raw event address twice
     // in two different unique ptrs and attempted to
     // insert it into the unfolding...
index 3f004e4..4e6f627 100644 (file)
@@ -6,11 +6,36 @@
 #include "src/3rd-party/catch.hpp"
 #include "src/mc/explo/udpor/Unfolding.hpp"
 
+using namespace simgrid::mc::udpor;
+
 TEST_CASE("simgrid::mc::udpor::Unfolding: Creating an unfolding")
 {
-  using namespace simgrid::mc::udpor;
+  Unfolding unfolding;
+  REQUIRE(unfolding.size() == 0);
+  REQUIRE(unfolding.empty());
+}
 
+TEST_CASE("simgrid::mc::udpor::Unfolding: Inserting and removing events with an unfolding")
+{
   Unfolding unfolding;
-  CHECK(unfolding.empty());
+  auto e1        = std::make_unique<UnfoldingEvent>();
+  auto e2        = std::make_unique<UnfoldingEvent>();
+  auto e1_handle = e1.get();
+  auto e2_handle = e2.get();
+
+  unfolding.insert(std::move(e1));
+  REQUIRE(unfolding.size() == 1);
+  REQUIRE_FALSE(unfolding.empty());
+
+  unfolding.insert(std::move(e2));
+  REQUIRE(unfolding.size() == 2);
+  REQUIRE_FALSE(unfolding.empty());
+
+  unfolding.remove(e1_handle);
+  REQUIRE(unfolding.size() == 1);
+  REQUIRE_FALSE(unfolding.empty());
+
+  unfolding.remove(e2_handle);
   REQUIRE(unfolding.size() == 0);
+  REQUIRE(unfolding.empty());
 }
\ No newline at end of file