Doing What It Takes to Clarify Tests

For our next test, we tackle the case where two adjacent letters encode to the same digit. Per Soundex rule #3, such duplicate letters get encoded as a single digit. The rule also states that it applies to the first letter. Let’s deal with the first case now and worry about the first letter next.

c2/29/SoundexTest.cpp
 
TEST_F(SoundexEncoding, CombinesDuplicateEncodings) {
 
ASSERT_THAT(soundex.encode(​"Abfcgdt"​), Eq(​"A123"​));
 
}

That’s a confusing test! To understand why Abfcgdt encodes to A123, we have to know that b and f both encode to 1, c and g both encode to 2, and d and t both encode to 3. We can learn these facts from reading other tests, such as ReplacesConsonantsWithAppropriateDigits, but maybe ...

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.