Skip to content

Commit

Permalink
update test for plant module
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank-Pareek committed Oct 28, 2024
1 parent c2e3af9 commit 7c01cdc
Showing 1 changed file with 76 additions and 28 deletions.
104 changes: 76 additions & 28 deletions tests/modules/plant_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Locale>
{
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<Locale>& paramInfo) { return toString(paramInfo.param); });

0 comments on commit 7c01cdc

Please sign in to comment.