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

A2.2 Let’s Go!

What are we building?

Story: Roman Numeral Converter

We need a function that takes an Arabic number and returns its Roman numeral equivalent (as a string).

One, Two, Three, ...

Getting the first test to pass will take us a few minutes, since there’s a good amount of setup work to do (getting the build script in place, adding header includes, and so on). There are also decisions to be made: What are we going to name our test method? What should the interface to our function look like?

We choose to make our conversion a free function. Here’s the first, failing test:

roman/1/RomanConverterTest.cpp
 
TEST(RomanConverter, CanConvertPositiveDigits) {
 
EXPECT_THAT(convert(1), Eq(​"I"​));
 
}

One of the goals for a kata is to minimize our ...

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