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.12 Dropping Vowels

Rule #1 says to drop all occurrences of vowels and the letters ​w​, ​h​, and ​y​. For lack of a better name, we’ll refer to these as ​ vowel-like​ letters.

c2/28/SoundexTest.cpp
 
TEST_F(SoundexEncoding, IgnoresVowelLikeLetters) {
 
ASSERT_THAT(soundex.encode(​"Baeiouhycdl"​), Eq(​"B234"​));
 
}

The test passes without us adding a lick of production code, because ​encodedDigit​ answers an empty string if the letter to be encoded wasn’t found. Any vowels thus encode to the empty string, which gets harmlessly appended.

A test that passes with no change to your classes is always cause for humility and pause (see Section 3.5, Getting Green on Red).​ Ask yourself, “What might I have done differently?”

If a stream of subsequent ...

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