1
exercism fetch cpp robot-name

robot_name_test.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "robot_name.h"
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/regex.hpp>

using namespace std;

namespace
{
const boost::regex name_pattern{R"name(^[[:upper:]]{2}\d{3}$)name"};
}

BOOST_AUTO_TEST_CASE(has_a_name)
{
    const robot_name::robot robot;

    BOOST_REQUIRE(boost::regex_match(robot.name(), name_pattern));
}

#if defined(EXERCISM_RUN_ALL_TESTS)
BOOST_AUTO_TEST_CASE(name_is_the_same_each_time)
{
    const robot_name::robot robot;

    BOOST_REQUIRE_EQUAL(robot.name(), robot.name());
}

BOOST_AUTO_TEST_CASE(different_robots_have_different_names)
{
    const robot_name::robot robot_one;
    const robot_name::robot robot_two;

    BOOST_REQUIRE_NE(robot_one.name(), robot_two.name());
}

BOOST_AUTO_TEST_CASE(is_able_to_reset_name)
{
    robot_name::robot robot;
    const auto original_name = robot.name();

    robot.reset();

    BOOST_REQUIRE_NE(original_name, robot.name());
}

BOOST_AUTO_TEST_CASE(exhausting_digits_yields_different_names)
{
    robot_name::robot robot;
    auto last_name = robot.name();

    for (int i = 0; i < 1000; ++i) {
        robot.reset();
        BOOST_REQUIRE_NE(last_name, robot.name());
        BOOST_REQUIRE(boost::regex_match(robot.name(), name_pattern));
    }
}
#endif