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 "pch.h"
|
||||||
#include "CppUnitTest.h"
|
#include "CppUnitTest.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -97,6 +97,7 @@ namespace UnitTest1
|
||||||
{ 1972, 1, 1 },
|
{ 1972, 1, 1 },
|
||||||
{ 1970, 1, 2 },
|
{ 1970, 1, 2 },
|
||||||
{ 1970, 1, 1 },
|
{ 1970, 1, 1 },
|
||||||
|
{ 1970, 1, 1 },
|
||||||
};
|
};
|
||||||
int dates2[][3] = { //expected
|
int dates2[][3] = { //expected
|
||||||
{ 1970, 1, 2 },
|
{ 1970, 1, 2 },
|
||||||
|
|
@ -107,6 +108,7 @@ namespace UnitTest1
|
||||||
{ 1972, 12, 31 },
|
{ 1972, 12, 31 },
|
||||||
{ 1970, 1, 1 },
|
{ 1970, 1, 1 },
|
||||||
{ 1970, 1, 1 },
|
{ 1970, 1, 1 },
|
||||||
|
{ 1970, 1, 1 },
|
||||||
};
|
};
|
||||||
int counts[] = {
|
int counts[] = {
|
||||||
1,
|
1,
|
||||||
|
|
@ -116,7 +118,8 @@ namespace UnitTest1
|
||||||
365,
|
365,
|
||||||
365,
|
365,
|
||||||
-1, //technically allowed
|
-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;
|
int testcount = sizeof(dates1) / 12;
|
||||||
for (size_t i = 0; i < testcount; i++)
|
for (size_t i = 0; i < testcount; i++)
|
||||||
|
|
@ -132,7 +135,7 @@ namespace UnitTest1
|
||||||
}
|
}
|
||||||
catch (const CMyDateException& e)
|
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 (...) {
|
catch (...) {
|
||||||
Assert::IsTrue(false);
|
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 "pch.h"
|
||||||
#include "CppUnitTest.h"
|
#include "CppUnitTest.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -97,6 +97,7 @@ namespace UnitTest1
|
||||||
{ 1972, 1, 1 },
|
{ 1972, 1, 1 },
|
||||||
{ 1970, 1, 2 },
|
{ 1970, 1, 2 },
|
||||||
{ 1970, 1, 1 },
|
{ 1970, 1, 1 },
|
||||||
|
{ 1970, 1, 1 },
|
||||||
};
|
};
|
||||||
int dates2[][3] = { //expected
|
int dates2[][3] = { //expected
|
||||||
{ 1970, 1, 2 },
|
{ 1970, 1, 2 },
|
||||||
|
|
@ -107,6 +108,7 @@ namespace UnitTest1
|
||||||
{ 1972, 12, 31 },
|
{ 1972, 12, 31 },
|
||||||
{ 1970, 1, 1 },
|
{ 1970, 1, 1 },
|
||||||
{ 1970, 1, 1 },
|
{ 1970, 1, 1 },
|
||||||
|
{ 1970, 1, 1 },
|
||||||
};
|
};
|
||||||
int counts[] = {
|
int counts[] = {
|
||||||
1,
|
1,
|
||||||
|
|
@ -116,7 +118,8 @@ namespace UnitTest1
|
||||||
365,
|
365,
|
||||||
365,
|
365,
|
||||||
-1, //technically allowed
|
-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;
|
int testcount = sizeof(dates1) / 12;
|
||||||
for (size_t i = 0; i < testcount; i++)
|
for (size_t i = 0; i < testcount; i++)
|
||||||
|
|
@ -132,7 +135,7 @@ namespace UnitTest1
|
||||||
}
|
}
|
||||||
catch (const CMyDateException& e)
|
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 (...) {
|
catch (...) {
|
||||||
Assert::IsTrue(false);
|
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 <iostream>
|
||||||
#include "cmydateexception.h"
|
#include "cmydateexception.h"
|
||||||
#include "cmydate.h"
|
#include "cmydate.h"
|
||||||
|
|
@ -35,7 +35,9 @@ CMyDate::CMyDate() {
|
||||||
m_iDay = 1;
|
m_iDay = 1;
|
||||||
}
|
}
|
||||||
CMyDate::CMyDate(int year, int month, int day) {
|
CMyDate::CMyDate(int year, int month, int day) {
|
||||||
IsValid(year, month, day);
|
IsValidYear(year);
|
||||||
|
IsValidMonth(month);
|
||||||
|
IsValidDay(year, month, day);
|
||||||
m_iYear = year;
|
m_iYear = year;
|
||||||
m_iMonth = month;
|
m_iMonth = month;
|
||||||
m_iDay = day;
|
m_iDay = day;
|
||||||
|
|
@ -70,12 +72,12 @@ void CMyDate::AddDays(int days) {
|
||||||
int timestamp = DateToTimeStamp(GetYear(), GetMonth(), GetDay());
|
int timestamp = DateToTimeStamp(GetYear(), GetMonth(), GetDay());
|
||||||
int y = 0, m = 0, d = 0;
|
int y = 0, m = 0, d = 0;
|
||||||
TimeStampToDate(timestamp + days, &y, &m, &d);
|
TimeStampToDate(timestamp + days, &y, &m, &d);
|
||||||
if (IsValid(y, m, d))
|
IsValidYear(y);
|
||||||
{
|
IsValidMonth(m);
|
||||||
m_iYear = y;
|
IsValidDay(y, m, d);
|
||||||
m_iMonth = m;
|
m_iYear = y;
|
||||||
m_iDay = d;
|
m_iMonth = m;
|
||||||
}
|
m_iDay = d;
|
||||||
}
|
}
|
||||||
void CMyDate::SubDays(int days) {
|
void CMyDate::SubDays(int days) {
|
||||||
AddDays(days * (-1));
|
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
|
#pragma once
|
||||||
class CMyDate {
|
class CMyDate {
|
||||||
public:
|
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"
|
#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)
|
CMyDateException::CMyDateException(const char* s)
|
||||||
{
|
{
|
||||||
msg = new char[256];
|
msg = std::string(s);
|
||||||
CopyStr(msg, s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CMyDateException::what() const {
|
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
|
#pragma once
|
||||||
|
#include <string>
|
||||||
class CMyDateException {
|
class CMyDateException {
|
||||||
public:
|
public:
|
||||||
CMyDateException(const char* s);
|
CMyDateException(const char* s);
|
||||||
|
|
@ -11,5 +12,5 @@ public:
|
||||||
static constexpr const char* ErrMinYear = "Hiba: ev kisebb, mint 1970!";
|
static constexpr const char* ErrMinYear = "Hiba: ev kisebb, mint 1970!";
|
||||||
static constexpr const char* ErrUnexpected = "Varatlan hiba";
|
static constexpr const char* ErrUnexpected = "Varatlan hiba";
|
||||||
private:
|
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 <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "cmydateexception.h"
|
#include "cmydateexception.h"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue