Skip to content

Commit

Permalink
rangelist: debug assert on negative numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Apr 19, 2021
1 parent b549298 commit cd95da5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/test/rangelist_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ TEST(DisplayIntListTest, duplicateValuesAreIgnored) {
EXPECT_EQ(QList<int>({1, 2, 3}), mixxx::parseRangeList("1, 1, 1, 1, 2, 2, 3"));
}

// TEST(DisplayIntListTest, negativeValuesAreIgnored) {
// EXPECT_EQ(QList<int>({}), mixxx::parseRangeList("-1,-2,-3"));
// EXPECT_QSTRING_EQ("", mixxx::stringifyRangeList(QList<int>({-1, -2, -3})));
// }

TEST(DisplayIntListTest, resultingListIsSortedAscending) {
const auto list = mixxx::parseRangeList("4, 2, 3, 1, 6, 5");
EXPECT_TRUE(std::is_sorted(list.cbegin(), list.cend()));
Expand Down
3 changes: 3 additions & 0 deletions src/util/rangelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ QString stringifyRangeList(const QList<int>& rangeList) {
auto first_duplicate = std::adjacent_find(rangeList.cbegin(), rangeList.cend());
return first_duplicate == rangeList.cend();
}());
DEBUG_ASSERT(std::all_of(rangeList.cbegin(), rangeList.cend(), [](int val) {
return val >= 0;
}));

QString stringifiedRangeList;

Expand Down
3 changes: 2 additions & 1 deletion src/util/rangelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ QList<int> parseRangeList(const QString& input);
/// take a list of positive integers and stringify them into a neat
/// user friendly representation (eg {1, 2, 3} => "1 - 3").
/// inverse counterpart of `parseRangeList`.
/// assumes rangeList is well-formed (sorted and not containing duplicates)
/// assumes rangeList is well-formed
/// (sorted, not containing duplicates, and positive integers only)
QString stringifyRangeList(const QList<int>& rangeList);

} // namespace mixxx

0 comments on commit cd95da5

Please sign in to comment.