Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add preliminary tests for Configuration
[simgrid.git] / src / mc / explo / udpor / Configuration_test.cpp
1 /* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved.               */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/3rd-party/catch.hpp"
7 #include "src/mc/explo/udpor/Configuration.hpp"
8 #include "src/mc/explo/udpor/EventSet.hpp"
9 #include "src/mc/explo/udpor/UnfoldingEvent.hpp"
10
11 using namespace simgrid::mc::udpor;
12
13 TEST_CASE("simgrid::mc::udpor::Configuration: Constructing Configurations")
14 {
15   SECTION("Creating a configuration without events")
16   {
17     Configuration C;
18     REQUIRE(C.get_events().empty());
19     REQUIRE(C.get_latest_event() == nullptr);
20   }
21
22   SECTION("Creating a configuration with events")
23   {
24     // The following tests concern the given event structure:
25     //                e1
26     //              /
27     //            e2
28     //           /
29     //          e3
30     //         /  /
31     //        e4   e5
32     UnfoldingEvent e1;
33     UnfoldingEvent e2{&e1};
34     UnfoldingEvent e3{&e2};
35     UnfoldingEvent e4{&e3}, e5{&e3};
36
37     // 5 choose 0 = 1 test
38     REQUIRE_NOTHROW(Configuration({&e1}));
39
40     // 5 choose 1 = 5 tests
41     REQUIRE_THROWS_AS(Configuration({&e2}), std::invalid_argument);
42     REQUIRE_THROWS_AS(Configuration({&e3}), std::invalid_argument);
43     REQUIRE_THROWS_AS(Configuration({&e4}), std::invalid_argument);
44     REQUIRE_THROWS_AS(Configuration({&e5}), std::invalid_argument);
45
46     // 5 choose 2 = 10 tests
47     REQUIRE_NOTHROW(Configuration({&e1, &e2}));
48     REQUIRE_THROWS_AS(Configuration({&e1, &e3}), std::invalid_argument);
49     REQUIRE_THROWS_AS(Configuration({&e1, &e4}), std::invalid_argument);
50     REQUIRE_THROWS_AS(Configuration({&e1, &e5}), std::invalid_argument);
51     REQUIRE_THROWS_AS(Configuration({&e2, &e3}), std::invalid_argument);
52     REQUIRE_THROWS_AS(Configuration({&e2, &e4}), std::invalid_argument);
53     REQUIRE_THROWS_AS(Configuration({&e2, &e5}), std::invalid_argument);
54     REQUIRE_THROWS_AS(Configuration({&e3, &e4}), std::invalid_argument);
55     REQUIRE_THROWS_AS(Configuration({&e3, &e5}), std::invalid_argument);
56     REQUIRE_THROWS_AS(Configuration({&e4, &e5}), std::invalid_argument);
57
58     // 5 choose 3 = 10 tests
59     REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3}));
60     REQUIRE_THROWS_AS(Configuration({&e1, &e2, &e4}), std::invalid_argument);
61     REQUIRE_THROWS_AS(Configuration({&e1, &e2, &e5}), std::invalid_argument);
62     REQUIRE_THROWS_AS(Configuration({&e1, &e3, &e4}), std::invalid_argument);
63     REQUIRE_THROWS_AS(Configuration({&e1, &e3, &e5}), std::invalid_argument);
64     REQUIRE_THROWS_AS(Configuration({&e1, &e4, &e5}), std::invalid_argument);
65     REQUIRE_THROWS_AS(Configuration({&e2, &e3, &e4}), std::invalid_argument);
66     REQUIRE_THROWS_AS(Configuration({&e2, &e3, &e5}), std::invalid_argument);
67     REQUIRE_THROWS_AS(Configuration({&e2, &e4, &e5}), std::invalid_argument);
68     REQUIRE_THROWS_AS(Configuration({&e3, &e4, &e5}), std::invalid_argument);
69
70     // 5 choose 4 = 5 tests
71     REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e4}));
72     REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e5}));
73     REQUIRE_THROWS_AS(Configuration({&e1, &e2, &e4, &e5}), std::invalid_argument);
74     REQUIRE_THROWS_AS(Configuration({&e1, &e3, &e4, &e5}), std::invalid_argument);
75     REQUIRE_THROWS_AS(Configuration({&e2, &e3, &e4, &e5}), std::invalid_argument);
76
77     // 5 choose 5 = 1 test
78     REQUIRE_NOTHROW(Configuration({&e1, &e2, &e3, &e4, &e5}));
79   }
80 }