-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf08a18
commit cc04052
Showing
10 changed files
with
694 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace faker | ||
{ | ||
class Book | ||
{ | ||
public: | ||
/** | ||
* @brief Returns a random book title. | ||
* | ||
* @returns Book title. | ||
* | ||
* @code | ||
* Book::title() // "Romeo and Juliet" | ||
* @endcode | ||
*/ | ||
static std::string title(); | ||
|
||
/** | ||
* @brief Returns a random book genre. | ||
* | ||
* @returns Book genre. | ||
* | ||
* @code | ||
* Book::genre() // "Fantasy" | ||
* @endcode | ||
*/ | ||
static std::string genre(); | ||
|
||
/** | ||
* @brief Returns a random book author. | ||
* | ||
* @returns Book author. | ||
* | ||
* @code | ||
* Book::author() // "Shakespeare, William" | ||
* @endcode | ||
*/ | ||
static std::string author(); | ||
|
||
/** | ||
* @brief Returns a random book publisher. | ||
* | ||
* @returns Book publisher. | ||
* | ||
* @code | ||
* Book::publisher() // "Addison-Wesley" | ||
* @endcode | ||
*/ | ||
static std::string publisher(); | ||
|
||
/** | ||
* @brief Returns a random book ISBN. | ||
* | ||
* @returns Book ISBN. | ||
* | ||
* @code | ||
* Book::isbn() // "978-83-01-00000-1" | ||
* @endcode | ||
*/ | ||
static std::string isbn(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "Book.h" | ||
|
||
#include "data/book/Authors.h" | ||
#include "data/book/Genres.h" | ||
#include "data/book/Publishers.h" | ||
#include "data/book/Titles.h" | ||
#include "Helper.h" | ||
#include "String.h" | ||
|
||
namespace faker | ||
{ | ||
std::string Book::title() | ||
{ | ||
return Helper::arrayElement<std::string>(titles); | ||
} | ||
|
||
std::string Book::genre() | ||
{ | ||
return Helper::arrayElement<std::string>(genres); | ||
} | ||
|
||
std::string Book::author() | ||
{ | ||
return Helper::arrayElement<std::string>(authors); | ||
} | ||
|
||
std::string Book::publisher() | ||
{ | ||
return Helper::arrayElement<std::string>(publishers); | ||
} | ||
|
||
std::string Book::isbn() | ||
{ | ||
return std::format("{}-{}-{}-{}-{}", String::numeric(3, false), String::numeric(2), String::numeric(2), | ||
String::numeric(5), String::numeric(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "Book.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#include "data/book/Authors.h" | ||
#include "data/book/Genres.h" | ||
#include "data/book/Publishers.h" | ||
#include "data/book/Titles.h" | ||
#include "StringHelper.h" | ||
|
||
using namespace ::testing; | ||
using namespace faker; | ||
|
||
class BookTest : public Test | ||
{ | ||
public: | ||
}; | ||
|
||
TEST_F(BookTest, shouldGenerateTitle) | ||
{ | ||
const auto bookTitle = Book::title(); | ||
|
||
ASSERT_TRUE(std::any_of(titles.begin(), titles.end(), | ||
[bookTitle](const std::string& title) { return title == bookTitle; })); | ||
} | ||
|
||
TEST_F(BookTest, shouldGenerateGenre) | ||
{ | ||
const auto bookGenre = Book::genre(); | ||
|
||
ASSERT_TRUE(std::any_of(genres.begin(), genres.end(), | ||
[bookGenre](const std::string& genre) { return genre == bookGenre; })); | ||
} | ||
|
||
TEST_F(BookTest, shouldGenerateAuthor) | ||
{ | ||
const auto bookAuthor = Book::author(); | ||
|
||
ASSERT_TRUE(std::any_of(authors.begin(), authors.end(), | ||
[bookAuthor](const std::string& author) { return author == bookAuthor; })); | ||
} | ||
|
||
TEST_F(BookTest, shouldGeneratePublisher) | ||
{ | ||
const auto bookPublisher = Book::publisher(); | ||
|
||
ASSERT_TRUE(std::any_of(publishers.begin(), publishers.end(), | ||
[bookPublisher](const std::string& publisher) { return publisher == bookPublisher; })); | ||
} | ||
|
||
TEST_F(BookTest, shouldGenerateIsbn) | ||
{ | ||
const auto bookIsbn = Book::isbn(); | ||
|
||
const auto isbnNumbersGroups = StringHelper::split(bookIsbn, "-"); | ||
|
||
ASSERT_EQ(bookIsbn.size(), 17); | ||
ASSERT_EQ(isbnNumbersGroups[0].size(), 3); | ||
ASSERT_EQ(isbnNumbersGroups[1].size(), 2); | ||
ASSERT_EQ(isbnNumbersGroups[2].size(), 2); | ||
ASSERT_EQ(isbnNumbersGroups[3].size(), 5); | ||
ASSERT_EQ(isbnNumbersGroups[4].size(), 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace faker | ||
{ | ||
const std::vector<std::string> authors = {"Shakespeare, William", | ||
"Smollett, T. (Tobias)", | ||
"Dumas, Alexandre", | ||
"Montgomery, L. M. (Lucy Maud)", | ||
"Melville, Herman", | ||
"Alcott, Louisa May", | ||
"Eliot, George", | ||
"Forster, E. M. (Edward Morgan)", | ||
"Austen, Jane", | ||
"Merrill, Frank T.", | ||
"Dickens, Charles", | ||
"Gaskell, Elizabeth Cleghorn", | ||
"Von Arnim, Elizabeth", | ||
"Brock, C. E. (Charles Edmund)", | ||
"Fielding, Henry", | ||
"Wagner, Richard", | ||
"Twain, Mark", | ||
"Doyle, Arthur Conan", | ||
"Dostoyevsky, Fyodor", | ||
"Packard, Vance", | ||
"Adams, Clifford R. (Clifford Rose)", | ||
"Wilde, Oscar", | ||
"Garnett, Constance", | ||
"Carroll, Lewis", | ||
"Nietzsche, Friedrich Wilhelm", | ||
"Tolstoy, Leo", | ||
"Stevenson, Robert Louis", | ||
"Wells, H. G. (Herbert George)", | ||
"Shelley, Mary Wollstonecraft", | ||
"Howard, Robert E. (Robert Ervin)", | ||
"Baum, L. Frank (Lyman Frank)", | ||
"Chesterton, G. K. (Gilbert Keith)", | ||
"Homer", | ||
"Plato", | ||
"Rizal, José", | ||
"Christie, Agatha", | ||
"Joyce, James", | ||
"Jowett, Benjamin", | ||
"Poe, Edgar Allan", | ||
"Verne, Jules", | ||
"Thoreau, Henry David", | ||
"Kafka, Franz", | ||
"Stoker, Bram", | ||
"Kipling, Rudyard", | ||
"Doré, Gustave", | ||
"Widger, David", | ||
"Fitzgerald, F. Scott (Francis Scott)", | ||
"Russell, Bertrand", | ||
"Swift, Jonathan", | ||
"Dante Alighieri", | ||
"Wyllie, David", | ||
"Hugo, Victor", | ||
"Lang, Andrew", | ||
"Maude, Aylmer", | ||
"Burton, Richard Francis, Sir", | ||
"Maude, Louise", | ||
"Hawthorne, Nathaniel", | ||
"Conrad, Joseph", | ||
"London, Jack", | ||
"Goethe, Johann Wolfgang von", | ||
"James, Henry", | ||
"Scott, Walter", | ||
"Chekhov, Anton Pavlovich", | ||
"Pope, Alexander", | ||
"Ibsen, Henrik", | ||
"Cervantes Saavedra, Miguel de", | ||
"Balzac, Honoré de", | ||
"Grimm, Jacob", | ||
"Grimm, Wilhelm", | ||
"Lovecraft, H. P. (Howard Phillips)", | ||
"Burroughs, Edgar Rice", | ||
"Shaw, Bernard", | ||
"Gilman, Charlotte Perkins", | ||
"Wodehouse, P. G. (Pelham Grenville)", | ||
"Hotten, John Camden", | ||
"Morley, Henry", | ||
"Machiavelli, Niccolò", | ||
"Derbyshire, Charles E.", | ||
"Barrie, J. M. (James Matthew)", | ||
"Brontë, Charlotte", | ||
"Defoe, Daniel", | ||
"Ward, Grady", | ||
"Levy, Oscar", | ||
"Burnett, Frances Hodgson", | ||
"Schopenhauer, Arthur", | ||
"Buckley, Theodore Alois", | ||
"Milne, A. A. (Alan Alexander)", | ||
"Marriott, W. K. (William Kenaz)", | ||
"Vatsyayana", | ||
"Potter, Beatrix", | ||
"Ormsby, John", | ||
"Bhide, Shivaram Parashuram", | ||
"Butler, Samuel", | ||
"Indrajit, Bhagavanlal", | ||
"Maupassant, Guy de", | ||
"Hapgood, Isabel Florence", | ||
"Chambers, Robert W. (Robert William)", | ||
"Marx, Karl", | ||
"Eliot, T. S. (Thomas Stearns)", | ||
"Hardy, Thomas"}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace faker | ||
{ | ||
const std::vector<std::string> genres = {"Adventure stories", | ||
"Classics", | ||
"Crime", | ||
"Fairy tales, fables, and folk tales", | ||
"Fantasy", | ||
"Historical fiction", | ||
"Horror", | ||
"Humour and satire", | ||
"Literary fiction", | ||
"Mystery", | ||
"Poetry", | ||
"Plays", | ||
"Romance", | ||
"Science fiction", | ||
"Short stories", | ||
"Thrillers", | ||
"War", | ||
"Women’s fiction", | ||
"Young adult", | ||
"Non-fiction", | ||
"Autobiography and memoir", | ||
"Biography", | ||
"Essays", | ||
"Non-fiction novel", | ||
"Self-help"}; | ||
} |
Oops, something went wrong.