-
Notifications
You must be signed in to change notification settings - Fork 16
first home task #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6504f38
1fba6ce
c035067
b795886
553eac2
6e72467
03397dd
35d5e67
c823ffb
1161ec0
20c6e9d
5a8042e
86ac94c
d3940b8
37b3eca
420c40f
bce290f
d7cec8e
826c85e
dba60a2
8a30a05
9ebf07f
19f4597
ac52868
e2af60a
ff3a01f
42618c4
2bba6aa
a2bfbbc
7682935
02f2d9c
9c8e787
d210926
6b11693
77c0cc5
1dba3c5
cd01843
0ff6185
379997a
b4bcbf1
8988a66
210e8a5
f937abc
0de9281
3e9433d
523f777
b3d1000
c7b9832
ed19e63
b484a4b
f10a8dd
679c5d5
372a4e5
b6fa14b
5afdc6b
4f00eb9
68fabfd
5d0e4eb
4fd85b8
bb5ca81
f5ee1f0
189e130
1a35b45
0d9c30d
c174fd9
8227979
5d79c78
18ec400
17c4673
db96423
6ee31ae
6d48ffe
6fc94b9
445ad38
5e7c1d2
5bf5c6b
cc96f91
03f47b3
42e3368
b46d661
86d43d0
3e4ca7a
3554b02
6d2b6b7
5f99591
7b3a455
17ce369
19a8799
e374063
550d351
0f82071
ab43fbf
4c30d8b
26f206c
0512156
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,61 @@ The last place in a ternary number is the 1's place. The second to last is the 3 | |
|
|
||
| If your language provides a method in the standard library to perform the conversion, pretend it doesn't exist and implement it yourself. | ||
| */ | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| int OneSignDemicalView(const std::string& oneSign) | ||
| { | ||
| if (oneSign == "1" || oneSign == "2" || oneSign == "0") | ||
| { | ||
|
|
||
| return std::stoi( oneSign ); | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
| int DemicalView(const std::string& str) | ||
| { | ||
| if (str.empty()) | ||
| { | ||
| return 0; | ||
| } | ||
| int answer = 0; | ||
| for(size_t i = 1; i <= str.size(); ++i) | ||
| { | ||
| answer += OneSignDemicalView(str.substr(str.size() - i , 1)) * pow(3, i - 1) ; | ||
| } | ||
| return (answer > 0) ? answer : 0; | ||
| } | ||
|
|
||
| TEST(TernaryNumbers, EmptyString) | ||
| { | ||
| ASSERT_EQ(0, DemicalView("")); | ||
| } | ||
|
|
||
| TEST(TernaryNumbers, EqualOne) | ||
| { | ||
| ASSERT_EQ(1, DemicalView("1")); | ||
| } | ||
|
|
||
| TEST(TernaryNumbers, EqualTwo) | ||
| { | ||
| ASSERT_EQ(2, DemicalView("2")); | ||
| } | ||
|
|
||
| TEST(TernaryNumbers, TwoSignString01) | ||
| { | ||
| ASSERT_EQ(1, DemicalView("01")); | ||
| } | ||
|
|
||
|
|
||
| TEST(TernaryNumbers, TwoSignString11) | ||
| { | ||
| ASSERT_EQ(4, DemicalView("11")); | ||
| } | ||
|
|
||
|
|
||
| TEST(TernaryNumbers, SpecifcationTest) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В спецификации есть еще ожидаемое поведение при воде невалидной строки. На это нет тестов. |
||
| { | ||
| ASSERT_EQ(302, DemicalView("102012")); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,8 @@ Example input and output | |
| */ | ||
| #include <gtest/gtest.h> | ||
| #include <string> | ||
| #include <vector> | ||
| #include <iterator> | ||
|
|
||
| const unsigned short g_linesInDigit = 3; | ||
| struct Digit | ||
|
|
@@ -139,6 +141,10 @@ const Digit s_digit9 = { " _ ", | |
| "|_|", | ||
| " _|" | ||
| }; | ||
| const Digit s_noDigit = { " _ ", | ||
| "|_|", | ||
| " _ " | ||
| }; | ||
|
|
||
| const Display s_displayAll0 = { " _ _ _ _ _ _ _ _ _ ", | ||
| "| || || || || || || || || |", | ||
|
|
@@ -194,3 +200,195 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", | |
| " | _| _||_||_ |_ ||_||_|", | ||
| " ||_ _| | _||_| ||_| _|" | ||
| }; | ||
| const Display s_wrongDisplay = { " _ _ _ _ _ _ _ _ _ ", | ||
| "|_||_||_||_||_||_||_||_||_|", | ||
| " _| _| _| _ _| _| _| _| _|" | ||
| }; | ||
|
|
||
| // parse 1 number 0-9 | ||
| // right numbers | ||
| // wrong numbers | ||
| // empty digit | ||
|
|
||
| // parse line | ||
| // more than 27 symbols in string | ||
| // less than 27 symbols in string | ||
| // 27 symbols in string | ||
|
|
||
| // parse several structs | ||
|
|
||
|
|
||
|
|
||
| // assumptions: | ||
| // one function, take vector of Display and return vector of string | ||
| // second function, take 1 Display and return one string with 9 digit. | ||
| // third function, take 1 Digit and return one int. | ||
| // No information about wrong entry* | ||
|
|
||
| bool CompareDigits(const Digit& left, const Digit& right) | ||
| { | ||
| return left.lines[0] == right.lines[0] && left.lines[1] == right.lines[1] && left.lines[2] == right.lines[2]; | ||
| } | ||
|
|
||
| int ZipNumberParser(const Digit& digit) | ||
| { | ||
| std::vector<Digit> allNumbers; | ||
| allNumbers.reserve(10); | ||
| allNumbers.push_back(s_digit0); | ||
| allNumbers.push_back(s_digit1); | ||
| allNumbers.push_back(s_digit2); | ||
| allNumbers.push_back(s_digit3); | ||
| allNumbers.push_back(s_digit4); | ||
| allNumbers.push_back(s_digit5); | ||
| allNumbers.push_back(s_digit6); | ||
| allNumbers.push_back(s_digit7); | ||
| allNumbers.push_back(s_digit8); | ||
| allNumbers.push_back(s_digit9); | ||
|
|
||
| for (int i = 0; i < allNumbers.size(); ++i) | ||
| { | ||
| if ( CompareDigits(digit, allNumbers[i]) ) | ||
| { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. новый код во время рефакторинга. теста таеого нет. |
||
| } | ||
|
|
||
| std::string ZipLineParser(const Display& display) | ||
| { | ||
| if (display.lines[0].size() != 27 || display.lines[1].size() != 27 || display.lines[2].size() != 27) | ||
| { | ||
| return "-1"; | ||
| } | ||
| std::string answer=""; | ||
| for(int i = 0; i < 27; i+=3) | ||
| { | ||
| Digit tempDigit{ std::string(display.lines[0].begin() + i,display.lines[0].begin()+3 + i), | ||
| std::string(display.lines[1].begin() + i,display.lines[1].begin()+3 + i), | ||
| std::string(display.lines[2].begin() + i,display.lines[2].begin()+3 + i)}; | ||
| int temp = ZipNumberParser(tempDigit); | ||
| if(temp == -1) | ||
| { | ||
| return "-1"; | ||
| } | ||
| else | ||
| { | ||
| answer = answer + std::to_string(temp); | ||
| } | ||
| } | ||
| return answer; | ||
| } | ||
|
|
||
| std::vector<std::string> ZipVectorParser(std::vector<Display> displays) | ||
| { | ||
| std::vector<std::string> answer; | ||
| for(auto disp:displays) | ||
| { | ||
| answer.push_back(ZipLineParser(disp)); | ||
| } | ||
| return answer; | ||
| } | ||
|
|
||
|
|
||
| TEST(Bank, NumberZero) | ||
| { | ||
| ASSERT_EQ(0, ZipNumberParser(s_digit0)); | ||
| } | ||
|
|
||
| TEST(Bank, NumberOne) | ||
| { | ||
| ASSERT_EQ(1, ZipNumberParser(s_digit1)); | ||
| } | ||
|
|
||
| TEST(Bank, NumberThree) | ||
| { | ||
| ASSERT_EQ(3, ZipNumberParser(s_digit3)); | ||
| } | ||
|
|
||
| TEST(Bank, WrongNumber) | ||
| { | ||
| ASSERT_EQ(-1, ZipNumberParser(s_noDigit)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. этот тест нужен был раньше |
||
| } | ||
|
|
||
| TEST(Bank, EmptyDigit) | ||
| { | ||
| const Digit emptyDigit{"", "", ""}; | ||
| ASSERT_EQ(-1, ZipNumberParser(emptyDigit)); | ||
| } | ||
|
|
||
| TEST(Bank, LineOfZero) | ||
| { | ||
| ASSERT_EQ("000000000", ZipLineParser(s_displayAll0)); | ||
| } | ||
|
|
||
| TEST(Bank, emptyDisplay) | ||
| { | ||
| Display emptyDisplay{"", "", ""}; | ||
| ASSERT_EQ("-1", ZipLineParser(emptyDisplay)); | ||
| } | ||
|
|
||
| TEST(Bank, largeDisplay) | ||
| { | ||
| Display largeDisplay{"______________________________", | ||
| "___________________________", | ||
| "___________________________"}; | ||
| ASSERT_EQ("-1", ZipLineParser(largeDisplay)); | ||
| } | ||
| TEST(Bank, LineOf1) | ||
| { | ||
| ASSERT_EQ("111111111", ZipLineParser(s_displayAll1)); | ||
| } | ||
|
|
||
| TEST(Bank, LineOf2) | ||
| { | ||
| ASSERT_EQ("222222222", ZipLineParser(s_displayAll2)); | ||
| } | ||
|
|
||
| TEST(Bank, Line123456789) | ||
| { | ||
| ASSERT_EQ("123456789", ZipLineParser(s_display123456789)); | ||
| } | ||
|
|
||
| TEST(Bank, WrongDispley) | ||
| { | ||
| ASSERT_EQ("-1", ZipLineParser(s_wrongDisplay)); | ||
| } | ||
|
|
||
| TEST(Bank, TwoLines) | ||
| { | ||
| std::vector<Display> linesOfDisplay; | ||
| linesOfDisplay.push_back(s_displayAll0); | ||
| linesOfDisplay.push_back(s_displayAll1); | ||
| std::vector<std::string> answer; | ||
| answer.push_back("000000000"); | ||
| answer.push_back("111111111"); | ||
| ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay)); | ||
| } | ||
|
|
||
| TEST(Bank, ThreeLines) | ||
| { | ||
| std::vector<Display> linesOfDisplay; | ||
| linesOfDisplay.push_back(s_displayAll0); | ||
| linesOfDisplay.push_back(s_displayAll1); | ||
| linesOfDisplay.push_back(s_display123456789); | ||
| std::vector<std::string> answer; | ||
| answer.push_back("000000000"); | ||
| answer.push_back("111111111"); | ||
| answer.push_back("123456789"); | ||
| ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay)); | ||
| } | ||
|
|
||
| TEST(Bank, ThreeLinesWithWrongDisplay) | ||
| { | ||
| std::vector<Display> linesOfDisplay; | ||
| linesOfDisplay.push_back(s_displayAll0); | ||
| linesOfDisplay.push_back(s_wrongDisplay); | ||
| linesOfDisplay.push_back(s_display123456789); | ||
| std::vector<std::string> answer; | ||
| answer.push_back("000000000"); | ||
| answer.push_back("-1"); | ||
| answer.push_back("123456789"); | ||
| ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay)); | ||
| } | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| include(../../gtest.pri) | ||
|
|
||
| TEMPLATE = app | ||
| CONFIG += console c++11 | ||
| CONFIG -= app_bundle | ||
| CONFIG -= qt | ||
|
|
||
| SOURCES += \ | ||
| test.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нет теста, покрывающего эту строку