Skip to content

Commit 0f7f2d9

Browse files
committed
feat(Codewars): WIP onlinePlatform/codewars/5kyu/coding_with_squared_strings.cc
1 parent fee5bfd commit 0f7f2d9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/onlinePlatform/codewars/5kyu/coding_with_squared_strings.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <cmath>
77
#include <numeric> // For std::accumulate
88

9+
char FILLER_CHAR = (char) 11;
10+
std::string FILLER(1, FILLER_CHAR);
11+
auto LINE_SEPARATOR = "\n";
12+
913
std::string joinStringVector(const std::vector<std::string> &strings, const std::string &delimiter) {
1014
if (strings.empty()) {
1115
return "";
@@ -93,9 +97,6 @@ std::vector<std::vector<char> > toCharsVectors(const std::string &s) {
9397
return v;
9498
}
9599

96-
char FILLER_CHAR = (char) 11;
97-
std::string FILLER(1, FILLER_CHAR);
98-
99100
class CodeSqStrings {
100101
public:
101102
static std::string code(const std::string &strng) {
@@ -113,7 +114,7 @@ class CodeSqStrings {
113114
// rotate 90 degrees clockwise
114115
rotateClockwise(temp, 0);
115116

116-
return joinVectorCharVector(temp, "\n");
117+
return joinVectorCharVector(temp, LINE_SEPARATOR);
117118
}
118119

119120
static std::string decode(const std::string &strng) {

src/onlinePlatform/codewars/5kyu/coding_with_squared_strings_google_test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ TEST(CodingWithSquaredStrings, Tests_CodeDecode) {
1313
"\013ytrwbI .o rasiho\n\013, d e i rtev,se \n\013 t hflnW h e ny\n\013fhmioo emot Is o\n\013oeemrvt eshh tIu\n\013r eehw eaiwr \n"
1414
"\013eptc deea tmaelr\n\013iihot rtc?.naoe\n\013gcamhhre h tkom\n\013nntiaia meHAeyke\n\013.i ntmiwirend em";
1515
EXPECT_EQ(CodeSqStrings::code(d), s);
16+
EXPECT_EQ(CodeSqStrings::decode(s), d);
1617

1718
d = "Some say the world will end in fire, Some say in ice. From what I've tasted of desire "
1819
"I hold with those who favor fire. But if it had to perish twice, I think I know enough of hate"
@@ -21,4 +22,5 @@ TEST(CodingWithSquaredStrings, Tests_CodeDecode) {
2122
"\013w s nIo srm y\n\013oatso Bwhtoee \n\013ulrautpuhoem nt\n\013lsuyghetold sdh\n\013doc hir d wa e\n\013 tt niif ohyi \n\013sgihoksfawfa nw\n"
2223
"\013uroaf h vi ti o\n\013fent I iotd nfr";
2324
EXPECT_EQ(CodeSqStrings::code(d), s);
25+
EXPECT_EQ(CodeSqStrings::decode(s), d);
2426
}

0 commit comments

Comments
 (0)