1
exercism fetch cpp say

say_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "say.h"
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(zero)
{
    BOOST_REQUIRE_EQUAL("zero", say::in_english(0ULL));
}

#if defined(EXERCISM_RUN_ALL_TESTS)
BOOST_AUTO_TEST_CASE(one)
{
    BOOST_REQUIRE_EQUAL("one", say::in_english(1ULL));
}

BOOST_AUTO_TEST_CASE(fourteen)
{
    BOOST_REQUIRE_EQUAL("fourteen", say::in_english(14ULL));
}

BOOST_AUTO_TEST_CASE(twenty)
{
    BOOST_REQUIRE_EQUAL("twenty", say::in_english(20ULL));
}

BOOST_AUTO_TEST_CASE(twenty_two)
{
    BOOST_REQUIRE_EQUAL("twenty-two", say::in_english(22ULL));
}

BOOST_AUTO_TEST_CASE(sixty_nine)
{
    BOOST_REQUIRE_EQUAL("sixty-nine", say::in_english(69ULL));
}

BOOST_AUTO_TEST_CASE(one_hundred)
{
    BOOST_REQUIRE_EQUAL("one hundred", say::in_english(100ULL));
}

BOOST_AUTO_TEST_CASE(one_hundred_twenty_three)
{
    BOOST_REQUIRE_EQUAL("one hundred twenty-three", say::in_english(123ULL));
}

BOOST_AUTO_TEST_CASE(one_thousand)
{
    BOOST_REQUIRE_EQUAL("one thousand", say::in_english(1000ULL));
}

BOOST_AUTO_TEST_CASE(one_thousand_two_hundred_thirty_four)
{
    BOOST_REQUIRE_EQUAL("one thousand two hundred thirty-four", say::in_english(1234ULL));
}

BOOST_AUTO_TEST_CASE(one_million)
{
    BOOST_REQUIRE_EQUAL("one million", say::in_english(1000ULL*1000ULL));
}

BOOST_AUTO_TEST_CASE(one_million_two)
{
    BOOST_REQUIRE_EQUAL("one million two", say::in_english(1000ULL*1000ULL + 2ULL));
}

BOOST_AUTO_TEST_CASE(one_million_two_thousand_three_hundred_forty_five)
{
    BOOST_REQUIRE_EQUAL("one million two thousand three hundred forty-five", say::in_english(1002345ULL));
}

BOOST_AUTO_TEST_CASE(one_billion)
{
    BOOST_REQUIRE_EQUAL("one billion", say::in_english(1000ULL*1000ULL*1000ULL));
}

BOOST_AUTO_TEST_CASE(a_really_big_number)
{
    BOOST_REQUIRE_EQUAL(
            "nine hundred eighty-seven billion"
            " six hundred fifty-four million"
            " three hundred twenty-one thousand"
            " one hundred twenty-three",
        say::in_english(987654321123ULL));
}

BOOST_AUTO_TEST_CASE(raises_an_error_below_zero)
{
    BOOST_REQUIRE_THROW(say::in_english(-1), std::domain_error);
}

BOOST_AUTO_TEST_CASE(raises_an_error_for_one_trillion)
{
    BOOST_REQUIRE_THROW(say::in_english(1000ULL*1000ULL*1000ULL*1000ULL), std::domain_error);
}
#endif