The Soundex Class
Since we’re ready to check in, let’s take a look at our solution. We decide that we don’t yet have a compelling reason to split out an implementation (.cpp) file, though that might be an essential part of making it production-ready in your system.
c2/40/SoundexTest.cpp | |
| #include "gmock/gmock.h" |
| #include "Soundex.h" |
| using namespace testing; |
| |
| class SoundexEncoding: public Test { |
| public: |
| Soundex soundex; |
| }; |
| |
| TEST_F(SoundexEncoding, RetainsSoleLetterOfOneLetterWord) { |
| ASSERT_THAT(soundex.encode("A"), Eq("A000")); |
| } |
| |
| TEST_F(SoundexEncoding, PadsWithZerosToEnsureThreeDigits) { |
| ASSERT_THAT(soundex.encode("I"), Eq("I000")); |
| } |
| |
| TEST_F(SoundexEncoding, ReplacesConsonantsWithAppropriateDigits) { |
|
Get Modern C++ Programming with Test-Driven Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.