Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add tests for adding events to configurations
authorMaxwell Pirtle <maxwellpirtle@gmail.com>
Wed, 22 Feb 2023 12:40:08 +0000 (13:40 +0100)
committerMaxwell Pirtle <maxwellpirtle@gmail.com>
Wed, 22 Feb 2023 12:40:08 +0000 (13:40 +0100)
src/mc/explo/udpor/Configuration.cpp
src/mc/explo/udpor/Configuration.hpp
src/mc/explo/udpor/Configuration_test.cpp

index ae6fb54..46bc8c5 100644 (file)
@@ -24,6 +24,14 @@ Configuration::Configuration(EventSet events) : events_(events)
 
 void Configuration::add_event(UnfoldingEvent* e)
 {
+  if (e == nullptr) {
+    throw std::invalid_argument("Expected a nonnull `UnfoldingEvent*` but received NULL instead");
+  }
+
+  if (this->events_.contains(e)) {
+    return;
+  }
+
   this->events_.insert(e);
   this->newest_event = e;
 
index 18089fa..a1d37c5 100644 (file)
@@ -38,6 +38,10 @@ public:
    * valid, i.e. that the newly added event's dependencies are contained
    * within the configuration.
    *
+   * @param e the event to add to the configuration. If the event is
+   * already a part of the configuration, calling this method has no
+   * effect.
+   *
    * @throws an invalid argument exception is raised should the event
    * be missing one of its dependencies
    *
@@ -53,7 +57,7 @@ public:
    * we shouldn't focus so much on this (let alone the additional benefit of the
    * assertions)
    */
-  void add_event(UnfoldingEvent*);
+  void add_event(UnfoldingEvent* e);
 
 private:
   /**
index b8c4ad2..3ba2795 100644 (file)
@@ -12,6 +12,19 @@ using namespace simgrid::mc::udpor;
 
 TEST_CASE("simgrid::mc::udpor::Configuration: Constructing Configurations")
 {
+  // The following tests concern the given event structure:
+  //                e1
+  //              /
+  //            e2
+  //           /
+  //          e3
+  //         /  /
+  //        e4   e5
+  UnfoldingEvent e1;
+  UnfoldingEvent e2{&e1};
+  UnfoldingEvent e3{&e2};
+  UnfoldingEvent e4{&e3}, e5{&e3};
+
   SECTION("Creating a configuration without events")
   {
     Configuration C;
@@ -21,19 +34,6 @@ TEST_CASE("simgrid::mc::udpor::Configuration: Constructing Configurations")
 
   SECTION("Creating a configuration with events")
   {
-    // The following tests concern the given event structure:
-    //                e1
-    //              /
-    //            e2
-    //           /
-    //          e3
-    //         /  /
-    //        e4   e5
-    UnfoldingEvent e1;
-    UnfoldingEvent e2{&e1};
-    UnfoldingEvent e3{&e2};
-    UnfoldingEvent e4{&e3}, e5{&e3};
-
     // 5 choose 0 = 1 test
     REQUIRE_NOTHROW(Configuration({&e1}));
 
@@ -78,3 +78,45 @@ TEST_CASE("simgrid::mc::udpor::Configuration: Constructing Configurations")
     REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e4, &e5}));
   }
 }
+
+TEST_CASE("simgrid::mc::udpor::Configuration: Adding Events")
+{
+  // The following tests concern the given event structure:
+  //                e1
+  //              /
+  //            e2
+  //           /
+  //         /  /
+  //        e3   e4
+  UnfoldingEvent e1;
+  UnfoldingEvent e2{&e1};
+  UnfoldingEvent e3{&e2};
+  UnfoldingEvent e4{&e2};
+
+  REQUIRE_THROWS_AS(Configuration().add_event(nullptr), std::invalid_argument);
+  REQUIRE_THROWS_AS(Configuration().add_event(&e2), std::invalid_argument);
+  REQUIRE_THROWS_AS(Configuration().add_event(&e3), std::invalid_argument);
+  REQUIRE_THROWS_AS(Configuration().add_event(&e4), std::invalid_argument);
+  REQUIRE_THROWS_AS(Configuration({&e1}).add_event(&e3), std::invalid_argument);
+  REQUIRE_THROWS_AS(Configuration({&e1}).add_event(&e4), std::invalid_argument);
+
+  REQUIRE_NOTHROW(Configuration().add_event(&e1));
+  REQUIRE_NOTHROW(Configuration({&e1}).add_event(&e1));
+  REQUIRE_NOTHROW(Configuration({&e1}).add_event(&e2));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2}).add_event(&e1));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2}).add_event(&e2));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2}).add_event(&e3));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2}).add_event(&e4));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3}).add_event(&e1));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3}).add_event(&e2));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3}).add_event(&e3));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3}).add_event(&e4));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e4}).add_event(&e1));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e4}).add_event(&e2));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e4}).add_event(&e3));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e4}).add_event(&e4));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e4}).add_event(&e1));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e4}).add_event(&e2));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e4}).add_event(&e3));
+  REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e4}).add_event(&e4));
+}