-
Notifications
You must be signed in to change notification settings - Fork 16
01-Leap Year #20
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
Alexandr1992
wants to merge
74
commits into
driverdevteam:master
Choose a base branch
from
Alexandr1992: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 #20
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
f0dc6d8
First test
alexchernysh92 ef5f02c
Green
alexchernysh92 7808524
Refactoring
alexchernysh92 62d0f6d
Red
alexchernysh92 44b9696
Green
alexchernysh92 de71170
refactoring
alexchernysh92 0cfe902
Read
alexchernysh92 93dd7e4
Green
alexchernysh92 56f373b
Refactoring
alexchernysh92 de62609
Green
alexchernysh92 c54701b
WS#2 added word count demo project
mokychandrey b020cff
First red test
alexchernysh92 2e932c2
Green
alexchernysh92 a22a075
Refactoring
alexchernysh92 aa48d05
Red
alexchernysh92 47c09e6
Green
alexchernysh92 cfcbb1d
Red
alexchernysh92 c6d369a
Green
alexchernysh92 c4d0e8d
Refactoring
alexchernysh92 1b77c23
Red
alexchernysh92 66d9de7
Green
alexchernysh92 e904716
Added several green tests
alexchernysh92 f1b20f5
AcceptanceTest
alexchernysh92 4080ca5
Refactoring tests
alexchernysh92 0e34d7e
Red
alexchernysh92 98552d9
Green + refactoring
alexchernysh92 fb09975
Red
alexchernysh92 99cdcdd
Green
alexchernysh92 a90cf74
Refactoring
alexchernysh92 9ff8ab3
Red
alexchernysh92 3cd4607
Green
alexchernysh92 9b15365
Refactoring
alexchernysh92 c8073c7
Red
alexchernysh92 944f4c7
Green
alexchernysh92 a004cfc
Added some test
alexchernysh92 afdf9fb
Added some test
alexchernysh92 456014f
Refactoring
alexchernysh92 f417ef6
Red
alexchernysh92 6f1e44a
Green
alexchernysh92 d4daf34
Red
alexchernysh92 c8c79c7
Green
alexchernysh92 23dea11
Refactoring
alexchernysh92 73f188e
Red
alexchernysh92 858047c
Green
alexchernysh92 967c443
Red
alexchernysh92 550d7fd
Refactoring
alexchernysh92 1a58753
Red + Green
alexchernysh92 ef3ee18
Red
alexchernysh92 a220bac
Green
alexchernysh92 3068f7d
Red
alexchernysh92 f072293
Green
alexchernysh92 272870e
Added test
alexchernysh92 a97542a
Red
alexchernysh92 14f8f04
Green
alexchernysh92 7fa9305
AcceptanceTest
alexchernysh92 a719696
Refactoring
alexchernysh92 532681f
First red test
alexchernysh92 70c89b5
green
alexchernysh92 e0859a2
Refactoring + red test
alexchernysh92 73da9dc
Green
alexchernysh92 d834675
Red
alexchernysh92 82e6d50
Green
alexchernysh92 34862d7
Refactoring
alexchernysh92 6ec87e2
Red
alexchernysh92 ca60ec4
Green
alexchernysh92 8a3099d
Refactoring + next Redtest
alexchernysh92 fb6d2f2
Green
alexchernysh92 6c1fbe7
Red
alexchernysh92 1be25c4
Green
alexchernysh92 3e857a5
Refactoring
alexchernysh92 f121f21
Red
alexchernysh92 c512957
Green
alexchernysh92 441f249
Merge pull request #3 from Alexandr1992/BankOCR
b2c20c7
Merge pull request #4 from Alexandr1992/BankOCR
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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| include(../../gtest.pri) | ||
|
|
||
| TEMPLATE = app | ||
| CONFIG += console c++11 | ||
| CONFIG -= app_bundle | ||
| CONFIG -= qt | ||
|
|
||
| SOURCES += \ | ||
| test.cpp | ||
|
|
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 |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| Given a phrase, count the occurrences of each word in that phrase. Ignore whitespaces and punctual symbols | ||
| For example for the input "olly olly in come free please please let it be in such manner olly" | ||
| olly: 3 | ||
| in: 2 | ||
| come: 1 | ||
| free: 1 | ||
| please: 2 | ||
| let: 1 | ||
| it: 1 | ||
| be: 1 | ||
| manner: 1 | ||
| such: 1 | ||
| */ | ||
|
|
||
| #include <gtest/gtest.h> | ||
| #include <string> | ||
| #include <map> | ||
|
|
||
| using words_mt = std::map<std::string, size_t>; | ||
| const static char wordSeparator = ' '; | ||
|
|
||
| bool TrimWord(std::string& phrase, std::string& word, const char seperator) | ||
| { | ||
| if (phrase.empty()) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| size_t index = phrase.find_first_of(seperator); | ||
| if (index == std::string::npos || index == phrase.size()) | ||
| { | ||
| word = phrase; | ||
| phrase.clear(); | ||
| } | ||
| else | ||
| { | ||
| word = phrase.substr(0, index); | ||
| phrase = phrase.substr(index + 1, phrase.size() - index); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| words_mt SeparateWords(const std::string& phrase) | ||
| { | ||
| words_mt words; | ||
| std::string currentPhrase = phrase; | ||
| std::string curentWord; | ||
|
|
||
| while (TrimWord(currentPhrase, curentWord, wordSeparator)) | ||
| { | ||
| ++words[curentWord]; | ||
| } | ||
|
|
||
| return words; | ||
| } | ||
|
|
||
| TEST(WordsCount, TestSeparateFirstWord) | ||
| { | ||
| words_mt words = SeparateWords("hello"); | ||
| EXPECT_EQ(1, words.size()); | ||
| EXPECT_TRUE(words.find("hello") != words.end()); | ||
| EXPECT_EQ(1, words["hello"]); | ||
| } | ||
|
|
||
| TEST(WordsCount, TestTrimOneWord) | ||
| { | ||
| std::string phrase = "tdd course"; | ||
| std::string word; | ||
| EXPECT_TRUE(TrimWord(phrase, word, ' ')); | ||
| EXPECT_EQ("course", phrase); | ||
|
|
||
| EXPECT_TRUE(TrimWord(phrase, word, ' ')); | ||
| EXPECT_EQ("", phrase); | ||
|
|
||
| EXPECT_FALSE(TrimWord(phrase, word, ' ')); | ||
| } | ||
|
|
||
| TEST(WordsCount, TestCountSeveralDifferentWords) | ||
| { | ||
| words_mt words = SeparateWords("hello bro"); | ||
| EXPECT_EQ(2, words.size()); | ||
|
|
||
| EXPECT_TRUE(words.find("hello") != words.end()); | ||
| EXPECT_EQ(1, words["hello"]); | ||
|
|
||
| EXPECT_TRUE(words.find("bro") != words.end()); | ||
| EXPECT_EQ(1, words["bro"]); | ||
| } | ||
|
|
||
| TEST(WordsCount, TestCountSeveralSameWords) | ||
| { | ||
| words_mt words = SeparateWords("hello bro hello"); | ||
|
|
||
| EXPECT_EQ(2, words.size()); | ||
| EXPECT_TRUE(words.find("hello") != words.end()); | ||
| EXPECT_EQ(2, words["hello"]); | ||
| } | ||
|
|
||
| TEST(WordsCount, TestNoWordsWhenEmptyInput) | ||
| { | ||
| words_mt words = SeparateWords(""); | ||
| EXPECT_TRUE(words.empty()); | ||
| } | ||
|
|
||
| TEST(WordsCount, TestOneWordWhenSeparatorInEnd) | ||
| { | ||
| words_mt words = SeparateWords("hello "); | ||
|
|
||
| EXPECT_EQ(1, words.size()); | ||
| EXPECT_TRUE(words.find("hello") != words.end()); | ||
| EXPECT_EQ(1, words["hello"]); | ||
| } | ||
|
|
||
| TEST(WordsCount, AcceptanceTest) | ||
| { | ||
| words_mt words = SeparateWords("olly olly in come free please please let it be in such manner olly"); | ||
|
|
||
| ASSERT_EQ(10, words.size()); | ||
|
|
||
| ASSERT_EQ(3, words["olly"]); | ||
| ASSERT_EQ(2, words["in"]); | ||
| ASSERT_EQ(1, words["come"]); | ||
| ASSERT_EQ(1, words["free"]); | ||
| ASSERT_EQ(2, words["please"]); | ||
| ASSERT_EQ(1, words["let"]); | ||
| ASSERT_EQ(1, words["it"]); | ||
| ASSERT_EQ(1, words["be"]); | ||
| ASSERT_EQ(1, words["manner"]); | ||
| ASSERT_EQ(1, words["such"]); | ||
| } |
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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ SUBDIRS += \ | |
| 01_bob \ | ||
| 01_fizz_buzz \ | ||
| 02_anagram \ | ||
| 02_word_count \ | ||
| #03_allergies \ | ||
| 03_roman_numerals \ | ||
| 04_timer | ||
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 |
|---|---|---|
|
|
@@ -13,3 +13,58 @@ If your language provides a method in the standard library that does this look-u | |
| */ | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
|
|
||
| const size_t g_four = 4; | ||
| const size_t g_oneHundred = 100; | ||
| const size_t g_fourHundred = g_four * g_oneHundred; | ||
|
|
||
| bool isDivisible(size_t number, size_t divider) | ||
| { | ||
| return number % divider == 0; | ||
| } | ||
|
|
||
| bool IsLeapYear(size_t year) | ||
| { | ||
| if (isDivisible(year, g_fourHundred)) | ||
| { | ||
| return true; | ||
| } | ||
| if (isDivisible(year, g_oneHundred)) | ||
| { | ||
| return false; | ||
| } | ||
| if (isDivisible(year, g_four)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| TEST(LeapYear, TestDivisible400) | ||
| { | ||
| EXPECT_TRUE(IsLeapYear(g_fourHundred)); | ||
| EXPECT_TRUE(IsLeapYear(g_fourHundred * 2)); | ||
| EXPECT_TRUE(IsLeapYear(g_fourHundred * 3)); | ||
|
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(LeapYear, TestDivisible4AndNot100) | ||
| { | ||
| EXPECT_TRUE(IsLeapYear(104)); | ||
| EXPECT_TRUE(IsLeapYear(404)); | ||
| EXPECT_TRUE(IsLeapYear(2008)); | ||
| EXPECT_TRUE(IsLeapYear(2012)); | ||
| } | ||
|
|
||
| TEST(LeapYear, TestDivisible100) | ||
| { | ||
| EXPECT_FALSE(IsLeapYear(g_oneHundred)); | ||
| EXPECT_FALSE(IsLeapYear(g_oneHundred * 5)); | ||
| } | ||
|
|
||
| TEST(LeapYear, TestNotDivisible4_400_100) | ||
| { | ||
| EXPECT_FALSE(IsLeapYear(333)); | ||
| EXPECT_FALSE(IsLeapYear(555)); | ||
| } | ||
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
Oops, something went wrong.
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.
не хватает непосредственно ожидания - понятно, что он проверяет кратность 400, но непонятно что должно стать с таким числом - каково ожидаемое поведение