Skip to content

Commit

Permalink
Исправлены тесты для storage (#27)
Browse files Browse the repository at this point in the history
* Fix tests for new requirements
* Replace string stream to string resize
  • Loading branch information
vslutov authored and xphoenix committed Sep 9, 2018
1 parent bd7adef commit 061e933
Showing 1 changed file with 30 additions and 39 deletions.
69 changes: 30 additions & 39 deletions test/storage/StorageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>

#include <storage/MapBasedGlobalLockImpl.h>
#include <afina/execute/Get.h>
Expand Down Expand Up @@ -50,76 +51,66 @@ TEST(StorageTest, PutIfAbsent) {
EXPECT_TRUE(value == "val1");
}

TEST(StorageTest, BigTest) {
MapBasedGlobalLockImpl storage(100000);
std::string
pad_space(const std::string &s, size_t length)
{
std::string result = s;
result.resize(length, ' ');
return result;
}

std::stringstream ss;
TEST(StorageTest, BigTest) {
const size_t length = 20;
MapBasedGlobalLockImpl storage(2 * 100000 * length);

for(long i=0; i<100000; ++i)
{
ss << "Key" << i;
std::string key = ss.str();
ss.str("");
ss << "Val" << i;
std::string val = ss.str();
ss.str("");
auto key = pad_space("Key " + std::to_string(i), length);
auto val = pad_space("Val " + std::to_string(i), length);
storage.Put(key, val);
}

for(long i=99999; i>=0; --i)
{
ss << "Key" << i;
std::string key = ss.str();
ss.str("");
ss << "Val" << i;
std::string val = ss.str();
ss.str("");

auto key = pad_space("Key " + std::to_string(i), length);
auto val = pad_space("Val " + std::to_string(i), length);

std::string res;
storage.Get(key, res);
EXPECT_TRUE(storage.Get(key, res));

EXPECT_TRUE(val == res);
}

}

TEST(StorageTest, MaxTest) {
MapBasedGlobalLockImpl storage(1000);
const size_t length = 20;
MapBasedGlobalLockImpl storage(2 * 1000 * length);

std::stringstream ss;

for(long i=0; i<1100; ++i)
{
ss << "Key" << i;
std::string key = ss.str();
ss.str("");
ss << "Val" << i;
std::string val = ss.str();
ss.str("");
auto key = pad_space("Key " + std::to_string(i), length);
auto val = pad_space("Val " + std::to_string(i), length);
storage.Put(key, val);
}

for(long i=100; i<1100; ++i)
{
ss << "Key" << i;
std::string key = ss.str();
ss.str("");
ss << "Val" << i;
std::string val = ss.str();
ss.str("");

auto key = pad_space("Key " + std::to_string(i), length);
auto val = pad_space("Val " + std::to_string(i), length);

std::string res;
storage.Get(key, res);
EXPECT_TRUE(storage.Get(key, res));

EXPECT_TRUE(val == res);
}

for(long i=0; i<100; ++i)
{
ss << "Key" << i;
std::string key = ss.str();
ss.str("");

auto key = pad_space("Key " + std::to_string(i), length);

std::string res;
EXPECT_FALSE(storage.Get(key, res));
}
Expand Down

0 comments on commit 061e933

Please sign in to comment.