diff options
author | tau3 <smr.oznob@gmail.com> | 2021-04-15 15:45:38 +0400 |
---|---|---|
committer | tau3 <smr.oznob@gmail.com> | 2021-04-15 15:45:38 +0400 |
commit | 81fc4b353e8d148338cc8357ffe73e6dcb8fb294 (patch) | |
tree | 9ddeafcc37821ff30dcfb5a52246ef881d9e8e5f /test/feedcontainer.cpp | |
parent | d054a5b3629ab92e29993e2b641348fcd83fc46d (diff) |
unit test for last updated sort method
Diffstat (limited to 'test/feedcontainer.cpp')
-rw-r--r-- | test/feedcontainer.cpp | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/test/feedcontainer.cpp b/test/feedcontainer.cpp index 72e008fc..83bdaf91 100644 --- a/test/feedcontainer.cpp +++ b/test/feedcontainer.cpp @@ -496,12 +496,12 @@ TEST_CASE("sort_feeds() and keep in-group order when sorting by articles", ConfigContainer cfg; Cache rsscache(":memory:", &cfg); - const std::map<std::string, int> name_to_order = { + const std::map<std::string, int> name_to_articles = { {"a", 3}, {"b", 2}, {"c", 1}, {"d", 1}, {"e", 1} }; std::vector<std::shared_ptr<RssFeed>> feeds; - for (const auto& entry : name_to_order) { + for (const auto& entry : name_to_articles) { const auto feed = std::make_shared<RssFeed>(&rsscache, ""); feed->set_title(entry.first); for (int i=0; i<entry.second; ++i) { @@ -545,6 +545,61 @@ TEST_CASE("sort_feeds() and keep in-group order when sorting by articles", } } +TEST_CASE("sort_feeds() and keep in-group order when sorting by lsat updated item", + "[FeedContainer]") +{ + ConfigContainer cfg; + Cache rsscache(":memory:", &cfg); + + const std::map<std::string, int> name_to_date = { + {"a", 3}, {"b", 2}, {"c", 1}, {"d", 1}, {"e", 1} + }; + + std::vector<std::shared_ptr<RssFeed>> feeds; + for (const auto& entry : name_to_date) { + const auto feed = std::make_shared<RssFeed>(&rsscache, ""); + feed->set_title(entry.first); + auto item = std::make_shared<RssItem>(&rsscache); + item->set_pubDate(entry.second); + feed->add_item(item); + feeds.push_back(feed); + } + FeedContainer feedcontainer; + feedcontainer.set_feeds(feeds); + + FeedSortStrategy strategy; + strategy.sm = FeedSortMethod::LAST_UPDATED; + SECTION("descending order") { + strategy.sd = SortDirection::DESC; + feedcontainer.sort_feeds(strategy); + const auto sorted_feeds = feedcontainer.get_all_feeds(); + + std::vector<std::string> actual; + for (const auto& feed : sorted_feeds) { + auto title = feed->title(); + actual.push_back(title); + } + + const std::vector<std::string> expected = {"a", "b", "c", "d", "e"}; + REQUIRE(expected == actual); + } + + SECTION("acsending order") { + strategy.sd = SortDirection::ASC; + feedcontainer.sort_feeds(strategy); + const auto sorted_feeds = feedcontainer.get_all_feeds(); + + std::vector<std::string> actual; + for (const auto& feed : sorted_feeds) { + auto title = feed->title(); + actual.push_back(title); + } + + const std::vector<std::string> expected = {"c", "d", "e", "b", "a"} ; + REQUIRE(expected == actual); + } +} + TEST_CASE("sort_feeds() sorts by number of unread articles if `feed-sort-order` " "is \"unreadarticlecount\"", "[FeedContainer]") |