Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Food Module is Added. #237

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions include/faker-cxx/Food.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#pragma once

#include <string>

namespace faker {

class Food {

public:
/**
* @brief Returns a random alcoholic beverage name.
*
* @returns Alcoholic beverage.
*
* @code
* Food::alcoholicBeverage() // "champain"
* @endcode
*/
static std::string alcoholicBeverage();

/**
* @brief Returns a random grain measurement.
*
* @returns Grain.
*
* @code
* Food::grain() // "1 Lt"
* @endcode
*/
static std::string grain();

/**
* @brief Returns a random milk product's name.
*
* @returns Milk product.
*
* @code
* Food::milkProduct() // "mozzarella"
* @endcode
*/
static std::string milkProduct();

/**
* @brief Returns a random fruit's name.
*
* @returns Fruit.
*
* @code
* Food::fruit() // "apple"
* @endcode
*/
static std::string fruit();

/**
* @brief Returns a random meat's name.
*
* @returns Meat.
*
* @code
* Food::meat() // "antrikot"
* @endcode
*/
static std::string meat();

/**
* @brief Returns a random seafood's name.
*
* @returns Seafood.
*
* @code
* Food::seafood() // "lobster"
* @endcode
*/
static std::string seafood();

/**
* @brief Returns a random vegetable's name.
*
* @returns Vegetable.
*
* @code
* Food::vegetable() // "watermelon"
* @endcode
*/
static std::string vegetable();

/**
* @brief Returns a random oil's name.
*
* @returns Oil.
*
* @code
* Food::oil() // "olive oil"
* @endcode
*/
static std::string oil();

/**
* @brief Returns a random nut's name.
*
* @returns Nuts.
*
* @code
* Food::nut() // "walnut"
* @endcode
*/
static std::string nut();

/**
* @brief Returns a random seed's name.
*
* @returns Seed.
*
* @code
* Food::seed() // "mozzarella"
* @endcode
*/
static std::string seed();

/**
* @brief Returns a random sugar product's name.
*
* @returns Sugar product.
*
* @code
* Food::sugarProduct() // "honey harmony"
* @endcode
*/
static std::string sugarProduct();

/**
* @brief Returns a random non-alcoholic beverage's name.
*
* @returns Non-alcoholic Beverage.
*
* @code
* Food::nonalcoholicBeverage() // "water"
* @endcode
*/
static std::string nonalcoholicBeverage();

/**
* @brief Returns a random dish's name.
*
* @returns Dish.
*
* @code
* Food::dishName() // "beef wellington"
* @endcode
*/
static std::string dishName();

/**
* @brief Returns a random food categories' name.
*
* @returns Food Category.
*
* @code
* Food::foodCategory() // "Dairy"
* @endcode
*/
static std::string foodCategory();
};
}
77 changes: 77 additions & 0 deletions src/modules/food/Food.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "faker-cxx/Food.h"

#include "data/alcoholicBeverages.h"
#include "data/dishNames.h"
#include "data/foodCategories.h"
#include "data/fruits.h"
#include "data/grains.h"
#include "data/meats.h"
#include "data/milkProducts.h"
#include "data/nonalcoholicBeverages.h"
#include "data/nuts.h"
#include "data/oils.h"
#include "data/seafoods.h"
#include "data/seeds.h"
#include "data/sugarProducts.h"
#include "data/vegetables.h"

#include "faker-cxx/Helper.h"

namespace faker {

std::string Food::alcoholicBeverage() {
return Helper::arrayElement<std::string>(alcoholicBeverages);
}

std::string Food::dishName() {
return Helper::arrayElement<std::string>(dishNames);
}

std::string Food::foodCategory() {
return Helper::arrayElement<std::string>(foodCategories);
}

std::string Food::fruit() {
return Helper::arrayElement<std::string>(fruits);
}

std::string Food::grain() {
return Helper::arrayElement<std::string>(grains);
}

std::string Food::meat() {
return Helper::arrayElement<std::string>(meats);
}

std::string Food::milkProduct() {
return Helper::arrayElement<std::string>(milkProducts);
}

std::string Food::nonalcoholicBeverage() {
return Helper::arrayElement<std::string>(nonalcoholicBeverages);
}

std::string Food::nut() {
return Helper::arrayElement<std::string>(nuts);
}

std::string Food::oil() {
return Helper::arrayElement<std::string>(oils);
}

std::string Food::seafood() {
return Helper::arrayElement<std::string>(seafoods);
}

std::string Food::seed() {
return Helper::arrayElement<std::string>(seeds);
}

std::string Food::sugarProduct() {
return Helper::arrayElement<std::string>(sugarProducts);
}

std::string Food::vegetable() {
return Helper::arrayElement<std::string>(vegetables);
}
}
132 changes: 132 additions & 0 deletions src/modules/food/FoodTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#include "faker-cxx/Food.h"

#include <algorithm>

#include "gtest/gtest.h"

#include "data/alcoholicBeverages.h"
#include "data/dishNames.h"
#include "data/foodCategories.h"
#include "data/fruits.h"
#include "data/grains.h"
#include "data/meats.h"
#include "data/milkProducts.h"
#include "data/nonalcoholicBeverages.h"
#include "data/nuts.h"
#include "data/oils.h"
#include "data/seafoods.h"
#include "data/seeds.h"
#include "data/sugarProducts.h"
#include "data/vegetables.h"

using namespace ::testing;
using namespace faker;

class FoodTest : public Test
{
public:
};

TEST_F(FoodTest, shouldGenerateAlcoholicBeverage)
{
const auto generatedAlcoholicBeverage = Food::alcoholicBeverage();

ASSERT_TRUE(
std::ranges::any_of(alcoholicBeverages, [generatedAlcoholicBeverage](const std::string& alcoholicBeverage) { return generatedAlcoholicBeverage == alcoholicBeverage; }));
}

TEST_F(FoodTest, shouldGenerateDishName)
{
const auto generatedDishName = Food::dishName();

ASSERT_TRUE(std::ranges::any_of(dishNames, [generatedDishName](const std::string& dishName)
{ return generatedDishName == dishName; }));
}

TEST_F(FoodTest, shouldGenerateFoodCategories)
{
const auto generatedFoodCategory = Food::foodCategory();

ASSERT_TRUE(std::ranges::any_of(foodCategories, [generatedFoodCategory](const std::string& foodCategory)
{ return generatedFoodCategory == foodCategory; }));
}

TEST_F(FoodTest, shouldGenerateFruit)
{
const auto generatedFruit = Food::fruit();

ASSERT_TRUE(
std::ranges::any_of(fruits, [generatedFruit](const std::string& fruit) { return generatedFruit == fruit; }));
}

TEST_F(FoodTest, shouldGenerateMeat)
{
const auto generatedMeat = Food::meat();

ASSERT_TRUE(std::ranges::any_of(meats, [generatedMeat](const std::string& meat)
{ return generatedMeat == meat; }));
}

TEST_F(FoodTest, shouldGenerateMilkProduct)
{
const auto generatedMilkProduct = Food::milkProduct();

ASSERT_TRUE(std::ranges::any_of(milkProducts, [generatedMilkProduct](const std::string& milkProduct)
{ return generatedMilkProduct == milkProduct; }));
}

TEST_F(FoodTest, shouldGenerateNonalcoholicBeverages)
{
const auto generatedNonalcoholicBeverages = Food::nonalcoholicBeverage();

ASSERT_TRUE(std::ranges::any_of(nonalcoholicBeverages, [generatedNonalcoholicBeverages](const std::string& nonalcoholicBeverage)
{ return generatedNonalcoholicBeverages == nonalcoholicBeverage; }));
}

TEST_F(FoodTest, shouldGenerateNut)
{
const auto generatedNut = Food::nut();

ASSERT_TRUE(std::ranges::any_of(nuts, [generatedNut](const std::string& nut)
{ return generatedNut == nut; }));
}

TEST_F(FoodTest, shouldGenerateOil)
{
const auto generatedOil = Food::oil();

ASSERT_TRUE(std::ranges::any_of(oils, [generatedOil](const std::string& oil)
{ return generatedOil == oil; }));
}

TEST_F(FoodTest, shouldGenerateSeafood)
{
const auto generatedSeafood = Food::seafood();

ASSERT_TRUE(std::ranges::any_of(seafoods, [generatedSeafood](const std::string& seafood)
{ return generatedSeafood == seafood; }));
}

TEST_F(FoodTest, shouldGenerateSeed)
{
const auto generatedSeed = Food::seed();

ASSERT_TRUE(std::ranges::any_of(seeds, [generatedSeed](const std::string& seed)
{ return generatedSeed == seed; }));
}

TEST_F(FoodTest, shouldGenerateSugarProduct)
{
const auto generatedSugarProduct = Food::sugarProduct();

ASSERT_TRUE(std::ranges::any_of(sugarProducts, [generatedSugarProduct](const std::string& sugarProduct)
{ return generatedSugarProduct == sugarProduct; }));
}

TEST_F(FoodTest, shouldGenerateVegetable)
{
const auto generatedVegetable = Food::vegetable();

ASSERT_TRUE(std::ranges::any_of(vegetables, [generatedVegetable](const std::string& vegetable)
{ return generatedVegetable == vegetable; }));
}
Loading