-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25cc377
commit a2726e4
Showing
14 changed files
with
98 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -2,4 +2,7 @@ build | |
.vscode | ||
cpm_modules | ||
.DS_Store | ||
.cache | ||
.cache | ||
compile_commands.json | ||
.cpm_cache | ||
make_compile_commands_json.sh |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,23 +1,26 @@ | ||
#include "effective_c++/clock.h" | ||
|
||
#include <iostream> | ||
#include <thread> | ||
|
||
using std::cout; | ||
using std::string; | ||
using namespace effective; | ||
|
||
Clock::Clock(int tickFrequency) : tick_frequency(tickFrequency) {} | ||
|
||
void Clock::onTick() const { cout << "Only tick."; } | ||
string Clock::onTick() const { return "tick "; } | ||
|
||
void Clock::tick() const { | ||
string Clock::tick() const { | ||
using std::this_thread::sleep_for; | ||
cout << "Tick begin"; | ||
while (is_running) { | ||
onTick(); | ||
auto num = 0; | ||
string result = "Tick begin "; | ||
while (is_running && (num < 10)) { | ||
num++; | ||
result += onTick(); | ||
// sleep for 1000 ms. | ||
sleep_for(std::chrono::milliseconds(1000 / tick_frequency)); | ||
} | ||
result += "end."; | ||
return result; | ||
} | ||
|
||
void Clock::stop() { is_running = false; } |
This file contains 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 |
---|---|---|
@@ -1,38 +1,37 @@ | ||
#include "effective_c++/home.h" | ||
|
||
#include <iostream> | ||
|
||
//> 不要导入整个命名空间std,因为会有符号名冲突。导入具体的符号可以将冲突范围最小化。 | ||
using std::cout; | ||
using std::string; | ||
using namespace effective; | ||
|
||
Home::Home(string address) : Clock(1), address_(address) {} | ||
|
||
Home::~Home() {} | ||
|
||
int Home::healthValue() const { | ||
cout << "do something before doHealthValue()."; | ||
int retVal = doHealthValue(); | ||
cout << "do something after doHealthValue()."; | ||
return retVal; | ||
string Home::healthValue() const { | ||
string before = "before "; | ||
string record = doHealthValue(); | ||
string after = " after."; | ||
return before + record + after; | ||
} | ||
|
||
void Home::draw(int color) const { doDraw(color); } | ||
string Home::draw(int color) const { return doDraw(color); } | ||
|
||
void Home::boardcastAddress() const { tick(); } | ||
string Home::boardcastAddress() const { return tick(); } | ||
|
||
int Home::doHealthValue() const { return 1; } | ||
string Home::doHealthValue() const { return "check health of full house"; } | ||
|
||
void Home::doDraw(int color) const { | ||
string Home::doDraw(int color) const { | ||
if (color == 1) { | ||
cout << "let paint the house as Red"; | ||
return "let paint the house as Red"; | ||
} | ||
return "bad color, can not paint."; | ||
} | ||
|
||
void Home::onTick() const { cout << "My home address is : " + address_; } | ||
string Home::onTick() const { return "My home address is : " + address_; } | ||
|
||
void Home::tick() const { | ||
cout << "This from home"; | ||
Clock::tick(); | ||
string Home::tick() const { | ||
string result = "This from home begin send address "; | ||
result += Clock::tick(); | ||
return result; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
#include "effective_c++/nest.h" | ||
|
||
#include <iostream> | ||
|
||
using std::cout; | ||
using namespace effective; | ||
|
||
int Nest::doHealthValue() const { return 2; } | ||
std::string Nest::doHealthValue() const { return "check health of full Nest"; } | ||
|
||
void Nest::doDraw(int color) const { | ||
std::string Nest::doDraw(int color) const { | ||
if (color == 2) { | ||
cout << "let paint the house as Blue"; | ||
return "let paint the house as Blue"; | ||
} | ||
return "bad color, can not paint."; | ||
} | ||
|
||
void Nest::onTick() const { cout << "My nest address is : " + address_; } | ||
std::string Nest::onTick() const { return "My nest address is : " + address_; } |
This file contains 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,17 @@ | ||
#include "effective_c++/cave.h" | ||
|
||
using std::string; | ||
using namespace effective; | ||
|
||
Cave::Cave(string address) : Home(address) {} | ||
|
||
string Cave::doHealthValue() const { return "check health of full Cave"; } | ||
|
||
string Cave::doDraw(int color) const { | ||
if (color == 3) { | ||
return "let paint the house as Brown"; | ||
} | ||
return "bad color, can not paint."; | ||
} | ||
|
||
string Cave::onTick() const { return "My cave address is : " + address_; } |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,21 +1,14 @@ | ||
#include <doctest/doctest.h> | ||
#include <greeter/greeter.h> | ||
#include <greeter/version.h> | ||
|
||
#include <string> | ||
|
||
TEST_CASE("Greeter") { | ||
using namespace greeter; | ||
|
||
Greeter greeter("Tests"); | ||
|
||
CHECK(greeter.greet(LanguageCode::EN) == "Hello, Tests!"); | ||
CHECK(greeter.greet(LanguageCode::DE) == "Hallo Tests!"); | ||
CHECK(greeter.greet(LanguageCode::ES) == "¡Hola Tests!"); | ||
CHECK(greeter.greet(LanguageCode::FR) == "Bonjour Tests!"); | ||
} | ||
|
||
TEST_CASE("Greeter version") { | ||
static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0")); | ||
CHECK(std::string(GREETER_VERSION) == std::string("1.0")); | ||
#include "effective_c++/cave.h" | ||
|
||
#include "doctest/doctest.h" | ||
|
||
TEST_CASE("Cave") { | ||
using namespace effective; | ||
auto one_cave = Cave("ParaMountain"); | ||
one_cave.boardcastAddress(); | ||
CHECK(one_cave.draw(3) == "let paint the house as Brown"); | ||
CHECK(one_cave.healthValue() == "before check health of full Cave after."); | ||
CHECK(one_cave.GetAddress("decorate ") == "decorate ParaMountain"); | ||
CHECK(one_cave.GetAddress() == "ParaMountain"); | ||
CHECK(one_cave.boardcastAddress() == "This from home begin send address Tick begin My cave address is : ParaMountainMy cave address is : ParaMountainMy cave address is : ParaMountainMy cave address is : ParaMountainMy cave address is : ParaMountainMy cave address is : ParaMountainMy cave address is : ParaMountainMy cave address is : ParaMountainMy cave address is : ParaMountainMy cave address is : ParaMountainend."); | ||
} |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | ||
|
||
#include <doctest/doctest.h> | ||
#include "doctest/doctest.h" |