Commit 3582e9a3 by Karsa Zoltán István

size_t numbers

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