forked from luteberget/simcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
95 lines (73 loc) · 2.23 KB
/
test.cpp
File metadata and controls
95 lines (73 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <gtest/gtest.h>
#include "simcpp.h"
class Awaiter : public simcpp::Process {
public:
Awaiter(simcpp::SimulationPtr sim, simcpp::EventPtr event)
: Process(sim), event(event) {}
bool Run() override {
PT_BEGIN();
PROC_WAIT_FOR(event);
PT_END();
}
private:
simcpp::EventPtr event;
};
TEST(SimulationTest, AnyOfEmpty) {
auto sim = simcpp::Simulation::create();
auto any_of = sim->any_of({});
auto awaiter = sim->start_process<Awaiter>(any_of);
ASSERT_EQ(sim->get_now(), 0);
sim->advance_to(awaiter);
ASSERT_EQ(sim->get_now(), 0);
}
TEST(SimulationTest, AnyOfTriggered) {
auto sim = simcpp::Simulation::create();
auto event1 = sim->timeout(5);
auto event2 = sim->event();
event2->trigger();
auto any_of = sim->any_of({event1, event2});
auto awaiter = sim->start_process<Awaiter>(any_of);
ASSERT_EQ(sim->get_now(), 0);
sim->advance_to(awaiter);
ASSERT_EQ(sim->get_now(), 0);
}
TEST(SimulationTest, AnyOfPending) {
auto sim = simcpp::Simulation::create();
auto event1 = sim->timeout(5);
auto event2 = sim->timeout(10);
auto any_of = sim->any_of({event1, event2});
auto awaiter = sim->start_process<Awaiter>(any_of);
ASSERT_EQ(sim->get_now(), 0);
sim->advance_to(awaiter);
ASSERT_EQ(sim->get_now(), 5);
}
TEST(SimulationTest, AllOfEmpty) {
auto sim = simcpp::Simulation::create();
auto all_of = sim->all_of({});
auto awaiter = sim->start_process<Awaiter>(all_of);
ASSERT_EQ(sim->get_now(), 0);
sim->advance_to(awaiter);
ASSERT_EQ(sim->get_now(), 0);
}
TEST(SimulationTest, AllOfTriggered) {
auto sim = simcpp::Simulation::create();
auto event1 = sim->event();
event1->trigger();
auto event2 = sim->event();
event2->trigger();
auto all_of = sim->all_of({event1, event2});
auto awaiter = sim->start_process<Awaiter>(all_of);
ASSERT_EQ(sim->get_now(), 0);
sim->advance_to(awaiter);
ASSERT_EQ(sim->get_now(), 0);
}
TEST(SimulationTest, AllOfPending) {
auto sim = simcpp::Simulation::create();
auto event1 = sim->timeout(5);
auto event2 = sim->timeout(10);
auto all_of = sim->all_of({event1, event2});
auto awaiter = sim->start_process<Awaiter>(all_of);
ASSERT_EQ(sim->get_now(), 0);
sim->advance_to(awaiter);
ASSERT_EQ(sim->get_now(), 10);
}