v3
This commit is contained in:
parent
41988f0df6
commit
a1dbab091d
11 changed files with 30 additions and 44 deletions
|
|
@ -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.
BIN
feladat4/feladat4/IFPQYY_feladat4V3.zip
Normal file
BIN
feladat4/feladat4/IFPQYY_feladat4V3.zip
Normal file
Binary file not shown.
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,13 +72,13 @@ 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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
//Tóth Dániel Mátyás | IFPQYY | V1
|
||||
#include "feladat4.h"
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
//Tóth Dániel Mátyás | IFPQYY | V1
|
||||
#pragma once
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue