Skip to content

Commit

Permalink
Zodiac signs (#248)
Browse files Browse the repository at this point in the history
* Added Zodiac Signs Vectors
Both Western and Chinese Zodiacs

* Zodiac Generator
Two functions, each to generate a random western/chinese zodiac.

* Zodiac Tests
Test the two Zodiac Generator functions

* Ran clang-format

* Fixed Include Paths
  • Loading branch information
ViviGayming authored Nov 12, 2023
1 parent d43d6ea commit e3742fa
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/faker-cxx/Food.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

#include <string>

namespace faker {
namespace faker
{

class Food
{

class Food {

public:
/**
* @brief Returns a random alcoholic beverage name.
Expand Down
24 changes: 24 additions & 0 deletions include/faker-cxx/Person.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,29 @@ class Person
*/

static std::string nationality();

/**
* @brief Returns a random Western Zodiac
*
* @returns Western Zodiac
*
* @code
* Person::westernZodiac() // "Virgo"
* @endcode
*/

static std::string westernZodiac();

/**
* @brief Returns a random Chinese Zodiac
*
* @returns Chinese Zodiac
*
* @code
* Person::chineseZodiac() // "Dragon"
* @endcode
*/

static std::string chineseZodiac();
};
}
11 changes: 11 additions & 0 deletions src/modules/person/Person.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "data/turkish/TurkishPeopleNames.h"
#include "faker-cxx/Helper.h"
#include "fmt/format.h"
#include "data/ZodiacSigns.h"

namespace faker
{
Expand Down Expand Up @@ -396,4 +397,14 @@ std::string suffixForLanguage(Language language, std::optional<Sex> sex)
return Helper::arrayElement<std::string>(suffixes);
}
}

std::string Person::westernZodiac()
{
return Helper::arrayElement<std::string>(westernZodiacs);
}

std::string Person::chineseZodiac()
{
return Helper::arrayElement<std::string>(chineseZodiacs);
}
}
18 changes: 18 additions & 0 deletions src/modules/person/PersonTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "data/italian/ItalianPeopleNames.h"
#include "data/JobTitles.h"
#include "data/Nationalities.h"
#include "data/ZodiacSigns.h"
#include "data/nepalese/NepalesePeopleNames.h"
#include "data/polish/PolishPeopleNames.h"
#include "data/romanian/RomanianPeopleNames.h"
Expand Down Expand Up @@ -383,3 +384,20 @@ TEST_F(PersonTest, shouldGenerateNationality)
ASSERT_TRUE(std::ranges::any_of(nationalities, [generatedNationality](const std::string& nationality)
{ return generatedNationality == nationality; }));
}

TEST_F(PersonTest, shouldGenerateWesternZodiacs)
{
const auto generatedWesternZodiacs = Person::westernZodiac();

ASSERT_TRUE(std::ranges::any_of(westernZodiacs, [generatedWesternZodiacs](const std::string& westernZodiac)
{ return generatedWesternZodiacs == westernZodiac;}));

}

TEST_F(PersonTest, shouldGenerateChineseZodiacs)
{
const auto generatedChineseZodiacs = Person::chineseZodiac();

ASSERT_TRUE(std::ranges::any_of(chineseZodiacs, [generatedChineseZodiacs](const std::string& chineseZodiac)
{ return generatedChineseZodiacs == chineseZodiac;}));
}
35 changes: 35 additions & 0 deletions src/modules/person/data/ZodiacSigns.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <string>
#include <vector>


const std::vector<std::string> westernZodiacs = {
"Aries",
"Taurus",
"Gemini",
"Cancer",
"Leo",
"Virgo",
"Libra",
"Scorpio",
"Sagittarius",
"Capricorn",
"Aquarius",
"Pisces"
};

const std::vector<std::string> chineseZodiacs = {
"Rat",
"Ox",
"Tiger",
"Rabbit",
"Dragon",
"Snake"
"Horse",
"Sheep",
"Monkey"
"Rooster",
"Dog",
"Pig"
};

0 comments on commit e3742fa

Please sign in to comment.