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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.