This commit is contained in:
Damimani 2026-11-01 18:48:06 +01:00
parent 41988f0df6
commit a1dbab091d
11 changed files with 30 additions and 44 deletions

View file

@ -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 <iostream>
@ -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);

Binary file not shown.

View file

@ -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 <iostream>
@ -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);

View file

@ -1,4 +1,4 @@
//Tóth Dániel Mátyás | IFPQYY | V2
//Tóth Dániel Mátyás | IFPQYY | V3
#include <iostream>
#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))
{
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));

View file

@ -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:

View file

@ -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();
}

View file

@ -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 <string>
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;
};

View file

@ -1,2 +0,0 @@
//Tóth Dániel Mátyás | IFPQYY | V1
#include "feladat4.h"

View file

@ -1,2 +0,0 @@
//Tóth Dániel Mátyás | IFPQYY | V1
#pragma once

View file

@ -1,4 +1,4 @@
//Tóth Dániel Mátyás | IFPQYY | V2
//Tóth Dániel Mátyás | IFPQYY | V3
#include <exception>
#include <iostream>
#include "cmydateexception.h"