Skip to Content
Modern C++ Programming with Test-Driven Development
book

Modern C++ Programming with Test-Driven Development

by Jeff Langr
October 2013
Intermediate to advanced
368 pages
9h 20m
English
Pragmatic Bookshelf
Content preview from Modern C++ Programming with Test-Driven Development

2.13 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, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Effective Modern C++

Effective Modern C++

Scott Meyers
Modern CMake for C++

Modern CMake for C++

Rafał Świdziński
Embracing Modern C++ Safely

Embracing Modern C++ Safely

John Lakos, Vittorio Romeo, Rostislav Khlebnikov, Alisdair Meredith

Publisher Resources

ISBN: 9781941222423Errata