-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.cpp
More file actions
109 lines (82 loc) · 2.05 KB
/
Copy pathservice.cpp
File metadata and controls
109 lines (82 loc) · 2.05 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "service.h"
#include <algorithm>
void Service::add(int id, string title, vector<string> prog, string state) {
Task::validate(id,title,prog,state);
repo.validateId(id);
repo.add(Task(id,title,prog,state));
notify();
}
vector<Task> &Service::get_all_ent() {
return repo.get_all();
}
void Service::validateIdd(int id) {
repo.validateId(id);
}
vector<Task> Service::filter(string crit) {
vector<Task> rez;
rez.clear();
for(auto& task: repo.get_all()){
for (auto& el : task.getProgrammers())
{
if (el.find(crit) != -1)
{
rez.push_back(task);
}
}
/* string name=task.getTitle();
if(name.find(crit)!=-1){
rez.push_back(task);
}*/
}
return rez;
}
void Service::changeState(int ind, string new_state) {
repo.change(ind,new_state);
notify();
}
void test_service(){
auto rp=FileRepo{"text.txt"};
auto srv=Service{rp};
assert(srv.get_all_ent().size()==5);
vector<string> prog;
prog.push_back("Seba");
prog.push_back("Stanis");
srv.add(10,"Soft",prog,"open");
assert(srv.get_all_ent().size()==6);
try{
srv.add(1,"Soft",prog,"open");
assert(false);
} catch(DuplicatedIdException& de){
assert(true);
}
try{
srv.add(1,"",prog,"open");
assert(false);
} catch(ValidationException& ve){
assert(true);
}
try{
srv.add(1,"Soft",prog,"");
assert(false);
} catch(ValidationException& ve){
assert(true);
}
try{
prog.push_back(prog[0]);
prog.push_back(prog[0]);
prog.push_back(prog[0]);
srv.add(1,"Soft",prog,"open");
assert(false);
} catch(ValidationException& ve){
assert(true);
}
try{
prog.clear();
srv.add(1,"Soft",prog,"open");
assert(false);
} catch(ValidationException& ve){
assert(true);
}
auto rez=srv.filter("Seba");
assert(rez.size()==4);
}