Enumerator generator
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Catch2 の GENERATE および GENERATE_REF マクロと range generator から始め、その動作を expected_results に対するループと比較します。生成された値が CAPTURE にどのように公開されるかを追跡し、既存の generator API で手動のインデックス付けなしに要素とそのインデックスの両方を提供できるかを確認します。適切なアプローチを文書化または実装できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I'm using fff to mock a call and I have a std::vector of expected arguments for the mocked function. The way fff works, I need a generator that works like the Python enumerate statement: on each iteration it returns the iteration number and an element of my vector, so my test goes something like this:
REQUIRE(my_function_fake.arg0_history[i] == val_a);
REQUIRE(my_function_fake.arg1_history[i] == val_b);
I need both the vector element and the index. I'm trying to understand how to best go about it. My first try was to simply iterate over the vector and use CAPTURE:
uint32_t factorial(uint32_t number)
{
return number <= 1 ? number : factorial(number - 1) * number;
}
TEST_CASE("Factorials are computed", "[factorial]")
{
std::vector<std::tuple<uint32_t, uint32_t>> expected_results = {
{1, 1},
{2, 2},
{3, 6},
{10, 3'628'800+1}, // Bad value
};
for( int i = -1; const auto& v : expected_results ) {
++i;
auto& [input, expected] = v;
CAPTURE(i, input, expected);
REQUIRE(factorial(input) == expected);
}
This works great, I get a nice error message with the particular values that failed:
test.cc:50: FAILED:
REQUIRE( factorial(input) == expected )
with expansion:
3628800 (0x375f00) == 3628801 (0x375f01)
with messages:
i := 3
input := 10
expected := 3628801 (0x375f01)
Using the range generator seems a bit overly complicated:
size_t i = GENERATE_REF(Catch::Generators::range(static_cast<size_t>(0), expected_results.size()));
auto [input, expected] = expected_results[i];
CAPTURE(i, input, expected);
REQUIRE(factorial(input) == expected);
Is there a way to use one of the GENERATE macros for this?
Thanks!
- 主要言語
- C++
- スター
- 21.6k
- フォーク
- 3.4k
- 平均マージ
- 3日 12時間
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
catchorg/Catch2 のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 2 日以内に返信
-
catch_discover_tests passes all EXTRA_ARGS as one argument対応中かも @CyberKun が 11 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
catchorg/Catch2#3239 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Not seeing some error messages from fakeit in jetbrains rider対応中かも @Amanpal9 が 21 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
catchorg/Catch2#3228 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
catch_discover_tests fails for Emscripten/WASM tests since v3.16.0対応中かも @nafiurahman00 が 8 日前に担当しました。 オープンExtras
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
catchorg/Catch2#3241 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 2 日以内に返信
catchorg/Catch2 の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
cp-algorithms/cp-algorithms#1774 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
telefonicaid/fiware-orion#4836 ·
メンテナーはふだん 1 日以内に返信
-
nixd exits at startup when its parent process belongs to another user対応中かも @conao3 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nix-community/nixd#930 ·
メンテナーはふだん 2 日以内に返信
-
refactor topic-ui topic-weather
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Command-Install Needs-Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
microsoft/winget-cli#6718 ·
メンテナーはふだん 2 日以内に返信