Skip to content

Commit

Permalink
fix book release year tests (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal committed Jan 23, 2024
1 parent 4fd32d8 commit 7f96d60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
18 changes: 9 additions & 9 deletions src/modules/book/Book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

#include "../../common/FormatHelper.h"
#include "data/Authors.h"
#include "data/BookFormat.h"
#include "data/Genres.h"
#include "data/Publishers.h"
#include "data/Series.h"
#include "data/Titles.h"
#include "data/Translators.h"
#include "data/Series.h"
#include "data/BookFormat.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/String.h"
#include "faker-cxx/Date.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/Number.h"
#include "faker-cxx/String.h"

namespace faker
{
Expand Down Expand Up @@ -43,26 +43,26 @@ std::string Book::isbn()

int Book::releaseYear()
{
return std::stoi(Date::pastDate(100).substr(0, 4));
return Number::integer(1940, 2024);
}

std::string Book::translator()
{
return Helper::arrayElement<std::string>(translators);
return Helper::arrayElement<std::string>(translators);
}

std::string Book::format()
{
return Helper::arrayElement<std::string>(bookFormats);
return Helper::arrayElement<std::string>(bookFormats);
}

int Book::page()
{
return Number::integer(50, 999);
return Number::integer(50, 999);
}

std::string Book::series()
{
return Helper::arrayElement<std::string>(bookSeries);
return Helper::arrayElement<std::string>(bookSeries);
}
}
22 changes: 12 additions & 10 deletions src/modules/book/BookTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

#include "../../common/StringHelper.h"
#include "data/Authors.h"
#include "data/BookFormat.h"
#include "data/Genres.h"
#include "data/Publishers.h"
#include "data/Series.h"
#include "data/Titles.h"
#include "data/Translators.h"
#include "data/Series.h"
#include "data/BookFormat.h"

using namespace ::testing;
using namespace faker;
Expand Down Expand Up @@ -64,9 +64,11 @@ TEST_F(BookTest, shouldGenerateIsbn)
ASSERT_EQ(isbnNumbersGroups[4].size(), 1);
}

TEST_F(BookTest, shouldGenerateReleaseYear) {
int releaseYear = Book::releaseYear();
ASSERT_TRUE((releaseYear >= 1924) && (releaseYear <= 2024));
TEST_F(BookTest, shouldGenerateReleaseYear)
{
const auto releaseYear = Book::releaseYear();

ASSERT_TRUE((releaseYear >= 1940) && (releaseYear <= 2024));
}

TEST_F(BookTest, shouldGenerateTranslator)
Expand All @@ -80,9 +82,9 @@ TEST_F(BookTest, shouldGenerateTranslator)
TEST_F(BookTest, shouldGenerateFormat)
{
const auto bookFormat = Book::format();
ASSERT_TRUE(std::ranges::any_of(bookFormats, [bookFormat](const std::string& format)
{ return format == bookFormat; }));

ASSERT_TRUE(
std::ranges::any_of(bookFormats, [bookFormat](const std::string& format) { return format == bookFormat; }));
}

TEST_F(BookTest, shouldGeneratePage)
Expand All @@ -96,6 +98,6 @@ TEST_F(BookTest, shouldGenerateSeries)
{
const auto randomSeries = Book::series();

ASSERT_TRUE(std::ranges::any_of(bookSeries, [randomSeries](const std::string& series)
{ return series == randomSeries; }));
ASSERT_TRUE(
std::ranges::any_of(bookSeries, [randomSeries](const std::string& series) { return series == randomSeries; }));
}

0 comments on commit 7f96d60

Please sign in to comment.