Commit 3582e9a3 by Karsa Zoltán István

size_t numbers

parent 7e8d2adf
......@@ -7,4 +7,5 @@
* Ezt a fájlt be kell adni (fel kell tölteni) a megoldással.
*/
#include "memtrace.h"
#include "pool.h"
\ No newline at end of file
......@@ -11,6 +11,7 @@
#ifndef POOL_H
#define POOL_H
#include "memtrace.h"
#include "rstring.h"
class StringPool {
......
......@@ -7,4 +7,5 @@
* Ezt a fájlt be kell adni (fel kell tölteni) a megoldással.
*/
#include "memtrace.h"
#include "rstring.h"
\ No newline at end of file
......@@ -12,6 +12,7 @@
#define RSTRING_H
#include <cstdio>
#include "memtrace.h"
class RString {
public:
......
......@@ -29,18 +29,18 @@ int main() {
TEST(RString, konstruktorok) {
RString a(100);
EXPECT_STREQ("", a);
EXPECT_EQ(100, a.capacity());
EXPECT_EQ(0, a.size());
EXPECT_EQ(100u, a.capacity());
EXPECT_EQ(0u, a.size());
RString b("alma");
EXPECT_STREQ("alma", b);
EXPECT_EQ(5, b.capacity());
EXPECT_EQ(4, b.size());
EXPECT_EQ(5u, b.capacity());
EXPECT_EQ(4u, b.size());
RString c("alma", 10);
EXPECT_STREQ("alma", b);
EXPECT_EQ(10, c.capacity());
EXPECT_EQ(4, c.size());
EXPECT_EQ(10u, c.capacity());
EXPECT_EQ(4u, c.size());
} END
#endif
......@@ -48,8 +48,8 @@ int main() {
TEST(RString, konstruktor kivetel) {
RString a("alma", 5);
EXPECT_STREQ("alma", a);
EXPECT_EQ(5, a.capacity());
EXPECT_EQ(4, a.size());
EXPECT_EQ(5u, a.capacity());
EXPECT_EQ(4u, a.size());
try {
EXPECT_THROW_THROW(RString b("alma", 4), const char* p);
......@@ -66,12 +66,12 @@ int main() {
RString a("alma", 20);
a = "korte";
EXPECT_STREQ("korte", a);
EXPECT_EQ(20, a.capacity());
EXPECT_EQ(5, a.size());
EXPECT_EQ(20u, a.capacity());
EXPECT_EQ(5u, a.size());
a = "fa";
EXPECT_STREQ("fa", a);
EXPECT_EQ(20, a.capacity());
EXPECT_EQ(2, a.size());
EXPECT_EQ(20u, a.capacity());
EXPECT_EQ(2u, a.size());
} END
#endif
......@@ -81,8 +81,8 @@ int main() {
char* str = a;
strcpy(&str[4], "fa");
EXPECT_STREQ("almafa", a);
EXPECT_EQ(20, a.capacity());
EXPECT_EQ(6, a.size());
EXPECT_EQ(20u, a.capacity());
EXPECT_EQ(6u, a.size());
} END
#endif
......@@ -90,10 +90,10 @@ int main() {
#if ELKESZULT > 4
TEST(StringPool, init) {
StringPool pool(10, 20);
EXPECT_EQ(10, pool.size());
EXPECT_EQ(10, pool.free_size());
EXPECT_EQ(10u, pool.size());
EXPECT_EQ(10u, pool.free_size());
RString& ref = pool.acquire(15);
EXPECT_EQ(20, ref.capacity());
EXPECT_EQ(20u, ref.capacity());
EXPECT_STREQ("", ref);
RString& ref2 = pool.acquire("almafa");
EXPECT_STREQ("almafa", ref2);
......@@ -104,13 +104,13 @@ int main() {
#if ELKESZULT > 5
TEST(StringPool, free_size) {
StringPool pool(2, 20);
EXPECT_EQ(2, pool.free_size());
EXPECT_EQ(2u, pool.free_size());
RString& ref1 = pool.acquire(15);
EXPECT_EQ(1, pool.free_size());
EXPECT_EQ(1u, pool.free_size());
RString& ref2 = pool.acquire(20);
EXPECT_EQ(0, pool.free_size());
EXPECT_EQ(20, ref1.capacity());
EXPECT_EQ(20, ref2.capacity());
EXPECT_EQ(0u, pool.free_size());
EXPECT_EQ(20u, ref1.capacity());
EXPECT_EQ(20u, ref2.capacity());
} END
#endif
......@@ -118,12 +118,12 @@ int main() {
TEST(StringPool, create_new_obj) {
StringPool pool(1, 20);
RString& ref = pool.acquire(15);
EXPECT_EQ(20, ref.capacity());
EXPECT_EQ(0, pool.free_size());
EXPECT_EQ(20u, ref.capacity());
EXPECT_EQ(0u, pool.free_size());
RString& newobj = pool.acquire(10);
EXPECT_EQ(0, pool.free_size());
EXPECT_EQ(2, pool.size());
EXPECT_EQ(10, newobj.capacity());
EXPECT_EQ(0u, pool.free_size());
EXPECT_EQ(2u, pool.size());
EXPECT_EQ(10u, newobj.capacity());
} END
#endif
......@@ -131,15 +131,15 @@ int main() {
TEST(StringPool, release) {
StringPool pool(1, 20);
RString& ref = pool.acquire(15);
EXPECT_EQ(1, pool.size());
EXPECT_EQ(0, pool.free_size());
EXPECT_EQ(1u, pool.size());
EXPECT_EQ(0u, pool.free_size());
EXPECT_FALSE(pool.acquireable(ref));
ref = "alma";
EXPECT_STREQ("alma", ref);
pool.release(ref);
EXPECT_TRUE(pool.acquireable(ref));
EXPECT_EQ(1, pool.free_size());
EXPECT_EQ(1, pool.size());
EXPECT_EQ(1u, pool.free_size());
EXPECT_EQ(1u, pool.size());
ref = pool.acquire(15);
EXPECT_STREQ("", ref);
} END
......@@ -149,21 +149,21 @@ int main() {
TEST(StringPool, release_new) {
StringPool pool(2, 15);
RString& ref = pool.acquire(30);
EXPECT_EQ(3, pool.size());
EXPECT_EQ(30, ref.capacity());
EXPECT_EQ(2, pool.free_size());
EXPECT_EQ(3u, pool.size());
EXPECT_EQ(30u, ref.capacity());
EXPECT_EQ(2u, pool.free_size());
ref = "alma";
RString& ref2 = pool.acquire(15);
EXPECT_EQ(3, pool.size());
EXPECT_EQ(15, ref2.capacity());
EXPECT_EQ(1, pool.free_size());
EXPECT_EQ(3u, pool.size());
EXPECT_EQ(15u, ref2.capacity());
EXPECT_EQ(1u, pool.free_size());
pool.release(ref);
pool.release(ref2);
EXPECT_EQ(3, pool.free_size());
EXPECT_EQ(3, pool.size());
EXPECT_EQ(3u, pool.free_size());
EXPECT_EQ(3u, pool.size());
pool.release(ref2);
EXPECT_EQ(3, pool.free_size());
EXPECT_EQ(3, pool.size());
EXPECT_EQ(3u, pool.free_size());
EXPECT_EQ(3u, pool.size());
} END
#endif
......@@ -172,23 +172,23 @@ int main() {
TEST(StringPool, release_complex) {
StringPool pool(3, 15);
RString& ref1 = pool.acquire(15);
EXPECT_EQ(3, pool.size());
EXPECT_EQ(15, ref1.capacity());
EXPECT_EQ(2, pool.free_size());
EXPECT_EQ(3u, pool.size());
EXPECT_EQ(15u, ref1.capacity());
EXPECT_EQ(2u, pool.free_size());
RString& ref2 = pool.acquire(30);
EXPECT_EQ(4, pool.size());
EXPECT_EQ(30, ref2.capacity());
EXPECT_EQ(2, pool.free_size());
EXPECT_EQ(4u, pool.size());
EXPECT_EQ(30u, ref2.capacity());
EXPECT_EQ(2u, pool.free_size());
pool.release(ref2);
EXPECT_EQ(3, pool.free_size());
EXPECT_EQ(4, pool.size());
EXPECT_EQ(3u, pool.free_size());
EXPECT_EQ(4u, pool.size());
RString& ref3 = pool.acquire(25);
EXPECT_EQ(4, pool.size());
EXPECT_EQ(30, ref2.capacity());
EXPECT_EQ(2, pool.free_size());
EXPECT_EQ(4u, pool.size());
EXPECT_EQ(30u, ref2.capacity());
EXPECT_EQ(2u, pool.free_size());
pool.release(ref3);
EXPECT_EQ(3, pool.free_size());
EXPECT_EQ(4, pool.size());
EXPECT_EQ(3u, pool.free_size());
EXPECT_EQ(4u, pool.size());
} END
#endif
......@@ -196,36 +196,36 @@ int main() {
TEST(StringPool, max_capacity_check) {
StringPool pool(1, 10);
pool.release(pool.acquire(5));
EXPECT_EQ(1, pool.free_size());
EXPECT_EQ(1, pool.size());
EXPECT_EQ(1u, pool.free_size());
EXPECT_EQ(1u, pool.size());
RString& tmp = pool.acquire(15);
pool.release(pool.acquire(20));
pool.release(pool.acquire(25));
pool.release(tmp);
EXPECT_EQ(4, pool.free_size());
EXPECT_EQ(4, pool.size());
EXPECT_EQ(4u, pool.free_size());
EXPECT_EQ(4u, pool.size());
RString& ref = pool.acquire(15);
EXPECT_EQ(3, pool.free_size());
EXPECT_EQ(4, pool.size());
EXPECT_EQ(15, ref.capacity());
EXPECT_EQ(3u, pool.free_size());
EXPECT_EQ(4u, pool.size());
EXPECT_EQ(15u, ref.capacity());
RString& ref1 = pool.acquire(15);
EXPECT_EQ(2, pool.free_size());
EXPECT_EQ(4, pool.size());
EXPECT_EQ(20, ref1.capacity());
EXPECT_EQ(2u, pool.free_size());
EXPECT_EQ(4u, pool.size());
EXPECT_EQ(20u, ref1.capacity());
RString& ref2 = pool.acquire(15);
EXPECT_EQ(1, pool.free_size());
EXPECT_EQ(4, pool.size());
EXPECT_EQ(25, ref2.capacity());
EXPECT_EQ(1u, pool.free_size());
EXPECT_EQ(4u, pool.size());
EXPECT_EQ(25u, ref2.capacity());
RString& ref3 = pool.acquire(15);
EXPECT_EQ(1, pool.free_size());
EXPECT_EQ(5, pool.size());
EXPECT_EQ(15, ref3.capacity());
EXPECT_EQ(1u, pool.free_size());
EXPECT_EQ(5u, pool.size());
EXPECT_EQ(15u, ref3.capacity());
pool.release(ref1);
pool.release(ref2);
RString& ref4 = pool.acquire(15);
EXPECT_EQ(2, pool.free_size());
EXPECT_EQ(5, pool.size());
EXPECT_EQ(20, ref4.capacity());
EXPECT_EQ(2u, pool.free_size());
EXPECT_EQ(5u, pool.size());
EXPECT_EQ(20u, ref4.capacity());
} END
#endif
......@@ -235,8 +235,8 @@ int main() {
RString& alma = pool.acquire("alma");
const RString& fa = pool.acquire("fa");
RString& almafa = pool.append(alma, fa);
EXPECT_EQ(3, pool.size());
EXPECT_EQ(1, pool.free_size());
EXPECT_EQ(3u, pool.size());
EXPECT_EQ(1u, pool.free_size());
EXPECT_EQ(&almafa, &alma);
EXPECT_STREQ("almafa", almafa);
} END
......@@ -248,8 +248,8 @@ int main() {
RString& arvizturo = pool.acquire("arvizturo");
RString& tukorfurogep = pool.acquire("tukorfurogep");
RString& egyben = pool.append(arvizturo, tukorfurogep);
EXPECT_EQ(4, pool.size());
EXPECT_EQ(1, pool.free_size());
EXPECT_EQ(4u, pool.size());
EXPECT_EQ(1u, pool.free_size());
EXPECT_NE(&arvizturo, &egyben);
EXPECT_STREQ("arvizturotukorfurogep", egyben);
} END
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment