Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add tests for EventSet equality
authorMaxwell Pirtle <maxwellpirtle@gmail.com>
Mon, 20 Feb 2023 15:31:58 +0000 (16:31 +0100)
committerMaxwell Pirtle <maxwellpirtle@gmail.com>
Mon, 20 Feb 2023 15:31:58 +0000 (16:31 +0100)
src/mc/explo/udpor/EventSet.hpp
src/mc/explo/udpor/EventSet_test.cpp

index 1808eae..b7e2ef5 100644 (file)
@@ -49,8 +49,8 @@ public:
   bool contains(UnfoldingEvent*) const;
   bool is_subset_of(const EventSet&) const;
 
-  bool operator==(const EventSet& other) { return this->events_ == other.events_; }
-  bool operator!=(const EventSet& other) { return this->events_ != other.events_; }
+  bool operator==(const EventSet& other) const { return this->events_ == other.events_; }
+  bool operator!=(const EventSet& other) const { return this->events_ != other.events_; }
 };
 
 } // namespace simgrid::mc::udpor
index f5e363d..e643408 100644 (file)
@@ -180,13 +180,133 @@ TEST_CASE("simgrid::mc::udpor::EventSet: Deletions")
   }
 }
 
-TEST_CASE("simgrid::mc::udpor::EventSet: Set Equality") {}
+TEST_CASE("simgrid::mc::udpor::EventSet: Set Equality")
+{
+  UnfoldingEvent e1, e2, e3, e4;
+  EventSet A{&e1, &e2, &e3}, B{&e1, &e2, &e3}, C{&e1, &e2, &e3};
+
+  SECTION("Equality implies containment")
+  {
+    REQUIRE(A == B);
+
+    for (const auto& e : A) {
+      REQUIRE(B.contains(e));
+    }
+
+    for (const auto& e : B) {
+      REQUIRE(A.contains(e));
+    }
+  }
+
+  SECTION("Containment implies equality")
+  {
+    for (const auto& e : A) {
+      REQUIRE(B.contains(e));
+    }
+
+    for (const auto& e : C) {
+      REQUIRE(C.contains(e));
+    }
+
+    REQUIRE(A == C);
+  }
+
+  SECTION("Equality is an equivalence relation")
+  {
+    // Reflexive
+    REQUIRE(A == A);
+    REQUIRE(B == B);
+    REQUIRE(C == C);
+
+    // Symmetric
+    REQUIRE(A == B);
+    REQUIRE(B == A);
+    REQUIRE(A == C);
+    REQUIRE(C == A);
+    REQUIRE(B == C);
+    REQUIRE(C == B);
+
+    // Transitive
+    REQUIRE(A == B);
+    REQUIRE(B == C);
+    REQUIRE(A == C);
+  }
+
+  SECTION("Equality after copy (assignment + constructor)")
+  {
+    EventSet A_copy = A;
+    EventSet A_copy2(A);
+
+    REQUIRE(A == A_copy);
+    REQUIRE(A == A_copy2);
+  }
+
+  SECTION("Equality after move constructor")
+  {
+    EventSet A_copy = A;
+    EventSet A_move(std::move(A));
+    REQUIRE(A_move == A_copy);
+  }
+
+  SECTION("Equality after move-assignment")
+  {
+    EventSet A_copy = A;
+    EventSet A_move = std::move(A);
+    REQUIRE(A_move == A_copy);
+  }
+}
 
 TEST_CASE("simgrid::mc::udpor::EventSet: Unions and Set Difference")
 {
   UnfoldingEvent e1, e2, e3, e4;
 
-  EventSet A{&e1, &e2, &e3}, B{&e2, &e3, &e4}, C{&e2, &e3, &e4};
+  // C = A + B
+  EventSet A{&e1, &e2, &e3}, B{&e2, &e3, &e4}, C{&e1, &e2, &e3, &e4}, D{&e1, &e3};
+
+  SECTION("Unions with no effect")
+  {
+    EventSet A_copy = A;
+
+    SECTION("Self union")
+    {
+      // A = A union A
+      EventSet A_union = A.make_union(A);
+      REQUIRE(A == A_copy);
+
+      A.form_union(A);
+      REQUIRE(A == A_copy);
+    }
+
+    SECTION("Union with empty set")
+    {
+      // A = A union empty set
+      EventSet A_union = A.make_union(EventSet());
+      REQUIRE(A == A_union);
+
+      A.form_union(EventSet());
+      REQUIRE(A == A_copy);
+    }
+
+    SECTION("Union with an equivalent set")
+    {
+      // A = A union B if B == A
+      EventSet A_equiv{&e1, &e2, &e3};
+      REQUIRE(A == A_equiv);
+
+      EventSet A_union = A.make_union(A_equiv);
+      REQUIRE(A_union == A_copy);
 
-  SECTION("Self-union (A union A)") {}
+      A.form_union(A_equiv);
+      REQUIRE(A == A_copy);
+    }
+  }
+
+  SECTION("Unions with overlaps")
+  {
+    EventSet A_union_B = A.make_union(B);
+    REQUIRE(A_union_B == C);
+
+    A.form_union(B);
+    REQUIRE(A == C);
+  }
 }
\ No newline at end of file