diff --git a/feladat4/UnitTest1/UnitTest1.cpp b/feladat4/UnitTest1/UnitTest1.cpp index afec52c..1e98f8f 100644 --- a/feladat4/UnitTest1/UnitTest1.cpp +++ b/feladat4/UnitTest1/UnitTest1.cpp @@ -1,4 +1,4 @@ -//Tóth Dániel Mátyás | IFPQYY | V2 +//Tóth Dániel Mátyás | IFPQYY | V3 #include "pch.h" #include "CppUnitTest.h" #include @@ -97,6 +97,7 @@ namespace UnitTest1 { 1972, 1, 1 }, { 1970, 1, 2 }, { 1970, 1, 1 }, + { 1970, 1, 1 }, }; int dates2[][3] = { //expected { 1970, 1, 2 }, @@ -107,6 +108,7 @@ namespace UnitTest1 { 1972, 12, 31 }, { 1970, 1, 1 }, { 1970, 1, 1 }, + { 1970, 1, 1 }, }; int counts[] = { 1, @@ -116,7 +118,8 @@ namespace UnitTest1 365, 365, -1, //technically allowed - - 1 //since SubDays calls AddDays, this counts as its test + - 1, //since SubDays calls AddDays, this counts as its test + -100, }; int testcount = sizeof(dates1) / 12; for (size_t i = 0; i < testcount; i++) @@ -132,7 +135,7 @@ namespace UnitTest1 } catch (const CMyDateException& e) { - Assert::AreEqual(CMyDateException::ErrMinYear, e.what()); //should only happen in the last case + Assert::AreEqual(CMyDateException::ErrMinYear, e.what()); //should only happen in the last two cases } catch (...) { Assert::IsTrue(false); diff --git a/feladat4/feladat4/IFPQYY_feladat4V2.zip b/feladat4/feladat4/IFPQYY_feladat4V2.zip deleted file mode 100644 index 6596df5..0000000 Binary files a/feladat4/feladat4/IFPQYY_feladat4V2.zip and /dev/null differ diff --git a/feladat4/feladat4/IFPQYY_feladat4V3.zip b/feladat4/feladat4/IFPQYY_feladat4V3.zip new file mode 100644 index 0000000..235a7a2 Binary files /dev/null and b/feladat4/feladat4/IFPQYY_feladat4V3.zip differ diff --git a/feladat4/feladat4/UnitTest1.cpp b/feladat4/feladat4/UnitTest1.cpp index afec52c..1e98f8f 100644 --- a/feladat4/feladat4/UnitTest1.cpp +++ b/feladat4/feladat4/UnitTest1.cpp @@ -1,4 +1,4 @@ -//Tóth Dániel Mátyás | IFPQYY | V2 +//Tóth Dániel Mátyás | IFPQYY | V3 #include "pch.h" #include "CppUnitTest.h" #include @@ -97,6 +97,7 @@ namespace UnitTest1 { 1972, 1, 1 }, { 1970, 1, 2 }, { 1970, 1, 1 }, + { 1970, 1, 1 }, }; int dates2[][3] = { //expected { 1970, 1, 2 }, @@ -107,6 +108,7 @@ namespace UnitTest1 { 1972, 12, 31 }, { 1970, 1, 1 }, { 1970, 1, 1 }, + { 1970, 1, 1 }, }; int counts[] = { 1, @@ -116,7 +118,8 @@ namespace UnitTest1 365, 365, -1, //technically allowed - - 1 //since SubDays calls AddDays, this counts as its test + - 1, //since SubDays calls AddDays, this counts as its test + -100, }; int testcount = sizeof(dates1) / 12; for (size_t i = 0; i < testcount; i++) @@ -132,7 +135,7 @@ namespace UnitTest1 } catch (const CMyDateException& e) { - Assert::AreEqual(CMyDateException::ErrMinYear, e.what()); //should only happen in the last case + Assert::AreEqual(CMyDateException::ErrMinYear, e.what()); //should only happen in the last two cases } catch (...) { Assert::IsTrue(false); diff --git a/feladat4/feladat4/cmydate.cpp b/feladat4/feladat4/cmydate.cpp index 11af7b3..478e41a 100644 --- a/feladat4/feladat4/cmydate.cpp +++ b/feladat4/feladat4/cmydate.cpp @@ -1,4 +1,4 @@ -//Tóth Dániel Mátyás | IFPQYY | V2 +//Tóth Dániel Mátyás | IFPQYY | V3 #include #include "cmydateexception.h" #include "cmydate.h" @@ -35,7 +35,9 @@ CMyDate::CMyDate() { m_iDay = 1; } CMyDate::CMyDate(int year, int month, int day) { - IsValid(year, month, day); + IsValidYear(year); + IsValidMonth(month); + IsValidDay(year, month, day); m_iYear = year; m_iMonth = month; m_iDay = day; @@ -70,12 +72,12 @@ void CMyDate::AddDays(int days) { int timestamp = DateToTimeStamp(GetYear(), GetMonth(), GetDay()); int y = 0, m = 0, d = 0; TimeStampToDate(timestamp + days, &y, &m, &d); - if (IsValid(y, m, d)) - { - m_iYear = y; - m_iMonth = m; - m_iDay = d; - } + IsValidYear(y); + IsValidMonth(m); + IsValidDay(y, m, d); + m_iYear = y; + m_iMonth = m; + m_iDay = d; } void CMyDate::SubDays(int days) { AddDays(days * (-1)); diff --git a/feladat4/feladat4/cmydate.h b/feladat4/feladat4/cmydate.h index 5f82d40..e465906 100644 --- a/feladat4/feladat4/cmydate.h +++ b/feladat4/feladat4/cmydate.h @@ -1,4 +1,4 @@ -//Tóth Dániel Mátyás | IFPQYY | V2 +//Tóth Dániel Mátyás | IFPQYY | V3 #pragma once class CMyDate { public: diff --git a/feladat4/feladat4/cmydateexception.cpp b/feladat4/feladat4/cmydateexception.cpp index 1c3e0cd..103ea93 100644 --- a/feladat4/feladat4/cmydateexception.cpp +++ b/feladat4/feladat4/cmydateexception.cpp @@ -1,31 +1,12 @@ -//Tóth Dániel Mátyás | IFPQYY | V2 +//Tóth Dániel Mátyás | IFPQYY | V3 #include "cmydateexception.h" -static int CopyStr(char* dest, const char* src, const char* concat = "\0") { - if (dest == nullptr || src == nullptr) { - return -1; - } - int i = 0; - while (src[i] != '\0') - { - dest[i++] = src[i]; - } - int j = 0; - while (concat[j] != '\0') - { - dest[i++] = concat[j++]; - } - dest[i] = '\0'; - return -1; -} - CMyDateException::CMyDateException(const char* s) { - msg = new char[256]; - CopyStr(msg, s); + msg = std::string(s); } const char* CMyDateException::what() const { - return msg; + return msg.c_str(); } diff --git a/feladat4/feladat4/cmydateexception.h b/feladat4/feladat4/cmydateexception.h index 728d3e4..7214b5b 100644 --- a/feladat4/feladat4/cmydateexception.h +++ b/feladat4/feladat4/cmydateexception.h @@ -1,5 +1,6 @@ -//Tóth Dániel Mátyás | IFPQYY | V2 +//Tóth Dániel Mátyás | IFPQYY | V3 #pragma once +#include class CMyDateException { public: CMyDateException(const char* s); @@ -11,5 +12,5 @@ public: static constexpr const char* ErrMinYear = "Hiba: ev kisebb, mint 1970!"; static constexpr const char* ErrUnexpected = "Varatlan hiba"; private: - char* msg; + std::string msg; }; \ No newline at end of file diff --git a/feladat4/feladat4/feladat4.cpp b/feladat4/feladat4/feladat4.cpp deleted file mode 100644 index e159638..0000000 --- a/feladat4/feladat4/feladat4.cpp +++ /dev/null @@ -1,2 +0,0 @@ -//Tóth Dániel Mátyás | IFPQYY | V1 -#include "feladat4.h" \ No newline at end of file diff --git a/feladat4/feladat4/feladat4.h b/feladat4/feladat4/feladat4.h deleted file mode 100644 index 0b3d20a..0000000 --- a/feladat4/feladat4/feladat4.h +++ /dev/null @@ -1,2 +0,0 @@ -//Tóth Dániel Mátyás | IFPQYY | V1 -#pragma once diff --git a/feladat4/feladat4/main.cpp b/feladat4/feladat4/main.cpp index efd24c0..d0b21c2 100644 --- a/feladat4/feladat4/main.cpp +++ b/feladat4/feladat4/main.cpp @@ -1,4 +1,4 @@ -//Tóth Dániel Mátyás | IFPQYY | V2 +//Tóth Dániel Mátyás | IFPQYY | V3 #include #include #include "cmydateexception.h"