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

add movie module #78

Merged
merged 1 commit into from
Aug 12, 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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ set(FAKER_SOURCES
src/modules/system/System.cpp
src/modules/database/Database.cpp
src/modules/music/Music.cpp
src/modules/movie/Movie.cpp
)

set(FAKER_UT_SOURCES
Expand All @@ -64,6 +65,7 @@ set(FAKER_UT_SOURCES
src/modules/system/SystemTest.cpp
src/modules/database/DatabaseTest.cpp
src/modules/music/MusicTest.cpp
src/modules/movie/MovieTest.cpp
)

add_library(${LIBRARY_NAME} ${FAKER_SOURCES})
Expand Down
65 changes: 65 additions & 0 deletions include/faker-cxx/Movie.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once

#include <string>

namespace faker
{
class Movie
{
public:
/**
* @brief Returns a random movie genre.
*
* @returns Movie genre.
*
* @code
* Movie::genre() // "Drama"
* @endcode
*/
static std::string genre();

/**
* @brief Returns a random movie title.
*
* @returns Movie title.
*
* @code
* Movie::movieTitle() // "Pulp Fiction"
* @endcode
*/
static std::string movieTitle();

/**
* @brief Returns a random movie director name.
*
* @returns Movie director name.
*
* @code
* Movie::director() // "Quentin Tarantino"
* @endcode
*/
static std::string director();

/**
* @brief Returns a random actor name.
*
* @returns Actor name.
*
* @code
* Movie::actor() // "John Travolta"
* @endcode
*/
static std::string actor();

/**
* @brief Returns a random actress name.
*
* @returns Actress name.
*
* @code
* Movie::actress() // "Scarlett Johansson"
* @endcode
*/
static std::string actress();
};
}
36 changes: 36 additions & 0 deletions src/modules/movie/Movie.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "faker-cxx/Movie.h"

#include "data/Actors.h"
#include "data/Actresses.h"
#include "data/Directors.h"
#include "data/Genres.h"
#include "data/MovieTitles.h"
#include "faker-cxx/Helper.h"

namespace faker
{
std::string Movie::genre()
{
return Helper::arrayElement<std::string>(genres);
}

std::string Movie::movieTitle()
{
return Helper::arrayElement<std::string>(movieTitles);
}

std::string Movie::director()
{
return Helper::arrayElement<std::string>(directors);
}

std::string Movie::actor()
{
return Helper::arrayElement<std::string>(actors);
}

std::string Movie::actress()
{
return Helper::arrayElement<std::string>(actresses);
}
}
62 changes: 62 additions & 0 deletions src/modules/movie/MovieTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "faker-cxx/Movie.h"

#include <algorithm>

#include "gtest/gtest.h"

#include "data/Actors.h"
#include "data/Actresses.h"
#include "data/Directors.h"
#include "data/Genres.h"
#include "data/MovieTitles.h"

using namespace ::testing;
using namespace faker;

class MovieTest : public Test
{
public:
};

TEST_F(MovieTest, shouldGenerateGenre)
{
const auto generatedGenre = Movie::genre();

ASSERT_TRUE(std::any_of(genres.begin(), genres.end(),
[generatedGenre](const std::string& genre) { return generatedGenre == genre; }));
}

TEST_F(MovieTest, shouldGenerateMovieTitle)
{
const auto generatedMovieTitle = Movie::movieTitle();

ASSERT_TRUE(std::any_of(movieTitles.begin(), movieTitles.end(),
[generatedMovieTitle](const std::string& movieTitle) { return generatedMovieTitle == movieTitle; }));
}

TEST_F(MovieTest, shouldGenerateDirector)
{
const auto generatedDirector = Movie::director();

ASSERT_TRUE(std::any_of(directors.begin(), directors.end(),
[generatedDirector](const std::string& director)
{ return generatedDirector == director; }));
}

TEST_F(MovieTest, shouldGenerateActor)
{
const auto generatedActor = Movie::actor();

ASSERT_TRUE(std::any_of(actors.begin(), actors.end(),
[generatedActor](const std::string& actor)
{ return generatedActor == actor; }));
}

TEST_F(MovieTest, shouldGenerateActress)
{
const auto generatedActress = Movie::actress();

ASSERT_TRUE(std::any_of(actresses.begin(), actresses.end(),
[generatedActress](const std::string& actress)
{ return generatedActress == actress; }));
}
Loading