Skip to content

Commit

Permalink
Feature/person hobby (#177)
Browse files Browse the repository at this point in the history
* added Person::Hobby function

* Rearranged files and formatted them
  • Loading branch information
eric-bodhi authored Oct 5, 2023
1 parent 8713de0 commit f686a36
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/faker-cxx/Person.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,17 @@ class Person
* @endcode
*/
static std::string jobType();

/**
* @brief Returns a random hobby.
*
* @returns Hobby.
*
* @code
* Person::hobby() // "Gaming"
* @endcode
*/

static std::string hobby();
};
}
6 changes: 6 additions & 0 deletions src/modules/person/Person.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "data/german/GermanFirstNamesFemales.h"
#include "data/german/GermanFirstNamesMales.h"
#include "data/german/GermanLastNames.h"
#include "data/Hobbies.h"
#include "data/indian/IndianFirstNames.h"
#include "data/indian/IndianLastNames.h"
#include "data/italian/ItalianFirstNamesFemales.h"
Expand Down Expand Up @@ -179,4 +180,9 @@ std::string Person::prefix(std::optional<Sex> sex)
return Helper::arrayElement<std::string>(allPrefixes);
}
}

std::string Person::hobby()
{
return Helper::arrayElement<std::string>(hobbies);
}
}
9 changes: 9 additions & 0 deletions src/modules/person/PersonTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "data/german/GermanFirstNamesFemales.h"
#include "data/german/GermanFirstNamesMales.h"
#include "data/german/GermanLastNames.h"
#include "data/Hobbies.h"
#include "data/indian/IndianFirstNames.h"
#include "data/indian/IndianLastNames.h"
#include "data/italian/ItalianFirstNamesFemales.h"
Expand Down Expand Up @@ -317,3 +318,11 @@ TEST_F(PersonTest, shouldGenerateFemalePrefix)
ASSERT_TRUE(std::ranges::any_of(femalePrefixes, [generatedPrefix](const std::string& prefix)
{ return prefix == generatedPrefix; }));
}

TEST_F(PersonTest, shouldGenerateHobby)
{
const auto generatedHobby = Person::hobby();

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

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> hobbies = {
"Playing guitar",
"Reading books",
"Hiking",
"Cooking",
"Painting",
"Photography",
"Swimming",
"Gaming",
"Dancing",
"Traveling",
"Bird watching",
"Coding",
"Singing",
"Collecting stamps",
"Fishing",
"Yoga",
"Sculpting",
"Mountain biking",
"Chess",
"Archery",
"Rock climbing",
"Skiing",
"Writing poetry",
"Meditation",
"Solving puzzles",
"Gardening",
"Playing basketball",
"Volunteering",
"Playing board games",
"Astrophotography",
"Camping",
"Model building",
"Astronomy",
"Watching movies",
"Stargazing",
"Playing tennis",
"Cooking ethnic cuisines",
"Woodworking",
"Baking",
"Calligraphy",
"Pottery",
"Karaoke",
"Scuba diving",
"Metal detecting",
};
}

0 comments on commit f686a36

Please sign in to comment.