diff --git a/source/Age/Age.cpp b/source/Age/Age.cpp index 81415e9..05613a4 100644 --- a/source/Age/Age.cpp +++ b/source/Age/Age.cpp @@ -4,8 +4,8 @@ #include Age::Age(unsigned int years, unsigned int months) - : m_years(years) - , m_months(months) + : m_years(years) + , m_months(months) { } @@ -37,7 +37,7 @@ Age::Age(const QDate &birth, const QDate &reference) m_years = years; m_months = months; } - + bool Age::operator<(const Age &cmp) const { if (m_years == cmp.m_years) @@ -47,7 +47,7 @@ bool Age::operator<(const Age &cmp) const return m_years < cmp.m_years; } - + unsigned int Age::years() const { return m_years; @@ -57,7 +57,7 @@ unsigned int Age::months() const { return m_months; } - + std::string Age::toString() const { std::ostringstream result; diff --git a/test/Age.cpp b/test/Age.cpp index 34b3788..22b0fbb 100644 --- a/test/Age.cpp +++ b/test/Age.cpp @@ -18,7 +18,7 @@ TEST_CASE("year/month initialization") { 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); @@ -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); +}