1
exercism fetch cpp crypto-square

crypto_square_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
#include "crypto_square.h"
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(normalize_capitals)
{
    BOOST_REQUIRE_EQUAL("hello", crypto_square::cipher("Hello").normalize_plain_text());
}

#if defined(EXERCISM_RUN_ALL_TESTS)
BOOST_AUTO_TEST_CASE(normalize_spaces)
{
    BOOST_REQUIRE_EQUAL("hithere", crypto_square::cipher("Hi there").normalize_plain_text());
}

BOOST_AUTO_TEST_CASE(normalize_numbers)
{
    BOOST_REQUIRE_EQUAL("123go", crypto_square::cipher("1, 2, 3 GO!").normalize_plain_text());
}

BOOST_AUTO_TEST_CASE(plain_text_empty)
{
    const std::vector<std::string> expected{};

    const auto actual = crypto_square::cipher("").plain_text_segments();

    BOOST_REQUIRE_EQUAL_COLLECTIONS(expected.begin(), expected.end(), actual.begin(), actual.end());
}

BOOST_AUTO_TEST_CASE(plain_text_4_characters)
{
    const std::vector<std::string> expected{"ab", "cd"};

    const auto actual = crypto_square::cipher("Ab Cd").plain_text_segments();

    BOOST_REQUIRE_EQUAL_COLLECTIONS(expected.begin(), expected.end(), actual.begin(), actual.end());
}

BOOST_AUTO_TEST_CASE(plain_text_9_characters)
{
    const std::vector<std::string> expected{"thi", "sis", "fun"};

    const auto actual = crypto_square::cipher("This is fun!").plain_text_segments();

    BOOST_REQUIRE_EQUAL_COLLECTIONS(expected.begin(), expected.end(), actual.begin(), actual.end());
}

BOOST_AUTO_TEST_CASE(plain_text_segments_from_phrase)
{
    const std::vector<std::string> expected{"ifmanwas", "meanttos", "tayonthe", "groundgo", "dwouldha", "vegivenu", "sroots"};

    const auto actual = crypto_square::cipher("If man was meant to stay on the ground, god would have given us roots.").plain_text_segments();

    BOOST_REQUIRE_EQUAL_COLLECTIONS(expected.begin(), expected.end(), actual.begin(), actual.end());
}

BOOST_AUTO_TEST_CASE(cipher_text_empty_phrase)
{
    BOOST_REQUIRE_EQUAL("",
        crypto_square::cipher("").cipher_text());
}

BOOST_AUTO_TEST_CASE(cipher_text_long_phrase)
{
    BOOST_REQUIRE_EQUAL("imtgdvsfearwermayoogoanouuiontnnlvtwttddesaohghnsseoau",
        crypto_square::cipher("If man was meant to stay on the ground, god would have given us roots.").cipher_text());
}

BOOST_AUTO_TEST_CASE(normalized_cipher_text_empty)
{
    BOOST_REQUIRE_EQUAL("",
        crypto_square::cipher("").normalized_cipher_text());
}

BOOST_AUTO_TEST_CASE(normalized_cipher_text_fun)
{
    BOOST_REQUIRE_EQUAL("tsf hiu isn",
        crypto_square::cipher("This is fun!").normalized_cipher_text());
}

BOOST_AUTO_TEST_CASE(normalized_cipher_text_long_phrase)
{
    BOOST_REQUIRE_EQUAL("imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn  sseoau ",
        crypto_square::cipher("If man was meant to stay on the ground, god would have given us roots.").normalized_cipher_text());
}
#endif