Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lhecker committed May 19, 2021
1 parent 4b0eeef commit 7fdfaa7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/inc/til/rle.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
// 1 1 1|2 2 2|3 3 3
//
// If we're called with:
// _replace_unchecked(3, 6, {{4, 2}, {5, 2}})
// _replace_unchecked(3, 6, {{1, 2}, {4, 1}, {2, 1}})
// Or shown in a more visual way:
// 1 1 1|2 2 2|3 3 3
// ^ ^ <-- the first ^ is "start_index" (inclusive) and the second "end_index" (exclusive)
Expand Down
27 changes: 16 additions & 11 deletions src/til/ut_til/RunLengthEncodingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,10 @@ class RunLengthEncodingTests

rle.replace(test_case.start_index, test_case.end_index, change);

try
{
VERIFY_ARE_EQUAL(test_case.expected, rle);
}
catch (...)
{
// I couldn't figure out how to attach additional info
// to a failed assertion so I'm doing it this way...
Log::Comment(NoThrowString().Format(
VERIFY_ARE_EQUAL(
test_case.expected,
rle,
NoThrowString().Format(
L"test case: %d\nsource: %hs\nstart_index: %u\nend_index: %u\nchange: %hs\nexpected: %hs\nactual: %s",
idx,
test_case.source.data(),
Expand All @@ -378,8 +373,6 @@ class RunLengthEncodingTests
test_case.change.data(),
test_case.expected.data(),
rle.to_string().c_str()));
throw;
}

++idx;
}
Expand Down Expand Up @@ -449,12 +442,24 @@ class RunLengthEncodingTests
{
constexpr std::string_view data{ "133211155" };

// shrink
for (size_type length = 0; length <= data.size(); length++)
{
rle_vector rle{ rle_encode(data) };
rle.resize_trailing_extent(length);
VERIFY_ARE_EQUAL(data.substr(0, length), rle);
}

// grow
{
std::string expected{ data };
expected.insert(expected.end(), 5, expected.back());

rle_vector actual{ rle_encode(data) };
actual.resize_trailing_extent(static_cast<size_type>(expected.size()));

VERIFY_ARE_EQUAL(std::string_view{ expected }, actual);
}
}

TEST_METHOD(Comparison)
Expand Down

0 comments on commit 7fdfaa7

Please sign in to comment.