From 7c01cdcc3bec72325de9e353589c5abca04c4a92 Mon Sep 17 00:00:00 2001 From: Mayank Pareek Date: Mon, 28 Oct 2024 09:42:02 -0400 Subject: [PATCH] update test for plant module --- tests/modules/plant_test.cpp | 104 +++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 28 deletions(-) diff --git a/tests/modules/plant_test.cpp b/tests/modules/plant_test.cpp index 3967839d4..4cade2f62 100644 --- a/tests/modules/plant_test.cpp +++ b/tests/modules/plant_test.cpp @@ -7,73 +7,121 @@ #include "plant_data.h" using namespace ::testing; +using namespace faker; using namespace faker::plant; -class PlantTest : public Test +namespace +{ +const struct PlantDefinition& getPlantDefinition(Locale locale) +{ + switch (locale) + { + default: + return enUSPlantDefinition; + } +} +} + +class PlantTest : public TestWithParam { public: }; -TEST_F(PlantTest, shouldGenerateTree) +TEST_P(PlantTest, shouldGenerateTree) { - const auto generatedTree = tree(); + const auto locale = GetParam(); + + const auto& plantDefinition = getPlantDefinition(locale); - ASSERT_TRUE( - std::ranges::any_of(trees, [generatedTree](const std::string_view& tree) { return tree == generatedTree; })); + const auto generatedTree = tree(locale); + + ASSERT_TRUE(std::ranges::any_of(plantDefinition.trees, + [generatedTree](const std::string_view& tree) { return tree == generatedTree; })); } -TEST_F(PlantTest, shouldGenerateFlower) +TEST_P(PlantTest, shouldGenerateFlower) { - const auto generatedFlower = flower(); + const auto locale = GetParam(); + + const auto& plantDefinition = getPlantDefinition(locale); + + const auto generatedFlower = flower(locale); - ASSERT_TRUE(std::ranges::any_of(flowers, [generatedFlower](const std::string_view& flower) + ASSERT_TRUE(std::ranges::any_of(plantDefinition.flowers, [generatedFlower](const std::string_view& flower) { return flower == generatedFlower; })); } -TEST_F(PlantTest, shouldGenerateShrub) +TEST_P(PlantTest, shouldGenerateShrub) { - const auto generatedShrub = shrub(); + const auto locale = GetParam(); + + const auto& plantDefinition = getPlantDefinition(locale); + + const auto generatedShrub = shrub(locale); - ASSERT_TRUE(std::ranges::any_of(shrubs, [generatedShrub](const std::string_view& shrub) + ASSERT_TRUE(std::ranges::any_of(plantDefinition.shrubs, [generatedShrub](const std::string_view& shrub) { return shrub == generatedShrub; })); } -TEST_F(PlantTest, shouldGenerateGrass) +TEST_P(PlantTest, shouldGenerateGrass) { - const auto generatedGrass = grass(); + const auto locale = GetParam(); - ASSERT_TRUE(std::ranges::any_of(grasses, [generatedGrass](const std::string_view& grass) + const auto& plantDefinition = getPlantDefinition(locale); + + const auto generatedGrass = grass(locale); + + ASSERT_TRUE(std::ranges::any_of(plantDefinition.grasses, [generatedGrass](const std::string_view& grass) { return grass == generatedGrass; })); } -TEST_F(PlantTest, shouldGenerateFern) +TEST_P(PlantTest, shouldGenerateFern) { - const auto generatedFern = fern(); + const auto locale = GetParam(); + + const auto& plantDefinition = getPlantDefinition(locale); - ASSERT_TRUE( - std::ranges::any_of(ferns, [generatedFern](const std::string_view& fern) { return fern == generatedFern; })); + const auto generatedFern = fern(locale); + + ASSERT_TRUE(std::ranges::any_of(plantDefinition.ferns, + [generatedFern](const std::string_view& fern) { return fern == generatedFern; })); } -TEST_F(PlantTest, shouldGenerateSucculent) +TEST_P(PlantTest, shouldGenerateSucculent) { - const auto generatedSucculent = succulent(); + const auto locale = GetParam(); + + const auto& plantDefinition = getPlantDefinition(locale); + + const auto generatedSucculent = succulent(locale); - ASSERT_TRUE(std::ranges::any_of(succulents, [generatedSucculent](const std::string_view& succulent) + ASSERT_TRUE(std::ranges::any_of(plantDefinition.succulents, [generatedSucculent](const std::string_view& succulent) { return succulent == generatedSucculent; })); } -TEST_F(PlantTest, shouldGenerateVine) +TEST_P(PlantTest, shouldGenerateVine) { - const auto generatedVine = vine(); + const auto locale = GetParam(); - ASSERT_TRUE( - std::ranges::any_of(vines, [generatedVine](const std::string_view& vine) { return vine == generatedVine; })); + const auto& plantDefinition = getPlantDefinition(locale); + + const auto generatedVine = vine(locale); + + ASSERT_TRUE(std::ranges::any_of(plantDefinition.vines, + [generatedVine](const std::string_view& vine) { return vine == generatedVine; })); } -TEST_F(PlantTest, shouldGenerateType) +TEST_P(PlantTest, shouldGenerateType) { - const auto generatedType = plantType(); + const auto locale = GetParam(); + + const auto& plantDefinition = getPlantDefinition(locale); - ASSERT_TRUE(std::ranges::any_of(plantTypes, [generatedType](const std::string_view& plantType) + const auto generatedType = plantType(locale); + + ASSERT_TRUE(std::ranges::any_of(plantDefinition.plantTypes, [generatedType](const std::string_view& plantType) { return plantType == generatedType; })); } + +INSTANTIATE_TEST_SUITE_P(TestPlantByLocale, PlantTest, ValuesIn(locales), + [](const TestParamInfo& paramInfo) { return toString(paramInfo.param); });