Awesome
correct_cpp_bool_to_coin
Branch | Travis CI | Codecov |
---|---|---|
master |
Correct C++ chapter 'Hello CLI'.
Goal
- Write an application with 100% code coverage
Prerequisites
- Understand how this course works
- Have written a correct 'is_odd' program
Exercise
Write a command-line interface (CLI) program that converts a boolean (true
or false
) to a coin's side (heads
or tails
respectively),
followed by a newline. Fail if the user supplies no, two or more arguments.
Call to bool_to_coin | Output | Exit status |
---|---|---|
./bool_to_coin | Any | 1 |
./bool_to_coin true | heads (with newline) | 0 |
./bool_to_coin false | tails (with newline) | 0 |
./bool_to_coin nonsense | Any | 1 |
./bool_to_coin true true | Any | 1 |
This is the code you start with:
#include <iostream>
#include <string>
int main(int argc, char* argv[])
{
if (argc != 2)
{
return 1;
}
if (std::string(argv[1]) == "true")
{
std::cout << "heads\n";
}
else if (std::string(argv[1]) == "false")
{
std::cout << "tails\n";
}
else
{
return 1;
}
}
- Your code needs to have 100% code coverage, regardless how it is called (that is, with zero, one or more arguments), see how to get 100 percent code coverage
External links
- [none]