Enumerator generator
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 42/100
Línea de trabajo
Comienza con las macros GENERATE y GENERATE_REF de Catch2 y el generador de rangos, y compara después su comportamiento con el bucle sobre expected_results. Traza cómo se exponen los valores generados a CAPTURE y determina si la API de generadores existente puede proporcionar tanto un elemento como su índice sin indexación manual; se considera terminado cuando se haya documentado o implementado el enfoque adecuado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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!
- Lenguaje dominante
- C++
- Estrellas
- 21.6k
- Forks
- 3.4k
- Merge medio
- 3 d 12 h
- PR fusionados (30 d)
- 5
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de catchorg/Catch2
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Los mantenedores suelen responder en 2 días
-
catch_discover_tests passes all EXTRA_ARGS as one argumentPosiblemente ocupada @CyberKun la tomó hace 11 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
catchorg/Catch2#3239 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Not seeing some error messages from fakeit in jetbrains riderPosiblemente ocupada @Amanpal9 la tomó hace 21 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
catchorg/Catch2#3228 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
catch_discover_tests fails for Emscripten/WASM tests since v3.16.0Posiblemente ocupada @nafiurahman00 la tomó hace 8 días. AbiertoExtras
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
catchorg/Catch2#3241 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 2 días
Todos los issues de catchorg/Catch2
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
cp-algorithms/cp-algorithms#1774 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
telefonicaid/fiware-orion#4836 ·
Los mantenedores suelen responder en 1 día
-
nixd exits at startup when its parent process belongs to another userPosiblemente ocupada @conao3 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
nix-community/nixd#930 ·
Los mantenedores suelen responder en 2 días
-
refactor topic-ui topic-weather
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Command-Install Needs-Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
microsoft/winget-cli#6718 ·
Los mantenedores suelen responder en 2 días