From d5e355bf0b559643ec2b7406caed2a489181e2db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sun, 23 Oct 2016 21:05:14 +0200 Subject: [PATCH] written some parametric tests, few more to go --- test.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/test.cpp b/test.cpp index 09f53c8..5fe251f 100644 --- a/test.cpp +++ b/test.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "String.h" #include @@ -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; +class addStringTest : public ::testing::TestWithParam +{}; - 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 testvalues1 = + { + 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") + }; + +INSTANTIATE_TEST_CASE_P(testGroup1, addStringTest, ::testing::ValuesIn(testvalues1)); + +using strcharstr = std::tuple; +class addCharStringTest : public ::testing::TestWithParam +{}; + +TEST_P(addCharStringTest, addCharable) { - String str("cicá"); + String str(std::get<0>(GetParam())); - EXPECT_STREQ("cicák", (str+'k').c_str()); + EXPECT_STREQ(std::get<2>(GetParam()), (str+std::get<1>(GetParam())).c_str()); } -TEST(StringTest, plusequalsAddableChar) +TEST_P(addCharStringTest, plusEqualsCharable) { - String str("sajto"); - str+='k'; + String str(std::get<0>(GetParam())); + str+=std::get<1>(GetParam()); - EXPECT_STREQ("sajtok", str.c_str()); + EXPECT_STREQ(std::get<2>(GetParam()), str.c_str()); } +static const std::vector 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("sö", 'r', "sör"), + std::make_tuple("te", 'j', "tej") + }; + +INSTANTIATE_TEST_CASE_P(testGroup1, addCharStringTest, ::testing::ValuesIn(testvalues2)); + TEST(StringTest, comparable) { String str1("cica");