Skip to content

Commit

Permalink
add music module (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal authored Aug 12, 2023
1 parent 2b5e86f commit 94db8ba
Show file tree
Hide file tree
Showing 8 changed files with 1,413 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ set(FAKER_SOURCES
src/common/mappers/PrecisionMapper.cpp
src/modules/system/System.cpp
src/modules/database/Database.cpp
src/modules/music/Music.cpp
)

set(FAKER_UT_SOURCES
Expand All @@ -62,6 +63,7 @@ set(FAKER_UT_SOURCES
src/common/mappers/PrecisionMapperTest.cpp
src/modules/system/SystemTest.cpp
src/modules/database/DatabaseTest.cpp
src/modules/music/MusicTest.cpp
)

add_library(${LIBRARY_NAME} ${FAKER_SOURCES})
Expand Down
29 changes: 3 additions & 26 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
- [ ] country code
- [x] state
- [x] city
- [ ] county
- [x] zip code
- [x] street
- [x] street address
Expand Down Expand Up @@ -138,38 +137,16 @@

### 🎶 Music:

- [ ] genre
- [ ] songName
- [ ] artistName
- [x] genre
- [x] songName
- [x] artist

### 🎥 Movie:

- [ ] genre
- [ ] title
- [ ] director

### 🚗 Vehicle:

- [ ] bicycle
- [ ] color
- [ ] fuel
- [ ] manufacturer
- [ ] model
- [ ] type
- [ ] vehicle
- [ ] vin
- [ ] vrm

### ✈ Airline:

- [ ] aircraftType
- [ ] airline
- [ ] airplane
- [ ] airport
- [ ] flightNumber
- [ ] recordLocator
- [ ] seat

### Database:

- [x] collation
Expand Down
43 changes: 43 additions & 0 deletions include/faker-cxx/Music.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include <string>

namespace faker
{
class Music
{
public:
/**
* @brief Returns a random artist.
*
* @returns Artist.
*
* @code
* Music::artist() // "Nirvana"
* @endcode
*/
static std::string artist();

/**
* @brief Returns a random music genre.
*
* @returns Music genre.
*
* @code
* Music::genre() // "Rock"
* @endcode
*/
static std::string genre();

/**
* @brief Returns a random song name.
*
* @returns Song name.
*
* @code
* Music::songName() // "Light My Fire"
* @endcode
*/
static std::string songName();
};
}
24 changes: 24 additions & 0 deletions src/modules/music/Music.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "faker-cxx/Music.h"

#include "data/Artists.h"
#include "data/Genres.h"
#include "data/SongNames.h"
#include "faker-cxx/Helper.h"

namespace faker
{
std::string Music::artist()
{
return Helper::arrayElement<std::string>(artists);
}

std::string Music::genre()
{
return Helper::arrayElement<std::string>(genres);
}

std::string Music::songName()
{
return Helper::arrayElement<std::string>(songNames);
}
}
42 changes: 42 additions & 0 deletions src/modules/music/MusicTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "faker-cxx/Music.h"

#include <algorithm>

#include "gtest/gtest.h"

#include "data/Artists.h"
#include "data/Genres.h"
#include "data/SongNames.h"

using namespace ::testing;
using namespace faker;

class MusicTest : public Test
{
public:
};

TEST_F(MusicTest, shouldGenerateArtist)
{
const auto generatedArtist = Music::artist();

ASSERT_TRUE(std::any_of(artists.begin(), artists.end(),
[generatedArtist](const std::string& artist) { return generatedArtist == artist; }));
}

TEST_F(MusicTest, shouldGenerateGenre)
{
const auto generatedGenre = Music::genre();

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

TEST_F(MusicTest, shouldGenerateSongName)
{
const auto generatedSongName = Music::songName();

ASSERT_TRUE(std::any_of(songNames.begin(), songNames.end(),
[generatedSongName](const std::string& songName)
{ return generatedSongName == songName; }));
}
Loading

0 comments on commit 94db8ba

Please sign in to comment.