-
Notifications
You must be signed in to change notification settings - Fork 16
Good Title #1
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?
Good Title #1
Changes from all commits
4e12935
3b9b0e9
1744071
7bd7fca
bfa4b73
84ea9db
c70e9f3
4b16832
5aa8007
a213436
dbb50e3
eff64d9
3930208
a3bb0e9
b515066
7f60cfa
0a2094c
8f9899d
a75569d
f7533fd
3cc14e6
9e55f9f
93bed2e
bf839de
196f707
9044c1d
35c45b3
1e556e4
e2dcb1b
4b79407
a537402
edfa61f
44af337
aa2b61d
607b641
cc01447
a331c51
f4a0732
0509c22
20d13fd
21bdd1c
05666e2
3095775
6058f1f
bcf5c50
b95360d
0dfbc26
aed731d
1864c44
0ced762
8b479d2
402e7ac
6b39a61
a1f2c36
3780eb3
d3b8e9d
8d20e88
c85fcd7
634e0dc
c823a10
77d9204
eb1de2c
ad73c86
80e7099
a7badbb
4b7f893
c1e6668
6b4057c
9ae5298
fa01dae
fbe700c
755b935
9c6fd82
8c4d507
f62436e
c3d03c1
757ed56
d8c6e1e
3749c0a
69fcb93
e7cd3ab
b216fc0
0a6491c
24fbc6a
64e4154
bcbe079
97cff32
d25e52c
53af558
335a471
30bb820
ad2e550
c9b6046
39561ac
4d259b7
899c191
a0987f9
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 |
|---|---|---|
|
|
@@ -195,3 +195,207 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", | |
| " | _| _||_||_ |_ ||_||_|", | ||
| " ||_ _| | _||_| ||_| _|" | ||
| }; | ||
|
|
||
| /* | ||
| * test list : | ||
| * throws if empty file | ||
| * throws if not each line 27 long | ||
| * throws if line count mod 3 != 0 | ||
| * throws in case of invalid number form | ||
| * successful conversation (one id) | ||
| * successful conversation (two id's) | ||
| * successful conversation (unlimited size) | ||
| */ | ||
|
|
||
| class EmptyFileError : public std::runtime_error | ||
| { | ||
| public: | ||
| EmptyFileError(const char* what) | ||
| : std::runtime_error(what) | ||
| {} | ||
| }; | ||
|
|
||
| class LenghtError : public std::runtime_error | ||
| { | ||
| public: | ||
| LenghtError(const char* what) | ||
| : std::runtime_error(what) | ||
| {} | ||
| }; | ||
|
|
||
| class LineCountError : public std::runtime_error | ||
| { | ||
| public: | ||
| LineCountError(const char* what) | ||
| : std::runtime_error(what) | ||
| {} | ||
| }; | ||
|
|
||
| class NumberFormatError : public std::runtime_error | ||
| { | ||
| public: | ||
| NumberFormatError(const char* what) | ||
| : std::runtime_error(what) | ||
| {} | ||
| }; | ||
|
|
||
| std::vector<std::string> SplitByLines(const std::string& strToSplit) | ||
| { | ||
| std::stringstream ss(strToSplit); | ||
| std::string item; | ||
| std::vector<std::string> splittedStrings; | ||
| while (std::getline(ss, item, '\n')) | ||
| { | ||
| if (item.size() != 27) | ||
| { | ||
| throw LenghtError("OOPS"); | ||
|
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. только этот кейс мог быть вынесен в отдельную ф-ю, т.к. во внешней функции реализован только он. |
||
| } | ||
|
|
||
| splittedStrings.push_back(item); | ||
| } | ||
| return splittedStrings; | ||
| } | ||
|
|
||
| bool operator == (const Digit& lhs, const Digit& rhs) | ||
|
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. Не по ТДД |
||
| { | ||
| bool equals = true; | ||
| for (size_t i = 0; i < 3; ++i) | ||
| { | ||
| equals = equals && lhs.lines[i] == rhs.lines[i]; | ||
| } | ||
|
|
||
| return equals; | ||
| } | ||
|
|
||
| size_t GetDigit(const Digit& digit) | ||
|
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. Не по ТДД |
||
| { | ||
| if (digit == s_digit0) | ||
| { | ||
| return 0; | ||
| } | ||
| if (digit == s_digit1) | ||
| { | ||
| return 1; | ||
| } | ||
| if (digit == s_digit2) | ||
| { | ||
| return 2; | ||
| } | ||
| if (digit == s_digit3) | ||
| { | ||
| return 3; | ||
| } | ||
| if (digit == s_digit4) | ||
| { | ||
| return 4; | ||
| } | ||
| if (digit == s_digit5) | ||
| { | ||
| return 5; | ||
| } | ||
| if (digit == s_digit6) | ||
| { | ||
| return 6; | ||
| } | ||
| if (digit == s_digit7) | ||
| { | ||
| return 7; | ||
| } | ||
| if (digit == s_digit8) | ||
| { | ||
| return 8; | ||
| } | ||
| if (digit == s_digit9) | ||
| { | ||
| return 9; | ||
| } | ||
|
|
||
| throw NumberFormatError("OOPS"); | ||
| } | ||
| std::string GetNumberFromThreeStrings(const std::string& first, const std::string& second, const std::string& third) | ||
|
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::stringstream stream; | ||
| size_t pos = 0; | ||
| while (pos < 27) | ||
| { | ||
| Digit digit; | ||
| digit.lines[0] = first.substr(pos, 3); | ||
| digit.lines[1] = second.substr(pos, 3); | ||
| digit.lines[2] = third.substr(pos, 3); | ||
| stream << GetDigit(digit); | ||
| pos += 3; | ||
| } | ||
|
|
||
| return stream.str(); | ||
| } | ||
|
|
||
| std::vector<std::string> SplitByNumbers(const std::vector<std::string>& lines) | ||
|
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::vector<std::string> numbers; | ||
| for (size_t i = 0; i < lines.size() / 3; ++i) | ||
| { | ||
| std::string firstLine = lines[3*i]; | ||
| std::string secondLine = lines[3*i + 1]; | ||
| std::string thirdLine = lines[3*i + 2]; | ||
| numbers.push_back(GetNumberFromThreeStrings(firstLine, secondLine, thirdLine)); | ||
| } | ||
|
|
||
| return numbers; | ||
| } | ||
|
|
||
| std::vector<std::string> ParseFile(const std::string& file) | ||
| { | ||
| if (file.empty()) | ||
| { | ||
| throw EmptyFileError("empty file"); | ||
| } | ||
|
|
||
| std::vector<std::string> lines = SplitByLines(file); | ||
|
|
||
| if (lines.size() % 3 != 0) | ||
| { | ||
| throw LineCountError("line count error"); | ||
| } | ||
|
|
||
| return SplitByNumbers(lines); | ||
| } | ||
|
|
||
| TEST(ParseFile, ThrowsIfEmptyFile) | ||
| { | ||
| ASSERT_THROW(ParseFile(""), EmptyFileError); | ||
| } | ||
|
|
||
| TEST(ParseFile, ThrowsIfNotEachLine27Long) | ||
| { | ||
| ASSERT_THROW(ParseFile("abc"), LenghtError); | ||
| } | ||
|
|
||
| TEST(ParseFile, ThrowsIfLineCountMod3NotZero) | ||
| { | ||
| std::string file(27, '_'); | ||
| file = file + '\n' + file; | ||
| ASSERT_THROW(ParseFile(file), LineCountError); | ||
| } | ||
|
|
||
| TEST(SplitByNumbers, ThrowsInCaseOfInvalidNumberForm) | ||
| { | ||
| std::string file(27, '_'); | ||
| file = file + '\n' + file + '\n' + file; | ||
| std::vector<std::string> files {file, file, file}; | ||
| ASSERT_THROW(SplitByNumbers(files), NumberFormatError); | ||
| } | ||
|
|
||
| TEST(SplitByNumbers, SuccessfulSplit) | ||
| { | ||
| std::vector<std::string> lines = {s_display123456789.lines[0], s_display123456789.lines[1], s_display123456789.lines[2]}; | ||
| auto result = SplitByNumbers(lines); | ||
| ASSERT_EQ(result.size(), 1); | ||
| ASSERT_EQ(result[0], "123456789"); | ||
| } | ||
|
|
||
| TEST(ParseFile, SuccessfulParse) | ||
| { | ||
| std::string file = s_display123456789.lines[0] + "\n" + s_display123456789.lines[1] + "\n" + s_display123456789.lines[2]; | ||
| std::vector<std::string> result = ParseFile(file); | ||
| ASSERT_EQ(result[0], "123456789"); | ||
| } | ||
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.
достаточно было бы ConvertToTernary("3")