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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#include <iostream>
#include <iomanip>
#include <string>
#include <regex> // if required for arpify function
std::string arpify(const std::string& str);
bool run_all_tests(bool showFailuresOnly);
bool run_test(const std::string& str, const std::string& expectedStr, bool showFailuresOnly);
int main()
{
std::cout << std::boolalpha;
bool showFailuresOnly = true;
bool pass = run_all_tests(showFailuresOnly);
return (pass ? EXIT_SUCCESS : EXIT_FAILURE);
}
bool run_all_tests(bool showFailuresOnly)
{
struct TESTCASE
{
const char* str;
const char* expectedStr;
};
static const TESTCASE testCases[] = {
// original
{"fish", "farpish"},
{"Harry", "Harparry"},
{"condition", "carpondarpitarpion"},
// 1. When a vowel or vowel sound (a, e, i, o, u, or y as in why)
// is found, arp is placed in front of it.
// vowel in the middle start
{"can", "carpan"},
{"pen", "parpen"},
{"spin", "sparpin"},
{"cloth", "clarpoth"},
{"burn", "barpurn"},
{"why", "wharpy"},
// vowel in front
{"app", "arpapp"},
{"elk", "arpelk"},
{"ink", "arpink"},
{"ork", "arpork"},
{"urn", "arpurn"},
// see yttrium below
// semi-vowel detail
// w
{"growth", "grarpowth"}, // w part of ow
{"borrow", "barporrow"}, // w part of ow at end but not only vowel sound
{"brow", "brarpow"}, // w part of ow at end and only vowel sound
{"homework", "harpomarpewarpork"}, // w distinct
{"worker", "warporkarper"}, // w distinct at front
// w does not act on its own
// y
{"geyser", "garpeysarper"}, // y part of ey
{"prepay", "prarpepay"}, // y part of ay at end but not only vowel sound
{"gray", "grarpay"}, // y part of ay at end and only vowel sound
{"gapyear", "garpapyarpear"}, // y distinct
{"year", "yarpear"}, // y distinct at front
// y acting on its own
{"styrofoam", "starpyrarpofarpoam"}, // y on its own
{"stylus", "starpylarpus"}, // y on its own
// see yttrium below
// 2. Two or more vowels together are treated as one.
{"mean", "marpean"},
{"loan", "larpoan"},
{"sleet", "slarpeet"},
{"aesthetic", "arpaestharpetarpic"},
{"ook", "arpook"},
{"harpoon", "harparparpoon"},
// 3. If a vowel or vowel sound occurs as the final letter of a word,
// it is only given an arp if it is the only vowel or vowel sound
// in the word.
{"taboo", "tarpaboo"},
{"woo", "warpoo"},
{"slurpee", "slarpurpee"},
// more
{"beau", "barpeau"},
{"beauty", "barpeauty"},
{"bureau", "barpureau"},
{"cowpat", "carpowparpat"},
{"ewe", "arpewe"},
{"hardwood", "harpardwarpood"},
{"meow", "marpeow"},
{"miaow", "marpiaow"},
{"ow", "arpow"},
{"rhythm", "rharpythm"},
{"towpath", "tarpowparpath"},
{"upward", "arpupwarpard"},
{"wooed", "warpooed"},
{"yellow", "yarpellow"},
{"yttrium", "arpyttrarpium"},
};
// considered, but apparently not valid spellings:
// twittwoo (twit twoo/twit-twoo)
// nappyrash (nappy rash)
static const size_t testCaseCount = sizeof(testCases)/sizeof(testCases[0]);
size_t passCount = 0;
for(size_t i = 0; i < testCaseCount; ++i)
{
const TESTCASE& tc = testCases[i];
bool pass = run_test(tc.str, tc.expectedStr, showFailuresOnly);
if(pass)
++passCount;
}
std::cout << "ran = " << testCaseCount << std::endl
<< "passed = " << passCount << std::endl
<< "failed = " << (testCaseCount - passCount) << std::endl
<< std::endl;
return (passCount == testCaseCount);
}
bool run_test(const std::string& str, const std::string& expectedStr, bool showFailuresOnly)
{
std::string arpedStr = arpify(str);
bool pass = (arpedStr == expectedStr);
if(!pass || !showFailuresOnly)
{
std::cout << str << " -> " << arpedStr << std::endl
<< "pass = " << pass << std::endl;
if(!pass)
std::cout << "(expected " << expectedStr << ")" << std::endl;
std::cout << std::endl;
}
return pass;
}
std::string arpify(const std::string& str)
{
return str; // TODO : implement arpification algorithm
}
|