#include gtest plz
class Skill {
public:
enum class SID { NONE,
EAT, SLEEP, BEAT_DOUDOU,
LADY_READ /*hard skill, contact you@are.lying.com if feel confident*/ };
Skill(SID sid) : m_sid(sid) {};
private:
const SID m_sid = SID::NONE;
};
struct Solution {
public:
Solution(bool solved) : m_solved(solved) { };
Solution(const Solution& others) = default;
Solution& operator=(const Solution& others) = default;
bool Solved() const { return m_solved; }
private:
bool m_solved { false };
};
class Problem {
public:
Problem() = delete;
Problem(std::initializer_listconst & skills): m_desiredSkills(skills) { }
struct WorkTable {
WorkTable(size_t size) : m_result(size, false) {}
bool Done() const { return std::find(begin(m_result), end(m_result), false) == end(m_result); }
void SetSolved(size_t index){ m_result[index] = true; }
vector m_result;
};
WorkTable NewWorkTable() const { return WorkTable(m_mustHaveSkills.size()); }
void Research(const Skill::SID sid, WorkTable& worktable) const {
auto itor = m_mustHaveSkills.find(sid);
if(itor != m_mustHaveSkills.end()) {
worktable.SetSolved(abs(std::distance(m_mustHaveSkills.begin(), itor)));
}
}
void Research(const std::unordered_set& skills, WorkTable& worktable) const {
for(auto sid : skills) {
Research(sid, worktable);
}
}
private:
std::unordered_set m_mustHaveSkills;
};
class Engineer {
public:
Engineer() = delete; // no skill? not a engineer.
Engineer(std::initializer_listconst & skills) : m_skills(skills) { };
void Work(const Problem& problem, Problem::WorkTable& worktable) const {
problem.Research(m_skills, worktable);
}
private:
std::unordered_set m_skills;
};
class Team {
public:
Team() = delete;
Team(std::initializer_listconst & engineers) : m_engineers(engineers) { };
Solution Work(const Problem& problem) const {
auto worktable = problem.NewWorkTable();
for(auto& e : m_engineers) {
e.Work(problem, worktable);
if(worktable.Done()) {
return Solution(true);
}
}
return Solution(false);
}
private:
std::vector m_engineers;
};
TEST(Q0007_SIMPLE, TEAM1)
{
Team team_1 {
{ {Skill::SID::EAT} },
{ {Skill::SID::SLEEP } },
{ {Skill::SID::EAT, Skill::SID::SLEEP } },
{ {Skill::SID::BEAT_DOUDOU, Skill::SID::SLEEP } },
};
Problem p1 { Skill::SID::BEAT_DOUDOU };
EXPECT_EQ(team_1.Work(p1).Solved(), true );
Problem p2 { Skill::SID::LADY_READ };
EXPECT_EQ(team_1.Work(p2).Solved(), false );
}