-
Notifications
You must be signed in to change notification settings - Fork 16
01 - Leap Year #19
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
Open
ZakKurasov
wants to merge
28
commits into
driverdevteam:master
Choose a base branch
from
ZakKurasov:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
01 - Leap Year #19
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7ed7b50
.gitignore
ZakKurasov 5495752
1: red
ZakKurasov 5f9b2ae
1: green
ZakKurasov a44bc67
1: red
ZakKurasov ee01e84
1: green
ZakKurasov fee6983
1: red
ZakKurasov 7831492
1: green
ZakKurasov f23351d
1: refactoring
ZakKurasov 1d7d5f1
1: red
ZakKurasov 05a4b60
1: green
ZakKurasov 2efb588
1: red
ZakKurasov 93f4e38
1: green
ZakKurasov 76bdaf0
1: refactoring
ZakKurasov 03a5a58
Merge remote-tracking branch 'upstream/master'
ZakKurasov 2ad2743
2.1: red
ZakKurasov d1ff635
2.1: green
ZakKurasov e3efe16
2.1:red
ZakKurasov 9c061ef
2.1: green
ZakKurasov 30cc80d
2.1: red
ZakKurasov f423cdf
2.1: green
ZakKurasov 726ef5a
2.1: red
ZakKurasov b3203b7
2.1: green
ZakKurasov 69f7a3c
2.1: refactoring
ZakKurasov ea2cf30
2.1: red
ZakKurasov 89515ca
2.1: green
ZakKurasov 9a527a8
2.1: red
ZakKurasov e1cebcd
2.1: green
ZakKurasov 846ebdf
2.1: acceptance
ZakKurasov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,3 +30,9 @@ | |
| *.exe | ||
| *.out | ||
| *.app | ||
|
|
||
| # Build dirs | ||
| build-* | ||
|
|
||
| # .user files | ||
| *.user | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,78 @@ such: 1 | |
| #include <string> | ||
| #include <map> | ||
|
|
||
| std::vector<std::string> Split(const std::string& sentence, const std::string& delimetr) | ||
| { | ||
| std::vector<std::string> result; | ||
|
|
||
| std::string::size_type pre_pos = 0; | ||
| for (;;) | ||
| { | ||
| std::string::size_type delimetr_pos = sentence.find(delimetr, pre_pos); | ||
| result.push_back(sentence.substr(pre_pos, delimetr_pos - pre_pos)); | ||
| if (delimetr_pos == std::string::npos) | ||
| { | ||
| break; | ||
| } | ||
| pre_pos = delimetr_pos + 1; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| std::map<std::string, size_t> CountWords(const std::string& sentence) | ||
| { | ||
| std::map<std::string, size_t> result; | ||
| std::vector<std::string> words = Split(sentence, " "); | ||
| for (const std::string& word : words) | ||
| { | ||
| if (result.find(word) != result.end()) | ||
| { | ||
| result[word]++; | ||
| } | ||
| else | ||
| { | ||
| result.insert(std::make_pair(word, 1)); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| TEST(SplitTest, ReturnsNWordsForNWordsSentenceSentence) | ||
| { | ||
| EXPECT_EQ(std::vector<std::string>({"word"}), Split("word", " ")); | ||
|
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. этот экспект должен идти отдельно, поскольку изолирует отдельный кейс отсутствия делимитера |
||
| EXPECT_EQ(std::vector<std::string>({"word_a", "word_b"}), Split("word_a word_b", " ")); | ||
| EXPECT_EQ(std::vector<std::string>({"word_a", "word_b", "word_c"}), Split("word_a word_b word_c", " ")); | ||
| EXPECT_EQ(std::vector<std::string>({"word_a", "word_b", "word_a"}), Split("word_a word_b word_a", " ")); | ||
| } | ||
|
|
||
| TEST(CountWordsTest, ReturnsSameWordMapForOneWord) | ||
| { | ||
| std::map<std::string, size_t> expected({ { "word", 1 } }); | ||
| EXPECT_EQ(expected, CountWords("word")); | ||
| } | ||
| TEST(CountWordsTest, CountsDifferentWords) | ||
| { | ||
| std::map<std::string, size_t> expected({ { "word_a", 1 }, { "word_b", 1 } }); | ||
| EXPECT_EQ(expected, CountWords("word_a word_b")); | ||
| } | ||
| TEST(CountWordsTest, CountSameWords) | ||
| { | ||
| std::map<std::string, size_t> expected({ { "word_a", 2 } }); | ||
| EXPECT_EQ(expected, CountWords("word_a word_a")); | ||
| } | ||
| TEST(CountWordsTest, Acceptance) | ||
| { | ||
| std::map<std::string, size_t> expected({ | ||
| { "olly", 3 }, | ||
| { "in", 2 }, | ||
| { "come", 1 }, | ||
| { "free", 1 }, | ||
| { "please", 2 }, | ||
| { "let", 1 }, | ||
| { "it", 1 }, | ||
| { "be", 1 }, | ||
| { "such", 1 }, | ||
| { "manner", 1 }, | ||
| }); | ||
| EXPECT_EQ(expected, CountWords("olly olly in come free please please let it be in such manner olly")); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
можно упростить за счёт оператора [] в std::map:
Он сделает вставку, если элемента нет, а в противном случае возьмет существующий
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.
А он проинициализирует вставленное значение нулем?)