From f3f340335fec9d3e602387343c0de8bf95f0aa46 Mon Sep 17 00:00:00 2001 From: Kasia Date: Fri, 17 Jun 2022 20:52:20 +0200 Subject: [PATCH] Make generic version of batcher function (#3822) --- benchmarks/CMakeLists.txt | 1 + benchmarks/src/Helpers.cpp | 46 ++++ .../notifications/NotificationController.cpp | 45 +--- .../notifications/NotificationController.hpp | 5 - src/providers/twitch/TwitchAccount.cpp | 28 +-- src/providers/twitch/TwitchIrcServer.cpp | 32 +-- src/util/Helpers.hpp | 30 +++ tests/CMakeLists.txt | 1 - tests/src/Helpers.cpp | 230 ++++++++++++++++++ tests/src/TwitchAccount.cpp | 157 ------------ 10 files changed, 316 insertions(+), 259 deletions(-) create mode 100644 benchmarks/src/Helpers.cpp delete mode 100644 tests/src/TwitchAccount.cpp diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index e8a8d0af..af78a0f9 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -5,6 +5,7 @@ set(benchmark_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/Emojis.cpp ${CMAKE_CURRENT_LIST_DIR}/src/Highlights.cpp ${CMAKE_CURRENT_LIST_DIR}/src/FormatTime.cpp + ${CMAKE_CURRENT_LIST_DIR}/src/Helpers.cpp # Add your new file above this line! ) diff --git a/benchmarks/src/Helpers.cpp b/benchmarks/src/Helpers.cpp new file mode 100644 index 00000000..acda59a3 --- /dev/null +++ b/benchmarks/src/Helpers.cpp @@ -0,0 +1,46 @@ +#include "util/Helpers.hpp" + +#include + +using namespace chatterino; + +template +void BM_SplitListIntoBatches(benchmark::State &state, Args &&...args) +{ + auto args_tuple = std::make_tuple(std::move(args)...); + for (auto _ : state) + { + auto result = splitListIntoBatches(std::get<0>(args_tuple), + std::get<1>(args_tuple)); + assert(!result.empty()); + } +} + +BENCHMARK_CAPTURE(BM_SplitListIntoBatches, 7 / 3, + QStringList{"", "", "", "", "", "", ""}, 3); +BENCHMARK_CAPTURE(BM_SplitListIntoBatches, 6 / 3, + QStringList{"", "", "", "", "", ""}, 3); +BENCHMARK_CAPTURE(BM_SplitListIntoBatches, 100 / 3, + QStringList{ + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", + }, + 3); +BENCHMARK_CAPTURE(BM_SplitListIntoBatches, 100 / 49, + QStringList{ + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", + }, + 49); diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index 0d20ce6e..1eae5d9b 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -10,6 +10,7 @@ #include "providers/twitch/api/Helix.hpp" #include "singletons/Toasts.hpp" #include "singletons/WindowManager.hpp" +#include "util/Helpers.hpp" #include "widgets/Window.hpp" #ifdef Q_OS_WIN @@ -35,15 +36,6 @@ void NotificationController::initialize(Settings &settings, Paths &paths) this->channelMap[Platform::Twitch].delayedItemsChanged.connect([this] { this->twitchSetting_.setValue(this->channelMap[Platform::Twitch].raw()); }); - /* - for (const QString &channelName : this->mixerSetting_.getValue()) { - this->channelMap[Platform::Mixer].appendItem(channelName); - } - - this->channelMap[Platform::Mixer].delayedItemsChanged.connect([this] { - this->mixerSetting_.setValue( - this->channelMap[Platform::Mixer]); - });*/ liveStatusTimer_ = new QTimer(); @@ -128,40 +120,12 @@ NotificationModel *NotificationController::createModel(QObject *parent, return model; } -namespace { - // TODO: combine this with getEmoteSetBatches in TwitchAccount.cpp, maybe some templated thing - std::vector getChannelsInBatches(QStringList channels) - { - constexpr int batchSize = 100; - - int batchCount = (channels.size() / batchSize) + 1; - - std::vector batches; - batches.reserve(batchCount); - - for (int i = 0; i < batchCount; i++) - { - QStringList batch; - - // I hate you, msvc - int last = (std::min)(batchSize, channels.size() - batchSize * i); - for (int j = 0; j < last; j++) - { - batch.push_back(channels.at(j + (batchSize * i))); - } - batches.emplace_back(batch); - } - - return batches; - } -} // namespace - void NotificationController::fetchFakeChannels() { qCDebug(chatterinoNotification) << "fetching fake channels"; QStringList channels; for (std::vector::size_type i = 0; - i != channelMap[Platform::Twitch].raw().size(); i++) + i < channelMap[Platform::Twitch].raw().size(); i++) { auto chan = getApp()->twitch->getChannelOrEmpty( channelMap[Platform::Twitch].raw()[i]); @@ -170,10 +134,11 @@ void NotificationController::fetchFakeChannels() channels.push_back(channelMap[Platform::Twitch].raw()[i]); } } - for (const auto &batch : getChannelsInBatches(channels)) + + for (const auto &batch : splitListIntoBatches(channels)) { getHelix()->fetchStreams( - QStringList(), batch, + {}, batch, [batch, this](std::vector streams) { std::unordered_set liveStreams; for (const auto &stream : streams) diff --git a/src/controllers/notifications/NotificationController.hpp b/src/controllers/notifications/NotificationController.hpp index abf1e311..6828c3be 100644 --- a/src/controllers/notifications/NotificationController.hpp +++ b/src/controllers/notifications/NotificationController.hpp @@ -15,7 +15,6 @@ class NotificationModel; enum class Platform : uint8_t { Twitch, // 0 - // Mixer, // 1 }; class NotificationController final : public Singleton, private QObject @@ -49,10 +48,6 @@ private: ChatterinoSetting> twitchSetting_ = { "/notifications/twitch"}; - /* - ChatterinoSetting> mixerSetting_ = { - "/notifications/mixer"}; - */ }; } // namespace chatterino diff --git a/src/providers/twitch/TwitchAccount.cpp b/src/providers/twitch/TwitchAccount.cpp index 31378d06..733acea2 100644 --- a/src/providers/twitch/TwitchAccount.cpp +++ b/src/providers/twitch/TwitchAccount.cpp @@ -17,36 +17,12 @@ #include "providers/twitch/TwitchUser.hpp" #include "providers/twitch/api/Helix.hpp" #include "singletons/Emotes.hpp" +#include "util/Helpers.hpp" #include "util/QStringHash.hpp" #include "util/RapidjsonHelpers.hpp" namespace chatterino { -std::vector getEmoteSetBatches(QStringList emoteSetKeys) -{ - // splitting emoteSetKeys to batches of 100, because Ivr API endpoint accepts a maximum of 100 emotesets at once - constexpr int batchSize = 100; - - int batchCount = (emoteSetKeys.size() / batchSize) + 1; - - std::vector batches; - batches.reserve(batchCount); - - for (int i = 0; i < batchCount; i++) - { - QStringList batch; - - int last = std::min(batchSize, emoteSetKeys.size() - batchSize * i); - for (int j = 0; j < last; j++) - { - batch.push_back(emoteSetKeys.at(j + (batchSize * i))); - } - batches.emplace_back(batch); - } - - return batches; -} - TwitchAccount::TwitchAccount(const QString &username, const QString &oauthToken, const QString &oauthClient, const QString &userID) : Account(ProviderId::Twitch) @@ -268,7 +244,7 @@ void TwitchAccount::loadUserstateEmotes(std::weak_ptr weakChannel) } // requesting emotes - auto batches = getEmoteSetBatches(newEmoteSetKeys); + auto batches = splitListIntoBatches(newEmoteSetKeys); for (int i = 0; i < batches.size(); i++) { qCDebug(chatterinoTwitch) diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index d803f45c..1286deb4 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -15,6 +15,7 @@ #include "providers/twitch/TwitchAccount.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchHelpers.hpp" +#include "util/Helpers.hpp" #include "util/PostToThread.hpp" #include @@ -26,35 +27,6 @@ using namespace std::chrono_literals; namespace chatterino { -namespace { - // TODO: combine this with getEmoteSetBatches in TwitchAccount.cpp, maybe some templated thing - template - std::vector getChannelsInBatches(T channels) - { - constexpr int batchSize = 100; - - int batchCount = (channels.size() / batchSize) + 1; - - std::vector batches; - batches.reserve(batchCount); - - for (int i = 0; i < batchCount; i++) - { - T batch; - - // I hate you, msvc - int last = (std::min)(batchSize, channels.size() - batchSize * i); - for (int j = 0; j < last; j++) - { - batch.push_back(channels.at(j + (batchSize * i))); - } - batches.emplace_back(batch); - } - - return batches; - } -} // namespace - TwitchIrcServer::TwitchIrcServer() : whispersChannel(new Channel("/whispers", Channel::Type::TwitchWhispers)) , mentionsChannel(new Channel("/mentions", Channel::Type::TwitchMentions)) @@ -344,7 +316,7 @@ void TwitchIrcServer::bulkRefreshLiveStatus() }); // iterate over batches of channel IDs - for (const auto &batch : getChannelsInBatches(twitchChans->keys())) + for (const auto &batch : splitListIntoBatches(twitchChans->keys())) { getHelix()->fetchStreams( batch, {}, diff --git a/src/util/Helpers.hpp b/src/util/Helpers.hpp index 10137c9b..8e5bd6a9 100644 --- a/src/util/Helpers.hpp +++ b/src/util/Helpers.hpp @@ -3,6 +3,8 @@ #include #include +#include + namespace chatterino { /** @@ -37,4 +39,32 @@ QColor getRandomColor(const QString &userId); QString formatUserMention(const QString &userName, bool isFirstWord, bool mentionUsersWithComma); +template +std::vector splitListIntoBatches(const T &list, int batchSize = 100) +{ + std::vector batches; + int batchCount = std::ceil(static_cast(list.size()) / batchSize); + batches.reserve(batchCount); + + auto it = list.cbegin(); + + for (int j = 0; j < batchCount; j++) + { + T batch; + + for (int i = 0; i < batchSize && it != list.end(); i++) + { + batch.append(*it); + it++; + } + if (batch.empty()) + { + break; + } + batches.emplace_back(std::move(batch)); + } + + return batches; +} + } // namespace chatterino diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6528a07b..72a3a6dc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,7 +10,6 @@ set(test_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/HighlightPhrase.cpp ${CMAKE_CURRENT_LIST_DIR}/src/Emojis.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ExponentialBackoff.cpp - ${CMAKE_CURRENT_LIST_DIR}/src/TwitchAccount.cpp ${CMAKE_CURRENT_LIST_DIR}/src/Helpers.cpp ${CMAKE_CURRENT_LIST_DIR}/src/RatelimitBucket.cpp ${CMAKE_CURRENT_LIST_DIR}/src/Hotkeys.cpp diff --git a/tests/src/Helpers.cpp b/tests/src/Helpers.cpp index 9ed012cc..7db1e1cd 100644 --- a/tests/src/Helpers.cpp +++ b/tests/src/Helpers.cpp @@ -20,3 +20,233 @@ TEST(Helpers, formatUserMention) // A user mention that is neither the first word, nor has 'mention with comma' enabled should not have a comma appended at the end. EXPECT_EQ(formatUserMention(userName, false, false), "pajlada"); } + +TEST(Helpers, BatchTwoParts) +{ + QStringList input{ + "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", "142", "143", "144", "145", "146", "147", "148", "149", "150", + }; + + std::vector expectation = { + { + "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", "142", "143", "144", "145", + "146", "147", "148", "149", "150", + }, + }; + + auto result = splitListIntoBatches(input); + + EXPECT_EQ(result, expectation); +} + +TEST(Helpers, NotEnoughForMoreThanOneBatch) +{ + QStringList input{ + "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", + }; + + std::vector expectation = { + { + "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", + }, + }; + + auto result = splitListIntoBatches(input); + + EXPECT_EQ(result, expectation); +} + +TEST(Helpers, BatchThreeParts) +{ + QStringList input{ + "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", "142", "143", "144", "145", "146", "147", "148", "149", "150", + "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", + "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", + "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", + "181", "182", "183", "184", "185", "186", "187", "188", "189", "190", + "191", "192", "193", "194", "195", "196", "197", "198", "199", "200", + "201", "202", "203", "204", "205", "206", "207", "208", "209", "210", + "211", "212", "213", "214", "215", "216", "217", "218", "219", "220", + "221", "222", "223", "224", "225", "226", "227", "228", "229", "230", + "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", + "241", "242", "243", "244", "245", "246", "247", "248", "249", "250", + }; + + std::vector expectation = { + { + "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", "142", "143", "144", "145", + "146", "147", "148", "149", "150", "151", "152", "153", "154", + "155", "156", "157", "158", "159", "160", "161", "162", "163", + "164", "165", "166", "167", "168", "169", "170", "171", "172", + "173", "174", "175", "176", "177", "178", "179", "180", "181", + "182", "183", "184", "185", "186", "187", "188", "189", "190", + "191", "192", "193", "194", "195", "196", "197", "198", "199", + "200", + }, + { + "201", "202", "203", "204", "205", "206", "207", "208", "209", + "210", "211", "212", "213", "214", "215", "216", "217", "218", + "219", "220", "221", "222", "223", "224", "225", "226", "227", + "228", "229", "230", "231", "232", "233", "234", "235", "236", + "237", "238", "239", "240", "241", "242", "243", "244", "245", + "246", "247", "248", "249", "250", + }, + }; + + auto result = splitListIntoBatches(input); + + EXPECT_EQ(result, expectation); +} + +TEST(Helpers, BatchOnePartDifferentSize) +{ + QStringList input{ + "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", + "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", + }; + + std::vector expectation{ + { + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + }, + { + "11", + "12", + "13", + "14", + "15", + "16", + "17", + "18", + "19", + "20", + }, + { + "21", + "22", + "23", + }, + }; + + auto result = splitListIntoBatches(input, 10); + + EXPECT_EQ(result, expectation); +} + +TEST(Helpers, BatchDifferentInputType) +{ + QList input{ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + }; + + std::vector> expectation{ + { + 1, + 2, + 3, + 4, + 5, + 6, + }, + { + 7, + 8, + 9, + 10, + 11, + 12, + }, + { + 13, + 14, + }, + }; + + auto result = splitListIntoBatches(input, 6); + + EXPECT_EQ(result, expectation); +} diff --git a/tests/src/TwitchAccount.cpp b/tests/src/TwitchAccount.cpp deleted file mode 100644 index bb7e400f..00000000 --- a/tests/src/TwitchAccount.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include "providers/twitch/TwitchAccount.hpp" - -#include - -using namespace chatterino; - -TEST(TwitchAccount, BatchTwoParts) -{ - QStringList bigList{ - "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", "142", "143", "144", "145", "146", "147", "148", "149", "150", - }; - - std::vector expectation = { - { - "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", "142", "143", "144", "145", - "146", "147", "148", "149", "150", - }, - }; - - auto result = getEmoteSetBatches(bigList); - - EXPECT_EQ(result, expectation); -} - -TEST(TwitchAccount, NotEnoughForMoreThanOneBatch) -{ - QStringList bigList{ - "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", - }; - - std::vector expectation = { - { - "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", - }, - }; - - auto result = getEmoteSetBatches(bigList); - - EXPECT_EQ(result, expectation); -} - -TEST(TwitchAccount, BatchThreeParts) -{ - QStringList bigList{ - "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", "142", "143", "144", "145", "146", "147", "148", "149", "150", - "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", - "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", - "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", - "181", "182", "183", "184", "185", "186", "187", "188", "189", "190", - "191", "192", "193", "194", "195", "196", "197", "198", "199", "200", - "201", "202", "203", "204", "205", "206", "207", "208", "209", "210", - "211", "212", "213", "214", "215", "216", "217", "218", "219", "220", - "221", "222", "223", "224", "225", "226", "227", "228", "229", "230", - "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", - "241", "242", "243", "244", "245", "246", "247", "248", "249", "250", - }; - - std::vector expectation = { - { - "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", "142", "143", "144", "145", - "146", "147", "148", "149", "150", "151", "152", "153", "154", - "155", "156", "157", "158", "159", "160", "161", "162", "163", - "164", "165", "166", "167", "168", "169", "170", "171", "172", - "173", "174", "175", "176", "177", "178", "179", "180", "181", - "182", "183", "184", "185", "186", "187", "188", "189", "190", - "191", "192", "193", "194", "195", "196", "197", "198", "199", - "200", - }, - { - "201", "202", "203", "204", "205", "206", "207", "208", "209", - "210", "211", "212", "213", "214", "215", "216", "217", "218", - "219", "220", "221", "222", "223", "224", "225", "226", "227", - "228", "229", "230", "231", "232", "233", "234", "235", "236", - "237", "238", "239", "240", "241", "242", "243", "244", "245", - "246", "247", "248", "249", "250", - }, - }; - - auto result = getEmoteSetBatches(bigList); - - EXPECT_EQ(result, expectation); -}