feladat5 v1 done
This commit is contained in:
parent
d5974bb824
commit
a5b58c2d8a
3 changed files with 144 additions and 10 deletions
|
|
@ -189,14 +189,20 @@ namespace UnitTest1
|
|||
CMyString preps[]{
|
||||
CMyString(),
|
||||
CMyString("testtesttest"),
|
||||
CMyString("testtesttest"),
|
||||
CMyString("test"),
|
||||
};
|
||||
CMyString strs[]{
|
||||
CMyString("test"),
|
||||
CMyString("test"),
|
||||
CMyString("testtesttesttest"),
|
||||
CMyString("testtesttesttest"),
|
||||
};
|
||||
int expected[][2] = {
|
||||
{ 4, 10 },
|
||||
{ 4, 13 },
|
||||
{ 16, 34 },
|
||||
{ 16, 34 },
|
||||
};
|
||||
int testcount = sizeof(expected) / (sizeof(int) * 2);
|
||||
for (size_t i = 0; i < testcount; i++)
|
||||
|
|
@ -365,9 +371,9 @@ namespace UnitTest1
|
|||
1,
|
||||
};
|
||||
char* text[] = {
|
||||
'\0',
|
||||
'\0',
|
||||
'\0',
|
||||
"",
|
||||
NULL,
|
||||
NULL,
|
||||
"test",
|
||||
"tes",
|
||||
"aaaaaaaaa",
|
||||
|
|
@ -398,7 +404,130 @@ namespace UnitTest1
|
|||
}
|
||||
}
|
||||
TEST_METHOD(ShrinkToFitTests) {
|
||||
CMyString str[]{
|
||||
CMyString("test"),
|
||||
CMyString("test"),
|
||||
CMyString(),
|
||||
};
|
||||
int eraseargs[][2] = {
|
||||
{ 0, 0 },
|
||||
{ 0, 4 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
int res[][2] = {
|
||||
{ 4, 5 },
|
||||
{ 0, 1 },
|
||||
{ 0, 1 },
|
||||
};
|
||||
int testcount = sizeof(res) / sizeof(int) / 2;
|
||||
for (size_t i = 0; i < testcount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
str[i].erase(eraseargs[i][0], eraseargs[i][1]);
|
||||
str[i].shrink_to_fit();
|
||||
Assert::AreEqual(res[i][0], (int)str[i].size());
|
||||
Assert::AreEqual(res[i][1], (int)str[i].capacity());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Assert::IsTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_METHOD(ReverseTests) {
|
||||
CMyString str[]{
|
||||
CMyString(),
|
||||
CMyString("bal"),
|
||||
CMyString("test"),
|
||||
CMyString("disestablishmentarianism"),
|
||||
};
|
||||
char* text[] = {
|
||||
"",
|
||||
"lab",
|
||||
"tset",
|
||||
"msinairatnemhsilbatsesid"
|
||||
};
|
||||
int testcount = sizeof(text) / sizeof(char*);
|
||||
for (size_t i = 0; i < testcount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
str[i].reverse();
|
||||
Assert::AreEqual(text[i], str[i].c_str());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Assert::IsTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_METHOD(AppendTests) {
|
||||
CMyString str[]{
|
||||
CMyString(),
|
||||
CMyString(),
|
||||
CMyString("test"),
|
||||
CMyString("test"),
|
||||
CMyString("test"),
|
||||
CMyString("test"),
|
||||
CMyString("test"),
|
||||
};
|
||||
const char* text[] = {
|
||||
"",
|
||||
nullptr,
|
||||
str[2].c_str(),
|
||||
"test",
|
||||
"test",
|
||||
"test",
|
||||
"test",
|
||||
};
|
||||
size_t extraargs[][2] = {
|
||||
{ 0, ~0 },
|
||||
{ 0, ~0 },
|
||||
{ 0, ~0 },
|
||||
{ 0, ~0 },
|
||||
{ 4, ~0 },
|
||||
{ 0, 5 },
|
||||
{ 2, 3 },
|
||||
};
|
||||
int sizes[][2] = {
|
||||
{ 0, 1 },
|
||||
{ 0, 1 },
|
||||
{ 4, 5 },
|
||||
{ 8, 16 },
|
||||
{ 4, 5 },
|
||||
{ 4, 5 },
|
||||
{ 4, 5 },
|
||||
};
|
||||
const char* expected[] = {
|
||||
"",
|
||||
"",
|
||||
"test",
|
||||
"testtest",
|
||||
CMyStringException::ErrOutOfRange,
|
||||
CMyStringException::ErrOutOfRange,
|
||||
CMyStringException::ErrOutOfRange,
|
||||
};
|
||||
int testcount = sizeof(text) / sizeof(char*);
|
||||
for (size_t i = 0; i < testcount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
str[i].append(text[i], extraargs[i][0], extraargs[i][1]);
|
||||
Assert::AreEqual(expected[i], str[i].c_str());
|
||||
Assert::AreEqual(sizes[i][0], (int)str[i].size());
|
||||
Assert::AreEqual(sizes[i][1], (int)str[i].capacity());
|
||||
}
|
||||
catch (const CMyStringException& e)
|
||||
{
|
||||
Assert::AreEqual(expected[i], e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Assert::IsTrue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue