-
Notifications
You must be signed in to change notification settings - Fork 0
/
condition_parser_test.cpp
86 lines (83 loc) · 4.07 KB
/
condition_parser_test.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
80
81
82
83
84
85
86
//
// condition_parser_test.cpp
// DataBaseCourseProject
//
// Created by Sergei Ziuzev on 3/17/22.
// Copyright © 2022 Sergei Ziuzev. All rights reserved.
//
#include "headers/condition_parser.hpp"
#include "headers/test_runner.hpp"
#include <sstream>
//using namespace std;
void TestParseCondition() {
{
std::istringstream is("date != 2017-11-18");
std::shared_ptr<Node> root = ParseCondition(is);
Assert(root->Evaluate({2017, 1, 1}, ""), "Parse condition 1");
Assert(!root->Evaluate({2017, 11, 18}, ""), "Parse condition 2");
}
{
std::istringstream is(R"(event == "sport event")");
std::shared_ptr<Node> root = ParseCondition(is);
Assert(root->Evaluate({2017, 1, 1}, "sport event"), "Parse condition 3");
Assert(!root->Evaluate({2017, 1, 1}, "holiday"), "Parse condition 4");
}
{
std::istringstream is("date >= 2017-01-01 AND date < 2017-07-01");
std::shared_ptr<Node> root = ParseCondition(is);
Assert(root->Evaluate({2017, 1, 1}, ""), "Parse condition 5");
Assert(root->Evaluate({2017, 3, 1}, ""), "Parse condition 6");
Assert(root->Evaluate({2017, 6, 30}, ""), "Parse condition 7");
Assert(!root->Evaluate({2017, 7, 1}, ""), "Parse condition 8");
Assert(!root->Evaluate({2016, 12, 31}, ""), "Parse condition 9");
}
{
std::istringstream is(R"(event != "sport event" AND event != "Wednesday")");
std::shared_ptr<Node> root = ParseCondition(is);
Assert(root->Evaluate({2017, 1, 1}, "holiday"), "Parse condition 10");
Assert(!root->Evaluate({2017, 1, 1}, "sport event"), "Parse condition 11");
Assert(!root->Evaluate({2017, 1, 1}, "Wednesday"), "Parse condition 12");
}
{
std::istringstream is(R"(event == "holiday AND date == 2017-11-18")");
std::shared_ptr<Node> root = ParseCondition(is);
Assert(!root->Evaluate({2017, 11, 18}, "holiday"), "Parse condition 13");
Assert(!root->Evaluate({2017, 11, 18}, "work day"), "Parse condition 14");
Assert(root->Evaluate({1, 1, 1}, "holiday AND date == 2017-11-18"), "Parse condition 15");
}
{
std::istringstream is(R"(((event == "holiday" AND date == 2017-01-01)))");
std::shared_ptr<Node> root = ParseCondition(is);
Assert(root->Evaluate({2017, 1, 1}, "holiday"), "Parse condition 16");
Assert(!root->Evaluate({2017, 1, 2}, "holiday"), "Parse condition 17");
}
{
std::istringstream is(R"(date > 2017-01-01 AND (event == "holiday" OR date < 2017-07-01))");
std::shared_ptr<Node> root = ParseCondition(is);
Assert(!root->Evaluate({2016, 1, 1}, "holiday"), "Parse condition 18");
Assert(root->Evaluate({2017, 1, 2}, "holiday"), "Parse condition 19");
Assert(root->Evaluate({2017, 1, 2}, "workday"), "Parse condition 20");
Assert(!root->Evaluate({2018, 1, 2}, "workday"), "Parse condition 21");
}
{
std::istringstream is(R"(date > 2017-01-01 AND event == "holiday" OR date < 2017-07-01)");
std::shared_ptr<Node> root = ParseCondition(is);
Assert(root->Evaluate({2016, 1, 1}, "event"), "Parse condition 22");
Assert(root->Evaluate({2017, 1, 2}, "holiday"), "Parse condition 23");
Assert(root->Evaluate({2017, 1, 2}, "workday"), "Parse condition 24");
Assert(!root->Evaluate({2018, 1, 2}, "workday"), "Parse condition 25");
}
{
std::istringstream is(R"(((date == 2017-01-01 AND event == "holiday")))");
std::shared_ptr<Node> root = ParseCondition(is);
Assert(root->Evaluate({2017, 1, 1}, "holiday"), "Parse condition 26");
Assert(!root->Evaluate({2017, 1, 2}, "holiday"), "Parse condition 27");
}
{
std::istringstream is(R"(((event == "2017-01-01" OR date > 2016-01-01)))");
std::shared_ptr<Node> root = ParseCondition(is);
Assert(root->Evaluate({1, 1, 1}, "2017-01-01"), "Parse condition 28");
Assert(!root->Evaluate({2016, 1, 1}, "event"), "Parse condition 29");
Assert(root->Evaluate({2016, 1, 2}, "event"), "Parse condition 30");
}
}