feladat5 v2 done

This commit is contained in:
Damimani 2026-11-08 16:38:49 +01:00
parent a5b58c2d8a
commit 459e111f2f
6 changed files with 92 additions and 41 deletions

View file

@ -1,4 +1,4 @@
// Tóth Dániel Mátyás | IFPQYY | v1
// Tóth Dániel Mátyás | IFPQYY | v2
#include "pch.h"
#include "CppUnitTest.h"
#include <CMyString.h>
@ -107,6 +107,9 @@ namespace UnitTest1
Assert::AreEqual(repeattextres[i], repeatctor.c_str());
}
}
catch (const CMyStringException& e) {
Assert::AreEqual(CMyStringException::ErrInvalidChar, e.what());
}
catch (...)
{
Assert::IsTrue(false);
@ -191,18 +194,21 @@ namespace UnitTest1
CMyString("testtesttest"),
CMyString("testtesttest"),
CMyString("test"),
CMyString("dio"),
};
CMyString strs[]{
CMyString("test"),
CMyString("test"),
CMyString("testtesttesttest"),
CMyString("testtesttesttest"),
CMyString("narancs"),
};
int expected[][2] = {
{ 4, 10 },
{ 4, 5 },
{ 4, 13 },
{ 16, 34 },
{ 16, 34 },
{ 16, 17 },
{ 16, 17 },
{ 7, 8 },
};
int testcount = sizeof(expected) / (sizeof(int) * 2);
for (size_t i = 0; i < testcount; i++)
@ -322,25 +328,36 @@ namespace UnitTest1
}
TEST_METHOD(ReserveTests) {
CMyString str = CMyString("test");
int allocs[] = {
1,
5,
10,
33,
};
int expected[] = {
5,
5,
10,
33,
};
int testcount = sizeof(allocs) / sizeof(int);
for (size_t i = 0; i < testcount; i++)
{
try
{
CMyString str = CMyString("test");
const char* ptr = str.c_str();
str.reserve(allocs[i]);
Assert::AreEqual(allocs[i], (int)str.capacity());
Assert::AreEqual(expected[i], (int)str.capacity());
if (i < 2)
{
Assert::AreEqual(ptr, str.c_str());
}
}
catch (const CMyStringException& e)
catch (...)
{
Assert::AreEqual(CMyStringException::ErrOutOfRange, e.what());
Assert::IsTrue(false);
}
}
}
@ -353,6 +370,8 @@ namespace UnitTest1
CMyString("test"),
CMyString("test"),
CMyString('a', 10),
CMyString("alma"),
CMyString("test"),
};
int pos[] = {
0,
@ -361,6 +380,8 @@ namespace UnitTest1
3,
3,
3,
4,
0,
};
int cnt[] = {
1,
@ -369,14 +390,18 @@ namespace UnitTest1
0,
1,
1,
100,
0,
};
char* text[] = {
"",
NULL,
"test",
NULL,
"test",
"tes",
"aaaaaaaaa",
"alma",
"test",
};
int testcount = sizeof(pos) / sizeof(int);
for (size_t i = 0; i < testcount; i++)
@ -388,14 +413,7 @@ namespace UnitTest1
}
catch (const CMyStringException& e)
{
if (i < 3)
{
Assert::AreEqual(CMyStringException::ErrOutOfRange, e.what());
}
else
{
Assert::IsTrue(false);
}
Assert::AreEqual(CMyStringException::ErrOutOfRange, e.what());
}
catch (...)
{
@ -472,6 +490,11 @@ namespace UnitTest1
CMyString("test"),
CMyString("test"),
CMyString("test"),
CMyString("test"),
CMyString("test"),
CMyString("test"),
CMyString("banan"),
CMyString("banan"),
};
const char* text[] = {
"",
@ -481,24 +504,39 @@ namespace UnitTest1
"test",
"test",
"test",
"",
"test",
"a",
"narancs",
"narancs",
};
size_t extraargs[][2] = {
{ 0, ~0 },
{ 0, ~0 },
{ 0, ~0 },
{ 0, ~0 },
{ 4, ~0 },
{ 5, ~0 },
{ 0, 5 },
{ 2, 3 },
{ 1, 0 },
{ 4, ~0 },
{ 0, ~0 },
{ 0, ~0 },
{ 2, 2 },
};
int sizes[][2] = {
{ 0, 1 },
{ 0, 1 },
{ 4, 5 },
{ 8, 16 },
{ 8, 18 },
{ 4, 5 },
{ 4, 5 },
{ 4, 5 },
{ 4, 5 },
{ 4, 5 },
{ 5, 12 },
{ 12, 26 },
{ 7, 16 },
};
const char* expected[] = {
"",
@ -508,6 +546,11 @@ namespace UnitTest1
CMyStringException::ErrOutOfRange,
CMyStringException::ErrOutOfRange,
CMyStringException::ErrOutOfRange,
CMyStringException::ErrCount,
"test",
"testa",
"banannarancs",
"bananra",
};
int testcount = sizeof(text) / sizeof(char*);
for (size_t i = 0; i < testcount; i++)