-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_partC.cpp
79 lines (67 loc) · 2.39 KB
/
test_partC.cpp
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
#include "base_event.h"
#include "closed_event.h"
#include "custom_event.h"
#include "date_wrap.h"
#include "event_container.h"
#include "exceptions.h"
#include "festival.h"
#include "one_time_event.h"
#include "open_event.h"
#include "recurring_event.h"
#include "schedule.h"
#include <cstdlib>
#include <iostream>
void test1(const mtm::Schedule& schedule) { schedule.printAllEvents(); }
void test2(const mtm::Schedule& schedule) {
schedule.printEventDetails(mtm::DateWrap(27, 12, 2020), "Publish Test");
}
void test3(const mtm::Schedule& schedule) {
schedule.printEventDetails(mtm::DateWrap(5, 1, 2021), "Update Q&A");
}
void test4(const mtm::Schedule& schedule) { schedule.printMonthEvents(12, 2020); }
class MutatingPredicate {
int counter = 0;
public:
bool operator()(const mtm::BaseEvent& event) {
++counter;
return true;
}
};
void test5(const mtm::Schedule& schedule) {
schedule.printSomeEvents(MutatingPredicate(), true);
}
typedef void (*Test)(const mtm::Schedule&);
const Test tests[] = {test1, test2, test3, test4, test5};
int main(int argc, char* argv[]) {
mtm::Schedule schedule;
schedule.addEvents(mtm::OneTimeEvent<mtm::OpenEvent>(
mtm::DateWrap(27, 12, 2020), "Publish Test"));
mtm::RecurringEvent<mtm::ClosedEvent> closed(mtm::DateWrap(20, 12, 2020),
"Update Q&A", 6, 5);
for (mtm::BaseEvent& event : closed) {
mtm::ClosedEvent& closed_event = dynamic_cast<mtm::ClosedEvent&>(event);
closed_event.addInvitee(1337);
closed_event.addInvitee(850);
closed_event.addInvitee(1500);
}
schedule.addEvents(closed);
schedule.registerToEvent(mtm::DateWrap(20, 12, 2020), "Update Q&A", 850);
schedule.registerToEvent(mtm::DateWrap(20, 12, 2020), "Update Q&A", 1500);
schedule.registerToEvent(mtm::DateWrap(5, 1, 2021), "Update Q&A", 850);
schedule.registerToEvent(mtm::DateWrap(5, 1, 2021), "Update Q&A", 1500);
schedule.unregisterFromEvent(mtm::DateWrap(20, 12, 2020), "Update Q&A",
1500);
if (argc < 2) {
test1(schedule);
test2(schedule);
test3(schedule);
test4(schedule);
test5(schedule);
} else if (argc > 2) {
std::cout << "invalid arguments" << std::endl;
} else {
int i = std::atoi(argv[1]);
tests[i - 1](schedule);
}
return 0;
}