From 031d0ad34b046a66761cfb677511aab0a529f6f2 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Fri, 1 Jun 2018 13:09:35 +0300 Subject: [PATCH 01/22] create base tests list --- .../06.Allergies/06.Allergies - Shortcut.lnk | Bin 0 -> 1589 bytes .../homework/06.Allergies/06.Allergies.pro | 9 + .../06.Allergies/06.Allergies.pro.user | 318 ++++++++++++++++++ tdd_intro/homework/06.Allergies/test.cpp | 34 ++ 4 files changed, 361 insertions(+) create mode 100644 tdd_intro/homework/06.Allergies/06.Allergies - Shortcut.lnk create mode 100644 tdd_intro/homework/06.Allergies/06.Allergies.pro create mode 100644 tdd_intro/homework/06.Allergies/06.Allergies.pro.user create mode 100644 tdd_intro/homework/06.Allergies/test.cpp diff --git a/tdd_intro/homework/06.Allergies/06.Allergies - Shortcut.lnk b/tdd_intro/homework/06.Allergies/06.Allergies - Shortcut.lnk new file mode 100644 index 0000000000000000000000000000000000000000..c61bfb04efc389c38bf73ee59c19048dbc9f43f4 GIT binary patch literal 1589 zcmcgsOH31C5dMlaqERV|rW#&qj2hUw7(x^Sf-Q)+P!mW{*rb*2Vhg20j;{pQ=5`Bws9$w(m$ zj2jx2myrq^t&c`iKTLglW?5Ae%bHG_4I|ktasPxKPRT&d;kWKs?&sow?as?o_q=Rzkk9os?6|`4o>!%f>8L?B z8lXW3y^8f{F)>G_@g^JUDx^wJMU=wSny9CwSUuYqbxv4D+JK%1#ol+DEn%n#5|)Q% z1zqsr7&;N4I3e=1quPuzB2Bj1Q15bKw~0R>&9?9<>t zcn;Qb1Xm)$`&PDbgfoXSNG~kw%eibbf`@VtqP0$O7`yQoY`@m7MvNNn{{!|@=}*|! z>>T(Bt(_Q0XpYy>o~YxPbdp$$MFpa>Fk0X!m!$dJj7i=I+nIUJ4CiJgN%GLVZy=%w z4wO?pgA_x@ary?8G6ZCjoHb|uX5JT)@Q9MwNw|8KIzAQgb!Z5L6fF`4b#uH~<**uT z@u*6d?^tI*3(3?7a;KsQKCMd+tHLhccmknLU6X(2Miz@4<-wq;9}lR+!9vu$@i4cK z(9FZAPM`N{orp}DN=P0Gjg8z02pEhQBv{$+R5 zAMY4E#fpuh0 zBS9IfiTscJGvgRm-ZKI>OeHl0w?-~CoklCgXp{KctJ$%Pq{n^1!oNV?KPF*r1FgR8 zCD$g>AH2Z0`;|S`Pv_a}z{u4k|0ikkZv~V8niXIVapMmdUf=E-y4q1SSXJieD>-!~ Wi_ZNds3J+r^KIcZFwJ@VW&8j%|3oSP literal 0 HcmV?d00001 diff --git a/tdd_intro/homework/06.Allergies/06.Allergies.pro b/tdd_intro/homework/06.Allergies/06.Allergies.pro new file mode 100644 index 0000000..ab8c016 --- /dev/null +++ b/tdd_intro/homework/06.Allergies/06.Allergies.pro @@ -0,0 +1,9 @@ +include(../../gtest.pri) + +TEMPLATE = app +CONFIG += console c++11 +CONFIG -= app_bundle +CONFIG -= qt + +SOURCES += test.cpp + diff --git a/tdd_intro/homework/06.Allergies/06.Allergies.pro.user b/tdd_intro/homework/06.Allergies/06.Allergies.pro.user new file mode 100644 index 0000000..9ecb317 --- /dev/null +++ b/tdd_intro/homework/06.Allergies/06.Allergies.pro.user @@ -0,0 +1,318 @@ + + + + + + EnvironmentId + {d40f95ee-3fbc-4856-b5dc-5ba27a967b64} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.11.0 MSVC2015 32bit + Desktop Qt 5.11.0 MSVC2015 32bit + qt.qt5.5110.win32_msvc2015_kit + 0 + 0 + 0 + + C:/MyWork/self_education/TDD/tdd-course-2/tdd_intro/homework/build-06.Allergies-Desktop_Qt_5_11_0_MSVC2015_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/MyWork/self_education/TDD/tdd-course-2/tdd_intro/homework/build-06.Allergies-Desktop_Qt_5_11_0_MSVC2015_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/MyWork/self_education/TDD/tdd-course-2/tdd_intro/homework/build-06.Allergies-Desktop_Qt_5_11_0_MSVC2015_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + 06.Allergies + + Qt4ProjectManager.Qt4RunConfiguration:C:/MyWork/self_education/TDD/tdd-course-2/tdd_intro/homework/06.Allergies/06.Allergies.pro + true + + 06.Allergies.pro + false + + C:/MyWork/self_education/TDD/tdd-course-2/tdd_intro/homework/build-06.Allergies-Desktop_Qt_5_11_0_MSVC2015_32bit-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp new file mode 100644 index 0000000..b9822ab --- /dev/null +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -0,0 +1,34 @@ +/* +Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies. +An allergy test produces a single numeric score which contains the information about all the allergies the person has (that they were tested for). +The list of items (and their value) that were tested are: + +eggs (1) peanuts (2) shellfish (4) strawberries (8) tomatoes (16) +chocolate (32) pollen (64) cats (128) + +So if Tom is allergic to peanuts and chocolate, he gets a score of 34. + +Now, given just that score of 34, your program should be able: + +To say have Tom allergic to specific product or not. +To give list of all allergens Tom is allergic to. +Note: a given score may include allergens not listed above (i.e. allergens that score 256, 512, 1024, etc.). Your program should ignore those components of the score. For example, if the allergy score is 257, your program should only report the eggs (1) allergy. +*/ +#include + +//tests list + +/* + + 1.Check no allergy + 2.Check eggs alergy + 3.Check peanuts alergy + 4.Check shellfish alergy + 5.Check tomatoes alergy + 6.Check chocolate alergy + 7.Check pollen alergy + 8.Check cats alergy + 9.Check eggs and peanuts + 10.Check eggs and strawberries and pollen + 11.Check random alergy + * \ From 99da113045165dc5dfa83d37bfe3aea4cd5b5381 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Fri, 1 Jun 2018 16:04:11 +0300 Subject: [PATCH 02/22] green test- Check_no_allergy --- tdd_intro/homework/06.Allergies/test.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index b9822ab..b3bc754 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -17,9 +17,7 @@ Note: a given score may include allergens not listed above (i.e. allergens that #include //tests list - /* - 1.Check no allergy 2.Check eggs alergy 3.Check peanuts alergy @@ -31,4 +29,14 @@ Note: a given score may include allergens not listed above (i.e. allergens that 9.Check eggs and peanuts 10.Check eggs and strawberries and pollen 11.Check random alergy - * \ + */ + +std::string GetAlergy(size_t score) +{ + return "You don't have any alergy"; +} + +TEST(GetAlergy, Check_no_allergy) +{ + EXPECT_EQ("You don't have any alergy", GetAlergy(0)); +} From 38c48c70bf3a3b57f48a6c53ea0a2633ef10acc4 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Fri, 1 Jun 2018 16:06:11 +0300 Subject: [PATCH 03/22] red test- Check_eggs_alergy --- tdd_intro/homework/06.Allergies/test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index b3bc754..4029b3b 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -40,3 +40,9 @@ TEST(GetAlergy, Check_no_allergy) { EXPECT_EQ("You don't have any alergy", GetAlergy(0)); } + +TEST(GetAlergy, Check_eggs_alergy) +{ + EXPECT_EQ("You have alergy:eggs", GetAlergy(1)); +} + From 673fe8559a89ea9e2463bee85c8ab847fea82cbb Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Fri, 1 Jun 2018 16:07:01 +0300 Subject: [PATCH 04/22] green test- Check_eggs_alergy --- tdd_intro/homework/06.Allergies/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 4029b3b..05508cd 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -33,6 +33,10 @@ Note: a given score may include allergens not listed above (i.e. allergens that std::string GetAlergy(size_t score) { + if(score) + { + return "You have alergy:eggs"; + } return "You don't have any alergy"; } From a8b4644aad13c108a2ed5740d1b5f0e312363b95 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Fri, 1 Jun 2018 16:11:51 +0300 Subject: [PATCH 05/22] red test- Check_peanuts_alergy --- tdd_intro/homework/06.Allergies/test.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 05508cd..ff56fce 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -31,18 +31,21 @@ Note: a given score may include allergens not listed above (i.e. allergens that 11.Check random alergy */ + +const std::string s_notAlergy = "You don't have any alergy"; + std::string GetAlergy(size_t score) { if(score) { return "You have alergy:eggs"; } - return "You don't have any alergy"; + return s_notAlergy; } TEST(GetAlergy, Check_no_allergy) { - EXPECT_EQ("You don't have any alergy", GetAlergy(0)); + EXPECT_EQ(s_notAlergy, GetAlergy(0)); } TEST(GetAlergy, Check_eggs_alergy) @@ -50,3 +53,8 @@ TEST(GetAlergy, Check_eggs_alergy) EXPECT_EQ("You have alergy:eggs", GetAlergy(1)); } +TEST(GetAlergy, Check_peanuts_alergy) +{ + EXPECT_EQ("You have alergy:peanuts", GetAlergy(2)); +} + From b9af7b79074f7d33e7afee9bd065c6c717d18e37 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Fri, 1 Jun 2018 16:14:57 +0300 Subject: [PATCH 06/22] green test- GetAlergy, Check_peanuts_alergy --- tdd_intro/homework/06.Allergies/test.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index ff56fce..e4411ee 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -36,7 +36,11 @@ const std::string s_notAlergy = "You don't have any alergy"; std::string GetAlergy(size_t score) { - if(score) + if(score == 2) + { + return "You have alergy:peanuts"; + } + if(score ==1) { return "You have alergy:eggs"; } From 5329034d19250f128007df8a2bc983e8f45045d2 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Fri, 1 Jun 2018 16:17:18 +0300 Subject: [PATCH 07/22] red test- Check_shellfish_alergy --- tdd_intro/homework/06.Allergies/test.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index e4411ee..31a53db 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -40,7 +40,7 @@ std::string GetAlergy(size_t score) { return "You have alergy:peanuts"; } - if(score ==1) + if(score == 1) { return "You have alergy:eggs"; } @@ -62,3 +62,10 @@ TEST(GetAlergy, Check_peanuts_alergy) EXPECT_EQ("You have alergy:peanuts", GetAlergy(2)); } +TEST(GetAlergy, Check_shellfish_alergy) +{ + EXPECT_EQ("You have alergy:shellfish", GetAlergy(4)); +} + + + From 2e3fa1e53f16bee26151164c7e6e21ad4b496cf5 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Fri, 1 Jun 2018 16:19:11 +0300 Subject: [PATCH 08/22] green test- Check_shellfish_alergy --- tdd_intro/homework/06.Allergies/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 31a53db..5db56cd 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -36,6 +36,10 @@ const std::string s_notAlergy = "You don't have any alergy"; std::string GetAlergy(size_t score) { + if(score == 4) + { + return "You have alergy:shellfish"; + } if(score == 2) { return "You have alergy:peanuts"; From 94ebe62107b7ad996cd9f111923179c7b494e62a Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Fri, 1 Jun 2018 16:25:04 +0300 Subject: [PATCH 09/22] red test- Check_tomatoes_alergy --- tdd_intro/homework/06.Allergies/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 5db56cd..ca7651a 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -71,5 +71,9 @@ TEST(GetAlergy, Check_shellfish_alergy) EXPECT_EQ("You have alergy:shellfish", GetAlergy(4)); } +TEST(GetAlergy, Check_tomatoes_alergy) +{ + EXPECT_EQ("You have alergy:tomatoes", GetAlergy(16)); +} From 243ce52e938677516eab212aa86185bf196076cd Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Fri, 1 Jun 2018 16:25:59 +0300 Subject: [PATCH 10/22] green test- Check_tomatoes_alergy --- tdd_intro/homework/06.Allergies/test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index ca7651a..fcc969c 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -23,9 +23,6 @@ Note: a given score may include allergens not listed above (i.e. allergens that 3.Check peanuts alergy 4.Check shellfish alergy 5.Check tomatoes alergy - 6.Check chocolate alergy - 7.Check pollen alergy - 8.Check cats alergy 9.Check eggs and peanuts 10.Check eggs and strawberries and pollen 11.Check random alergy @@ -36,6 +33,10 @@ const std::string s_notAlergy = "You don't have any alergy"; std::string GetAlergy(size_t score) { + if(score == 16) + { + return "You have alergy:tomatoes"; + } if(score == 4) { return "You have alergy:shellfish"; From e82d08d6fc9209bf17000a9115924cb8bd541061 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:00:52 +0300 Subject: [PATCH 11/22] refactored --- tdd_intro/homework/06.Allergies/test.cpp | 28 +++++++++++------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index fcc969c..f3b5f16 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -30,26 +30,24 @@ Note: a given score may include allergens not listed above (i.e. allergens that const std::string s_notAlergy = "You don't have any alergy"; +std::map alergyList = { + {1, "eggs"}, + {2, "peanuts"}, + {4, "shellfish"}, + {8, "strawberries"}, + {16, "tomatoes"}, + {32, "chocolate"}, + {64, "pollen"}, + {128, "cats"} + }; std::string GetAlergy(size_t score) { - if(score == 16) + if(!score) { - return "You have alergy:tomatoes"; + return s_notAlergy; } - if(score == 4) - { - return "You have alergy:shellfish"; - } - if(score == 2) - { - return "You have alergy:peanuts"; - } - if(score == 1) - { - return "You have alergy:eggs"; - } - return s_notAlergy; + return "You have alergy:" + alergyList[score]; } TEST(GetAlergy, Check_no_allergy) From 869c1aa06725aebd87d686ce312444b1fe77985a Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:03:26 +0300 Subject: [PATCH 12/22] refactored --- tdd_intro/homework/06.Allergies/test.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index f3b5f16..dc70163 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -30,7 +30,8 @@ Note: a given score may include allergens not listed above (i.e. allergens that const std::string s_notAlergy = "You don't have any alergy"; -std::map alergyList = { +const std::string s_alergyOn = "You have alergy:"; +std::map s_alergyList = { {1, "eggs"}, {2, "peanuts"}, {4, "shellfish"}, @@ -47,7 +48,7 @@ std::string GetAlergy(size_t score) { return s_notAlergy; } - return "You have alergy:" + alergyList[score]; + return s_alergyOn + s_alergyList[score]; } TEST(GetAlergy, Check_no_allergy) @@ -57,22 +58,22 @@ TEST(GetAlergy, Check_no_allergy) TEST(GetAlergy, Check_eggs_alergy) { - EXPECT_EQ("You have alergy:eggs", GetAlergy(1)); + EXPECT_EQ(s_alergyOn + s_alergyList[1], GetAlergy(1)); } TEST(GetAlergy, Check_peanuts_alergy) { - EXPECT_EQ("You have alergy:peanuts", GetAlergy(2)); + EXPECT_EQ(s_alergyOn + s_alergyList[2], GetAlergy(2)); } TEST(GetAlergy, Check_shellfish_alergy) { - EXPECT_EQ("You have alergy:shellfish", GetAlergy(4)); + EXPECT_EQ(s_alergyOn + s_alergyList[4], GetAlergy(4)); } TEST(GetAlergy, Check_tomatoes_alergy) { - EXPECT_EQ("You have alergy:tomatoes", GetAlergy(16)); + EXPECT_EQ(s_alergyOn + s_alergyList[16], GetAlergy(16)); } From 7f63d2057f29eff37983cc6c7b3626e36f318041 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:07:40 +0300 Subject: [PATCH 13/22] red test- Check_two_alergies --- tdd_intro/homework/06.Allergies/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index dc70163..12a8cb1 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -76,4 +76,8 @@ TEST(GetAlergy, Check_tomatoes_alergy) EXPECT_EQ(s_alergyOn + s_alergyList[16], GetAlergy(16)); } +TEST(GetAlergy, Check_two_alergies) +{ + EXPECT_EQ(s_alergyOn + "shellfish,eggs", GetAlergy(5)); +} From a5a0dd5cd209444c6ab8ee50ea5455c9933a5526 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:20:05 +0300 Subject: [PATCH 14/22] red test- GetDegreeCount --- tdd_intro/homework/06.Allergies/test.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 12a8cb1..e497564 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -42,12 +42,18 @@ std::map s_alergyList = { {128, "cats"} }; + +int GetDegreeCount(int number) +{ + return 0; +} std::string GetAlergy(size_t score) { if(!score) { return s_notAlergy; } + return s_alergyOn + s_alergyList[score]; } @@ -76,8 +82,12 @@ TEST(GetAlergy, Check_tomatoes_alergy) EXPECT_EQ(s_alergyOn + s_alergyList[16], GetAlergy(16)); } -TEST(GetAlergy, Check_two_alergies) +//TEST(GetAlergy, Check_two_alergies) +//{ + //EXPECT_EQ(s_alergyOn + "shellfish, eggs", GetAlergy(5)); +//} + +TEST(GetAlergy, GetDegreeCount) { - EXPECT_EQ(s_alergyOn + "shellfish,eggs", GetAlergy(5)); + EXPECT_EQ(1, GetDegreeCount(2)); } - From 158f47a8dfb33211bb8ea44c1dcd6b2eeb203409 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:20:49 +0300 Subject: [PATCH 15/22] green test- GetDegreeCount --- tdd_intro/homework/06.Allergies/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index e497564..76d77ed 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -45,7 +45,7 @@ std::map s_alergyList = { int GetDegreeCount(int number) { - return 0; + return 1; } std::string GetAlergy(size_t score) { From 493dd6ea49a820a38f9c663dcbdb26dada4a32fa Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:21:51 +0300 Subject: [PATCH 16/22] red test- GetDegreeCountFrom4 --- tdd_intro/homework/06.Allergies/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 76d77ed..1efdf03 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -91,3 +91,8 @@ TEST(GetAlergy, GetDegreeCount) { EXPECT_EQ(1, GetDegreeCount(2)); } + +TEST(GetAlergy, GetDegreeCountFrom4) +{ + EXPECT_EQ(2, GetDegreeCount(4)); +} From edcd82676bd9d45dd4dc222a9adba78ed7baf9ab Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:22:47 +0300 Subject: [PATCH 17/22] green test- GetDegreeCountFrom4 --- tdd_intro/homework/06.Allergies/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 1efdf03..363b8a8 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -45,6 +45,10 @@ std::map s_alergyList = { int GetDegreeCount(int number) { + if(number == 4) + { + return 2; + } return 1; } std::string GetAlergy(size_t score) From 55a550dc733b91a9b1737cdb3fa8ac6e90fa3f9e Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:26:02 +0300 Subject: [PATCH 18/22] refactored --- tdd_intro/homework/06.Allergies/test.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 363b8a8..4762b7a 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -45,11 +45,19 @@ std::map s_alergyList = { int GetDegreeCount(int number) { - if(number == 4) + int degree = 0; + + unsigned int power; + + while ((power = static_cast(pow(2, degree))) <= number) { - return 2; + if (power == number) + { + return degree; + } + ++degree; } - return 1; + return -1; } std::string GetAlergy(size_t score) { From 8895b02ba9d57fb9dabe56e24060318b0ddd6199 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:27:01 +0300 Subject: [PATCH 19/22] green test- GetDegreeCountFrom8 --- tdd_intro/homework/06.Allergies/test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 4762b7a..321bc6b 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -108,3 +108,9 @@ TEST(GetAlergy, GetDegreeCountFrom4) { EXPECT_EQ(2, GetDegreeCount(4)); } + +TEST(GetAlergy, GetDegreeCountFrom8) +{ + EXPECT_EQ(3, GetDegreeCount(8)); +} + From 2bd26685b75de8ddf98a0807bd2aab60ce5f7431 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:28:19 +0300 Subject: [PATCH 20/22] red test- Check_two_alergies --- tdd_intro/homework/06.Allergies/test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 321bc6b..95eab2b 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -94,10 +94,10 @@ TEST(GetAlergy, Check_tomatoes_alergy) EXPECT_EQ(s_alergyOn + s_alergyList[16], GetAlergy(16)); } -//TEST(GetAlergy, Check_two_alergies) -//{ - //EXPECT_EQ(s_alergyOn + "shellfish, eggs", GetAlergy(5)); -//} +TEST(GetAlergy, Check_two_alergies) +{ + EXPECT_EQ(s_alergyOn + "shellfish, eggs", GetAlergy(5)); +} TEST(GetAlergy, GetDegreeCount) { From 53ba67e89a5a5eb1e40bb75957ffe3df1b58a7ef Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 14:49:56 +0300 Subject: [PATCH 21/22] green test- Check_two_alergies --- tdd_intro/homework/06.Allergies/test.cpp | 30 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 95eab2b..45c4db5 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -59,6 +59,7 @@ int GetDegreeCount(int number) } return -1; } + std::string GetAlergy(size_t score) { if(!score) @@ -66,7 +67,30 @@ std::string GetAlergy(size_t 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(pow(2, foundDegree)))->second + ","; + } + break; + } + else + { + commonPow = static_cast(pow(2, commonDegree)); + result += s_alergyList.find(commonPow)->second + ","; + score -= commonPow; + } + } + result.pop_back(); + return result; } TEST(GetAlergy, Check_no_allergy) @@ -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)); From f06455710fcfc9189780f0f5cab511f4b5b98973 Mon Sep 17 00:00:00 2001 From: Chernysh Vladimir Date: Wed, 6 Jun 2018 15:22:02 +0300 Subject: [PATCH 22/22] green test- AcceptanceTest --- tdd_intro/homework/06.Allergies/test.cpp | 39 +++++++++++------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/tdd_intro/homework/06.Allergies/test.cpp b/tdd_intro/homework/06.Allergies/test.cpp index 45c4db5..e2a6c61 100644 --- a/tdd_intro/homework/06.Allergies/test.cpp +++ b/tdd_intro/homework/06.Allergies/test.cpp @@ -49,15 +49,12 @@ int GetDegreeCount(int number) unsigned int power; - while ((power = static_cast(pow(2, degree))) <= number) + while (static_cast(pow(2, degree)) <= number) { - if (power == number) - { - return degree; - } + ++degree; } - return -1; + return --degree; } std::string GetAlergy(size_t score) @@ -68,26 +65,21 @@ std::string GetAlergy(size_t score) } std::string result = s_alergyOn; - unsigned int commonDegree = 0; - unsigned int commonPow; + unsigned int maxDegree = s_alergyList.size() - 1;; + unsigned int foundPow; unsigned int foundDegree; while (score != 0) { - if ((foundDegree = GetDegreeCount(score)) != -1) - { - if (foundDegree < s_alergyList.size()) - { - result += s_alergyList.find(static_cast(pow(2, foundDegree)))->second + ","; - } - break; - } - else + foundDegree = GetDegreeCount(score); + foundPow = static_cast(pow(2, foundDegree)); + + if (foundDegree < maxDegree) { - commonPow = static_cast(pow(2, commonDegree)); - result += s_alergyList.find(commonPow)->second + ","; - score -= commonPow; + result += s_alergyList.find(foundPow)->second + ","; } + + score -= foundPow; } result.pop_back(); return result; @@ -120,7 +112,12 @@ TEST(GetAlergy, Check_tomatoes_alergy) TEST(GetAlergy, Check_two_alergies) { - EXPECT_EQ(s_alergyOn + "eggs,shellfish", GetAlergy(5)); + EXPECT_EQ(s_alergyOn + "shellfish,eggs", GetAlergy(5)); +} + +TEST(GetAlergy, AcceptanceTest) +{ + EXPECT_EQ(s_alergyOn + "chocolate,peanuts", GetAlergy(34)); } //---------------------------------------------------------------------- TEST(GetAlergy, GetDegreeCount)