summaryrefslogtreecommitdiffstats
path: root/StringTools/test/Char__CopySign.cpp
blob: a35bdbdc888f720f677ced68d1d4be995b8fb44e (plain)
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
#include <StringTools/CharTools.h>
#include "Catch2.h"

using namespace Leonetienne::StringTools;


TEST_CASE(__FILE__"/JustChars", "[Char][CopySign]")
{
    // Setup
    // Correct letters
    const std::string in        = "tHEEuEUROPEanunioNCOnsiStsOFStATESIncLudingGERmanySWedenAndfRanCE";
    // Correct signs
    const std::string signs     = "AaaAAApqlkzicZnionceroigjreiojiopjaopickwapPjfipojWqfpohoijFucmwp";
    // Correct signs and letters
    const std::string expected  = "TheEUEuropeanUnionconsistsofstatesincludingGermanySwedenandFrance";

    // Exercise
    std::string out = in;
    for (std::size_t i = 0; i < in.size(); i++)
    {
        const char cs = signs[i];
        char& co = out[i];
        co = CharTools::CopySign(cs, co);
    }

    // Verify:
    REQUIRE(out == expected);
}

TEST_CASE(__FILE__"/WithSymbols", "[Char][CopySign]")
{
    // Setup
    // Correct letters
    const std::string in        = "ThE eu (euRoPeAN uNIon) cONsiSts Of 20 STAtes, iNCLUDInG GeRMAnY, sweden, aND fRancE.";
    // Correct signs
    const std::string signs     = "DwefOPerKofkaqdioJeriofgjqeiopqwqefijoqgehjloivxcvmopfkuoQpwfioqjiOqgjeprjgnvqPemrqij";
    // Correct signs and letters
    const std::string expected  = "The EU (European Union) consists of 20 states, including Germany, Sweden, and France.";

    // Exercise
    std::string out = in;
    for (std::size_t i = 0; i < in.size(); i++)
    {
        const char cs = signs[i];
        char& co = out[i];
        co = CharTools::CopySign(cs, co);
    }

    // Verify:
    REQUIRE(out == expected);
}

TEST_CASE(__FILE__"/DoesntChangeSignsIfSymbolSupplied", "[Char][CopySign]")
{
    // Setup
    const std::string in        = "ThE eu (euRoPeAN uNIon) cONsiSts Of 20 STAtes, iNCLUDInG GeRMAnY, sweden, aND fRancE.";
    const std::string signs     = "!§$)=%164)';:'*?)/!?/&()()?)*'_;:_,.93ß04750928372!!$==)()/!§$)=%)*'';:'*?)/!1572?/&(";
    const std::string expected  = in;

    // Exercise
    std::string out = in;
    for (std::size_t i = 0; i < in.size(); i++)
    {
        const char cs = signs[i];

        char& co = out[i];
        co = CharTools::CopySign(cs, co);
    }

    // Verify:
    REQUIRE(out == expected);
}