Added more Age-class tests

This commit is contained in:
Michael Mandl 2018-11-25 14:30:45 +01:00
parent 09f8fa4faf
commit 220f92453d
2 changed files with 17 additions and 6 deletions

View file

@ -4,8 +4,8 @@
#include <sstream> #include <sstream>
Age::Age(unsigned int years, unsigned int months) Age::Age(unsigned int years, unsigned int months)
: m_years(years) : m_years(years)
, m_months(months) , m_months(months)
{ {
} }
@ -37,7 +37,7 @@ Age::Age(const QDate &birth, const QDate &reference)
m_years = years; m_years = years;
m_months = months; m_months = months;
} }
bool Age::operator<(const Age &cmp) const bool Age::operator<(const Age &cmp) const
{ {
if (m_years == cmp.m_years) if (m_years == cmp.m_years)
@ -47,7 +47,7 @@ bool Age::operator<(const Age &cmp) const
return m_years < cmp.m_years; return m_years < cmp.m_years;
} }
unsigned int Age::years() const unsigned int Age::years() const
{ {
return m_years; return m_years;
@ -57,7 +57,7 @@ unsigned int Age::months() const
{ {
return m_months; return m_months;
} }
std::string Age::toString() const std::string Age::toString() const
{ {
std::ostringstream result; std::ostringstream result;

View file

@ -18,7 +18,7 @@ TEST_CASE("year/month initialization")
{ {
for (unsigned int year = 0; year <= 100; ++year) for (unsigned int year = 0; year <= 100; ++year)
{ {
for (unsigned int month = 1; month <= 12; ++month) for (unsigned int month = 0; month < 12; ++month)
{ {
Age age(year, month); Age age(year, month);
@ -27,3 +27,14 @@ TEST_CASE("year/month initialization")
} }
} }
} }
TEST_CASE("age by reference")
{
QDate birth(1970, 1, 1);
QDate reference(1980, 1, 1);
Age age(birth, reference);
REQUIRE(age.years() == 10);
REQUIRE(age.months() == 0);
}