Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Prog2
/
szorgalmi_feladatok
/
stringpool
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
1be7ba0c
authored
Nov 29, 2022
by
Zoltan Karsa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tesztek: RString, StringPool kezdeti
parent
83104441
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
4 deletions
+109
-4
pool.h
+11
-2
rstring.h
+4
-0
test.cpp
+94
-2
No files found.
pool.h
View file @
1be7ba0c
...
...
@@ -18,9 +18,11 @@ class StringPool {
// Visszadja, hogy az str objektum szabad, azaz
// kiosztható/megszerezhető-e
bool
acquireable
(
RString
&
str
)
bool
acquireable
(
RString
&
str
)
;
// Ezután a visszaadott str objektum újra kiosztható másnak
// A függvény "reseteli" a stringet is: a karaktertömb első
// helyére '\0'-t rak.
void
release
(
RString
&
str
);
// Hozzáfűzi str1 végére str2-t.
...
...
@@ -33,7 +35,13 @@ class StringPool {
// érték is szintén kiosztott.
// Ha a paraméterek nem lefoglalt erőforrások,
// akkor eldobja a neptun kódodat!
Rstring
&
append
(
RString
&
str1
,
const
RString
&
str2
);
RString
&
append
(
RString
&
str1
,
const
RString
&
str2
);
// visszadja a pool méretét
size_t
size
();
// visszadja a szabad objektumok számát
size_t
free_size
();
};
#endif
\ No newline at end of file
rstring.h
View file @
1be7ba0c
...
...
@@ -21,6 +21,9 @@ class RString {
size_t
capacity
();
// Visszaadja a string memóriaterületére mutató pointert
operator
char
*
()
const
;
// Bemásolja a karaktertömbbe a paraméterül kapott
// karakterláncot, ha nem fér bele, eldobja a neptun kódot
RString
&
operator
=
(
const
char
*
str
);
};
#endif
\ No newline at end of file
test.cpp
View file @
1be7ba0c
...
...
@@ -19,14 +19,13 @@
#define ELKESZULT 1
/* ELKESZULT makró:
<=
5
: RString tesztjei
<=
3
: RString tesztjei
>= 10: Összes teszt
*/
int
main
()
{
GTINIT
(
std
::
cin
);
#if ELKESZULT > 0
//Caesar titkosítás ellenőrzése
TEST
(
RString
,
konstruktorok
)
{
RString
a
(
100
);
EXPECT_STREQ
(
""
,
a
);
...
...
@@ -45,6 +44,99 @@ int main() {
}
END
#endif
#if ELKESZULT > 1
TEST
(
RString
,
konstruktor
kivetel
)
{
RString
a
(
"alma"
,
5
);
EXPECT_STREQ
(
"alma"
,
a
);
EXPECT_EQ
(
5
,
a
.
capacity
());
EXPECT_EQ
(
4
,
a
.
size
());
try
{
EXPECT_THROW_THROW
(
RString
b
(
"alma"
,
4
),
const
char
*
p
);
}
catch
(
const
char
*
p
)
{
#ifdef CPORTA
EXPECT_ENVCASEEQ
(
"ORG_ID"
,
p
);
#endif
}
}
END
#endif
#if ELKESZULT > 2
TEST
(
RString
,
ertekado_str
)
{
RString
a
(
"alma"
,
20
);
a
=
"korte"
;
EXPECT_STREQ
(
"korte"
,
a
);
EXPECT_EQ
(
20
,
a
.
capacity
());
EXPECT_EQ
(
5
,
a
.
size
());
a
=
"fa"
;
EXPECT_STREQ
(
"fa"
,
a
);
EXPECT_EQ
(
20
,
a
.
capacity
());
EXPECT_EQ
(
2
,
a
.
size
());
}
END
#endif
#if ELKESZULT > 3
TEST
(
RString
,
cast
)
{
RString
a
(
"alma"
,
20
);
char
*
str
=
a
;
strcpy
(
&
str
[
4
],
"fa"
);
EXPECT_STREQ
(
"almafa"
,
a
);
EXPECT_EQ
(
20
,
a
.
capacity
());
EXPECT_EQ
(
6
,
a
.
size
());
}
END
#endif
#if ELKESZULT > 4
TEST
(
StringPool
,
init
)
{
StringPool
pool
(
10
,
20
);
EXPECT_EQ
(
10
,
pool
.
size
());
RString
&
ref
=
pool
.
acquire
(
15
);
EXPECT_EQ
(
20
,
ref
.
capacity
());
EXPECT_STREQ
(
""
,
ref
);
}
END
#endif
#if ELKESZULT > 5
TEST
(
StringPool
,
free_size
)
{
StringPool
pool
(
2
,
20
);
EXPECT_EQ
(
2
,
pool
.
free_size
());
RString
&
ref1
=
pool
.
acquire
(
15
);
EXPECT_EQ
(
1
,
pool
.
free_size
());
RString
&
ref2
=
pool
.
acquire
(
20
);
EXPECT_EQ
(
0
,
pool
.
free_size
());
EXPECT_EQ
(
20
,
ref1
.
capacity
());
EXPECT_EQ
(
20
,
ref2
.
capacity
());
}
END
#endif
#if ELKESZULT > 6
TEST
(
StringPool
,
create_new_obj
)
{
StringPool
pool
(
1
,
20
);
RString
&
ref
=
pool
.
acquire
(
15
);
EXPECT_EQ
(
0
,
pool
.
free_size
());
RString
&
newobj
=
pool
.
acquire
(
10
);
EXPECT_EQ
(
0
,
pool
.
free_size
());
EXPECT_EQ
(
2
,
pool
.
size
());
EXPECT_EQ
(
10
,
newobj
.
capacity
());
}
END
#endif
#if ELKESZULT > 7
TEST
(
StringPool
,
release
)
{
StringPool
pool
(
1
,
20
);
RString
&
ref
=
pool
.
acquire
(
15
);
EXPECT_EQ
(
1
,
pool
.
size
());
EXPECT_EQ
(
0
,
pool
.
free_size
());
ref
=
"alma"
;
pool
.
release
(
ref
);
EXPECT_EQ
(
1
,
pool
.
free_size
());
EXPECT_EQ
(
1
,
pool
.
size
());
}
END
#endif
if
(
ELKESZULT
<
10
)
ADD_FAILURE
()
<<
"
\n
Nem futott minden teszteset!"
<<
std
::
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment