Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions tdd_intro/homework/06.Allergies/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,38 @@ int GetDegreeCount(int number)
}
return -1;
}

std::string GetAlergy(size_t score)
{
if(!score)
{
return s_notAlergy;
}

return s_alergyOn + s_alergyList[score];
std::string result = s_alergyOn;
unsigned int commonDegree = 0;
unsigned int commonPow;
unsigned int foundDegree;

while (score != 0)
{
if ((foundDegree = GetDegreeCount(score)) != -1)
{
if (foundDegree < s_alergyList.size())
{
result += s_alergyList.find(static_cast<unsigned int>(pow(2, foundDegree)))->second + ",";
}
break;
}
else
{
commonPow = static_cast<unsigned int>(pow(2, commonDegree));
result += s_alergyList.find(commonPow)->second + ",";
score -= commonPow;
}
}
result.pop_back();
return result;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

оч большой шаг получился


TEST(GetAlergy, Check_no_allergy)
Expand Down Expand Up @@ -96,9 +120,9 @@ TEST(GetAlergy, Check_tomatoes_alergy)

TEST(GetAlergy, Check_two_alergies)
{
EXPECT_EQ(s_alergyOn + "shellfish, eggs", GetAlergy(5));
EXPECT_EQ(s_alergyOn + "eggs,shellfish", GetAlergy(5));
}

//----------------------------------------------------------------------
TEST(GetAlergy, GetDegreeCount)
{
EXPECT_EQ(1, GetDegreeCount(2));
Expand Down