Skip to content

Commit

Permalink
Cleaned up with one exception
Browse files Browse the repository at this point in the history
  • Loading branch information
oppiz committed Mar 10, 2019
1 parent f20692b commit ba06690
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 42 deletions.
1 change: 1 addition & 0 deletions include/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace elma {
Client& client() { return _client; }

private:
const int Priority_min = -5, Priority_max = 15;
vector<Process *> _processes;
map<string, Channel *> _channels;
map<string, vector<std::function<void(Event&)>>> event_handlers;
Expand Down
4 changes: 2 additions & 2 deletions src/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace elma {
_processes.push_back(&process);
process._manager_ptr = this;

if (-5 > process._priority || process._priority > 15 ){
if (Priority_min > process._priority || process._priority > Priority_max ){
throw Exception("Priority must be between -5(low priority) and 15(high priority)");
}

Expand Down Expand Up @@ -140,7 +140,7 @@ namespace elma {
//! \return A reference to the manager, for chaining
Manager& Manager::set_priority(Process& process, int priority) {

if (-5 <= priority && priority <= 15 ){
if (Priority_min <= priority && priority <= Priority_max ){
process._priority = priority;
sort_processes();
}else{
Expand Down
45 changes: 5 additions & 40 deletions test/priority.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace {
#define SLEEP(__ms__) std::this_thread::sleep_for(std::chrono::milliseconds(__ms__))
#define MS(__ms__) high_resolution_clock::duration(milliseconds(__ms__))

const int Priority_min = -5, Priority_max = 15;

TEST(Priority, basic) {

static vector<string> test1;
Expand All @@ -24,7 +26,6 @@ namespace {
void start() {}
void update() {
test1.push_back("james");
//std::cout << "james" << "\n";
}
void stop() {}

Expand All @@ -37,7 +38,6 @@ namespace {
void start() {}
void update() {
test1.push_back("lilly");
//std::cout << "lilly" << "\n";
}
void stop() {}

Expand All @@ -50,7 +50,6 @@ namespace {
void start() {}
void update() {
test1.push_back("boby");
//std::cout << "boby" << "\n";
}
void stop() {}

Expand All @@ -67,7 +66,6 @@ namespace {
.schedule(lily, MS(30))
.schedule(boby, MS(30));

//m.SetPriority("james", 3);
m.init().run(MS(100));
EXPECT_EQ(test1, ans1);

Expand All @@ -85,7 +83,6 @@ namespace {
void start() {}
void update() {
test1.push_back("james");
//std::cout << "james" << "\n";
}
void stop() {}

Expand All @@ -98,7 +95,6 @@ namespace {
void start() {}
void update() {
test1.push_back("lilly");
//std::cout << "lilly" << "\n";
}
void stop() {}

Expand All @@ -111,7 +107,6 @@ namespace {
void start() {}
void update() {
test1.push_back("boby");
//std::cout << "boby" << "\n";
}
void stop() {}

Expand All @@ -137,27 +132,6 @@ namespace {

}

//This is no longer valid now that the process is passed not its name
/* TEST(Priority, NoProcess) {
class Tester: public elma::Process {
public:
Tester(string name, int n = 0) : Process(name, n) {}
void init() {}
void start() {}
void update() {}
void stop() {}
};
elma::Manager m;
Tester james("james",0);
m.schedule(james, MS(30));
//EXPECT_ANY_THROW(m.set_priority("jams", 3));
}*/

TEST(Priority, LookSort) {

Expand All @@ -166,10 +140,7 @@ namespace {
Tester(string name, int n = 0) : Process(name, n) {}
void init() {}
void start() {}
void update() {
//test1.push_back("james");
//std::cout << "james" << "\n";
}
void update() {}
void stop() {}

};
Expand All @@ -179,10 +150,7 @@ namespace {
Tester2(string name, int n = 0) : Process(name, n) {}
void init() {}
void start() {}
void update() {
//test1.push_back("lilly");
//std::cout << "lilly" << "\n";
}
void update() {}
void stop() {}

};
Expand All @@ -192,10 +160,7 @@ namespace {
Tester3(string name, int n = 0) : Process(name, n) {}
void init() {}
void start() {}
void update() {
//test1.push_back("boby");
//std::cout << "boby" << "\n";
}
void update() {}
void stop() {}

};
Expand Down

0 comments on commit ba06690

Please sign in to comment.