written some parametric tests, few more to go

This commit is contained in:
Kjistóf 2016-10-23 21:05:14 +02:00
parent 06cebc829e
commit d5e355bf0b

View File

@ -2,6 +2,7 @@
#include <sstream>
#include <type_traits>
#include <stdexcept>
#include <tuple>
#include "String.h"
#include <gtest/gtest.h>
@ -54,38 +55,68 @@ TEST(StringTest, uninitializedStringcStrThrows)
EXPECT_THROW(str.c_str(), std::runtime_error);
}
TEST(StringTest, addable)
{
String str1("cica");
String str2("sajt");
using str3 = std::tuple<const char*, const char*, const char*>;
class addStringTest : public ::testing::TestWithParam<str3>
{};
EXPECT_STREQ("cicasajt", (str1+str2).c_str());
TEST_P(addStringTest, addable)
{
String str1(std::get<0>(GetParam()));
String str2(std::get<1>(GetParam()));
EXPECT_STREQ(std::get<2>(GetParam()), (str1+str2).c_str());
}
TEST(StringTest, plusequalsAddable)
TEST_P(addStringTest, plusEqualsable)
{
String str1("cica");
String str2("sajt");
String str1(std::get<0>(GetParam()));
String str2(std::get<1>(GetParam()));
str1 += str2;
EXPECT_STREQ("cicasajt", str1.c_str());
EXPECT_STREQ(std::get<2>(GetParam()), str1.c_str());
}
TEST(StringTest, addableChar)
static const std::vector<str3> testvalues1 =
{
String str("cicá");
std::make_tuple("cica", "sajt", "cicasajt"),
std::make_tuple("sajtos", " cica", "sajtos cica"),
std::make_tuple("szeretem", " a sajtot", "szeretem a sajtot"),
std::make_tuple("meg ", "a cicákat", "meg a cicákat"),
std::make_tuple("ennyi már ", "elég lesz", "ennyi már elég lesz")
};
EXPECT_STREQ("cicák", (str+'k').c_str());
}
INSTANTIATE_TEST_CASE_P(testGroup1, addStringTest, ::testing::ValuesIn(testvalues1));
TEST(StringTest, plusequalsAddableChar)
using strcharstr = std::tuple<const char*, char, const char*>;
class addCharStringTest : public ::testing::TestWithParam<strcharstr>
{};
TEST_P(addCharStringTest, addCharable)
{
String str("sajto");
str+='k';
String str(std::get<0>(GetParam()));
EXPECT_STREQ("sajtok", str.c_str());
EXPECT_STREQ(std::get<2>(GetParam()), (str+std::get<1>(GetParam())).c_str());
}
TEST_P(addCharStringTest, plusEqualsCharable)
{
String str(std::get<0>(GetParam()));
str+=std::get<1>(GetParam());
EXPECT_STREQ(std::get<2>(GetParam()), str.c_str());
}
static const std::vector<strcharstr> testvalues2 =
{
std::make_tuple("cicá", 'k', "cicák"),
std::make_tuple("sajto", 'k', "sajtok"),
std::make_tuple("C++1", '1', "C++11"),
std::make_tuple("", 'r', "sör"),
std::make_tuple("te", 'j', "tej")
};
INSTANTIATE_TEST_CASE_P(testGroup1, addCharStringTest, ::testing::ValuesIn(testvalues2));
TEST(StringTest, comparable)
{
String str1("cica");