Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add preliminary tests for Configuration
authorMaxwell Pirtle <maxwellpirtle@gmail.com>
Wed, 22 Feb 2023 12:09:50 +0000 (13:09 +0100)
committerMaxwell Pirtle <maxwellpirtle@gmail.com>
Wed, 22 Feb 2023 12:09:50 +0000 (13:09 +0100)
src/mc/explo/udpor/Configuration.cpp
src/mc/explo/udpor/Configuration.hpp
src/mc/explo/udpor/Configuration_test.cpp [new file with mode: 0644]
tools/cmake/Tests.cmake

index d6e42d3..ae6fb54 100644 (file)
 
 namespace simgrid::mc::udpor {
 
+Configuration::Configuration(std::initializer_list<UnfoldingEvent*> events) : Configuration(EventSet(std::move(events)))
+{
+}
+
+Configuration::Configuration(EventSet events) : events_(events)
+{
+  if (!events_.is_valid_configuration()) {
+    throw std::invalid_argument("The events do not form a valid configuration");
+  }
+}
+
 void Configuration::add_event(UnfoldingEvent* e)
 {
   this->events_.insert(e);
   this->newest_event = e;
 
+  // Preserves the property that the configuration is valid
   History history(e);
   if (!this->events_.contains(history)) {
     throw std::invalid_argument("The newly added event has dependencies "
index 27595e5..18089fa 100644 (file)
@@ -9,6 +9,8 @@
 #include "src/mc/explo/udpor/EventSet.hpp"
 #include "src/mc/explo/udpor/udpor_forward.hpp"
 
+#include <initializer_list>
+
 namespace simgrid::mc::udpor {
 
 class Configuration {
@@ -18,8 +20,8 @@ public:
   Configuration& operator=(Configuration const&) = default;
   Configuration(Configuration&&)                 = default;
 
-  Configuration(EventSet events) : events_(events) {}
-  Configuration(EventSet&& events) : events_(events) {}
+  Configuration(EventSet events);
+  Configuration(std::initializer_list<UnfoldingEvent*> events);
 
   auto begin() const { return this->events_.begin(); }
   auto end() const { return this->events_.end(); }
diff --git a/src/mc/explo/udpor/Configuration_test.cpp b/src/mc/explo/udpor/Configuration_test.cpp
new file mode 100644 (file)
index 0000000..b8c4ad2
--- /dev/null
@@ -0,0 +1,80 @@
+/* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved.               */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "src/3rd-party/catch.hpp"
+#include "src/mc/explo/udpor/Configuration.hpp"
+#include "src/mc/explo/udpor/EventSet.hpp"
+#include "src/mc/explo/udpor/UnfoldingEvent.hpp"
+
+using namespace simgrid::mc::udpor;
+
+TEST_CASE("simgrid::mc::udpor::Configuration: Constructing Configurations")
+{
+  SECTION("Creating a configuration without events")
+  {
+    Configuration C;
+    REQUIRE(C.get_events().empty());
+    REQUIRE(C.get_latest_event() == nullptr);
+  }
+
+  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}));
+
+    // 5 choose 1 = 5 tests
+    REQUIRE_THROWS_AS(Configuration({&e2}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e3}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e4}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e5}), std::invalid_argument);
+
+    // 5 choose 2 = 10 tests
+    REQUIRE_NOTHROW(Configuration({&e1, &e2}));
+    REQUIRE_THROWS_AS(Configuration({&e1, &e3}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e1, &e4}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e1, &e5}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e2, &e3}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e2, &e4}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e2, &e5}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e3, &e4}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e3, &e5}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e4, &e5}), std::invalid_argument);
+
+    // 5 choose 3 = 10 tests
+    REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3}));
+    REQUIRE_THROWS_AS(Configuration({&e1, &e2, &e4}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e1, &e2, &e5}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e1, &e3, &e4}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e1, &e3, &e5}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e1, &e4, &e5}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e2, &e3, &e4}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e2, &e3, &e5}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e2, &e4, &e5}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e3, &e4, &e5}), std::invalid_argument);
+
+    // 5 choose 4 = 5 tests
+    REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e4}));
+    REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e5}));
+    REQUIRE_THROWS_AS(Configuration({&e1, &e2, &e4, &e5}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e1, &e3, &e4, &e5}), std::invalid_argument);
+    REQUIRE_THROWS_AS(Configuration({&e2, &e3, &e4, &e5}), std::invalid_argument);
+
+    // 5 choose 5 = 1 test
+    REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e4, &e5}));
+  }
+}
index 992afa6..e469571 100644 (file)
@@ -133,7 +133,8 @@ if (SIMGRID_HAVE_MC)
                                src/mc/explo/udpor/EventSet_test.cpp
                                src/mc/explo/udpor/Unfolding_test.cpp
                                src/mc/explo/udpor/UnfoldingEvent_test.cpp
-                               src/mc/explo/udpor/History_test.cpp)
+                               src/mc/explo/udpor/History_test.cpp
+                               src/mc/explo/udpor/Configuration_test.cpp)
 else()
   set(EXTRA_DIST ${EXTRA_DIST} src/mc/sosp/Snapshot_test.cpp src/mc/sosp/PageStore_test.cpp)
 endif()