Tests for PIString 21-30. And add tab

This commit is contained in:
2021-01-22 16:15:45 +03:00
parent a5531933a2
commit fe6d8ca1d3

View File

@@ -7,209 +7,209 @@ using namespace std;
template <typename T> template <typename T>
bool is_equal(T x, T y) { bool is_equal(T x, T y) {
return std::fabs(x - y) < std::numeric_limits<T>::epsilon(); return std::fabs(x - y) < std::numeric_limits<T>::epsilon();
} }
TEST(PIString_Tests, constructor_empty){ TEST(PIString_Tests, constructor_empty){
PIString str1; PIString str1;
ASSERT_TRUE(str1.isEmpty()); ASSERT_TRUE(str1.isEmpty());
} }
TEST(PIString_Tests, operator_concatenation_pichar){ TEST(PIString_Tests, operator_concatenation_pichar){
PIString str1 = "AB C"; PIString str1 = "AB C";
const PIChar str2 = " "; const PIChar str2 = " ";
str1 += str2; str1 += str2;
PIString res = "AB C "; PIString res = "AB C ";
ASSERT_EQ(str1, res); ASSERT_EQ(str1, res);
} }
TEST(PIString_Tests, operator_concatenation_pichar_zero1){ TEST(PIString_Tests, operator_concatenation_pichar_zero1){
PIString str1 = ""; PIString str1 = "";
const PIChar str2 = "D"; const PIChar str2 = "D";
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "D"); ASSERT_EQ(str1, "D");
} }
TEST(PIString_Tests, operator_concatenation_cstring){ TEST(PIString_Tests, operator_concatenation_cstring){
PIString str1 = "AB C"; PIString str1 = "AB C";
const char *str2 = "D D "; const char *str2 = "D D ";
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "AB CD D "); ASSERT_EQ(str1, "AB CD D ");
} }
TEST(PIString_Tests, operator_concatenation_cstring_zero1){ TEST(PIString_Tests, operator_concatenation_cstring_zero1){
PIString str1 = ""; PIString str1 = "";
const char *str2 = "D D "; const char *str2 = "D D ";
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "D D "); ASSERT_EQ(str1, "D D ");
} }
TEST(PIString_Tests, operator_concatenation_wchar){ TEST(PIString_Tests, operator_concatenation_wchar){
PIString str1= "AB C"; PIString str1= "AB C";
wchar_t str2[] = L"C"; wchar_t str2[] = L"C";
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "AB CC"); ASSERT_EQ(str1, "AB CC");
} }
TEST(PIString_Tests, operator_concatenation_wchar_zero1){ TEST(PIString_Tests, operator_concatenation_wchar_zero1){
PIString str1 = ""; PIString str1 = "";
wchar_t str2[] = L"C"; wchar_t str2[] = L"C";
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "C"); ASSERT_EQ(str1, "C");
} }
TEST(PIString_Tests, operator_concatenation_pistring){ TEST(PIString_Tests, operator_concatenation_pistring){
PIString str1 = "AB C"; PIString str1 = "AB C";
PIString str2 = " CD "; PIString str2 = " CD ";
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "AB C CD "); ASSERT_EQ(str1, "AB C CD ");
} }
TEST(PIString_Tests, operator_concatenation_pistring_zero1){ TEST(PIString_Tests, operator_concatenation_pistring_zero1){
PIString str1 = ""; PIString str1 = "";
PIString str2 = "D DD"; PIString str2 = "D DD";
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "D DD"); ASSERT_EQ(str1, "D DD");
} }
TEST(PIString_Tests, operator_concatenation_pistring_zero2){ TEST(PIString_Tests, operator_concatenation_pistring_zero2){
PIString str1 = "AB C"; PIString str1 = "AB C";
PIString str2 = ""; PIString str2 = "";
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "AB C"); ASSERT_EQ(str1, "AB C");
} }
TEST(PIString_Tests, operator_concatenation_pistring_zero_zero){ TEST(PIString_Tests, operator_concatenation_pistring_zero_zero){
PIString str1; PIString str1;
PIString str2; PIString str2;
str1 += str2; str1 += str2;
ASSERT_EQ(str1, ""); ASSERT_EQ(str1, "");
} }
TEST(PIString_Tests, operator_concatenation_piByteArray){ TEST(PIString_Tests, operator_concatenation_piByteArray){
PIString str1 = "AB C"; PIString str1 = "AB C";
PIByteArray str2; PIByteArray str2;
str2.append('g'); str2.append('g');
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "AB Cg"); ASSERT_EQ(str1, "AB Cg");
} }
TEST(PIString_Tests, operator_concatenation_piByteArray_zero1){ TEST(PIString_Tests, operator_concatenation_piByteArray_zero1){
PIString str1 = ""; PIString str1 = "";
PIByteArray str2; PIByteArray str2;
str2.append('0'); str2.append('0');
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "0"); ASSERT_EQ(str1, "0");
} }
TEST(PIString_Tests, operator_concatenation_piByteArray_zero2){ TEST(PIString_Tests, operator_concatenation_piByteArray_zero2){
PIString str1 = "AB C"; PIString str1 = "AB C";
PIByteArray str2; PIByteArray str2;
str1 += str2; str1 += str2;
ASSERT_EQ(str1, "AB C"); ASSERT_EQ(str1, "AB C");
} }
TEST(PIString_Tests, operator_concatenation_piByteArray_zero_zero){ TEST(PIString_Tests, operator_concatenation_piByteArray_zero_zero){
PIString str1; PIString str1;
PIByteArray str2; PIByteArray str2;
str1 += str2; str1 += str2;
ASSERT_EQ(str1, ""); ASSERT_EQ(str1, "");
} }
TEST(PIString_Tests, construct_pistring){ TEST(PIString_Tests, construct_pistring){
PIString str1 = "New"; PIString str1 = "New";
PIString str(str1); PIString str(str1);
ASSERT_EQ(str1, str); ASSERT_EQ(str1, str);
} }
TEST(PIString_Tests, construct_pistring_move){ TEST(PIString_Tests, construct_pistring_move){
PIString str1 = "New"; PIString str1 = "New";
PIString res = str1; PIString res = str1;
PIString str(move(str1)); PIString str(move(str1));
ASSERT_EQ(res, str); ASSERT_EQ(res, str);
} }
TEST(PIString_Tests, construct_from_pichar){ TEST(PIString_Tests, construct_from_pichar){
PIChar str1 = 'n'; PIChar str1 = 'n';
PIString res = "n"; PIString res = "n";
ASSERT_EQ(res, PIString(str1)); ASSERT_EQ(res, PIString(str1));
} }
TEST(PIString_Tests, construct_from_char){ TEST(PIString_Tests, construct_from_char){
char str1 = 'n'; char str1 = 'n';
PIString res = "n"; PIString res = "n";
ASSERT_EQ(res, PIString(str1)); ASSERT_EQ(res, PIString(str1));
} }
TEST(PIString_Tests, construct_from_cstring){ TEST(PIString_Tests, construct_from_cstring){
char str1[] = "mew"; char str1[] = "mew";
PIString res = "mew"; PIString res = "mew";
ASSERT_EQ(res, PIString(str1)); ASSERT_EQ(res, PIString(str1));
} }
TEST(PIString_Tests, construct_from_wchar_t){ TEST(PIString_Tests, construct_from_wchar_t){
wchar_t str1[] = L"gav"; wchar_t str1[] = L"gav";
PIString res = "gav"; PIString res = "gav";
ASSERT_EQ(res, PIString(str1)); ASSERT_EQ(res, PIString(str1));
} }
TEST(PIString_Tests, construct_from_pibyte_array){ TEST(PIString_Tests, construct_from_pibyte_array){
PIByteArray str1; PIByteArray str1;
str1.append('m'); str1.append('m');
PIString res = "m"; PIString res = "m";
ASSERT_EQ(res, PIString(str1)); ASSERT_EQ(res, PIString(str1));
} }
TEST(PIString_Tests, construct_from_pichar_size){ TEST(PIString_Tests, construct_from_pichar_size){
PIChar *str1 = new PIChar[3]; PIChar *str1 = new PIChar[3];
str1[0] = 'n'; str1[0] = 'n';
str1[1] = 'e'; str1[1] = 'e';
str1[2] = 'w'; str1[2] = 'w';
PIString res = "new"; PIString res = "new";
ASSERT_EQ(res, PIString(str1, 3)); ASSERT_EQ(res, PIString(str1, 3));
} }
TEST(PIString_Tests, construct_from_char_size){ TEST(PIString_Tests, construct_from_char_size){
char str1[] = "good"; char str1[] = "good";
PIString res = "good"; PIString res = "good";
ASSERT_EQ(res, PIString(str1, 4)); ASSERT_EQ(res, PIString(str1, 4));
} }
TEST(PIString_Tests, construct_from_char_len){ TEST(PIString_Tests, construct_from_char_len){
char str1 = 'n'; char str1 = 'n';
PIString res = "nnn"; PIString res = "nnn";
ASSERT_EQ(res, PIString(3, str1)); ASSERT_EQ(res, PIString(3, str1));
} }
TEST(PIString_Tests, construct_from_pichar_len){ TEST(PIString_Tests, construct_from_pichar_len){
PIChar str1 = 'n'; PIChar str1 = 'n';
PIString res = "nnnnn"; PIString res = "nnnnn";
ASSERT_EQ(res, PIString(5, str1)); ASSERT_EQ(res, PIString(5, str1));
} }
TEST(PIString_Tests, operator_assignment){ TEST(PIString_Tests, operator_assignment){
PIString str1 = "testing"; PIString str1 = "testing";
PIString str; PIString str;
str = str1; str = str1;
ASSERT_EQ(PIString("testing"), str); ASSERT_EQ(PIString("testing"), str);
} }
TEST(PIString_Tests, operator_assignment_move){ TEST(PIString_Tests, operator_assignment_move){
PIString str1 = "testing"; PIString str1 = "testing";
PIString str; PIString str;
str = move(str1); str = move(str1);
ASSERT_EQ(PIString("testing"), str); ASSERT_EQ(PIString("testing"), str);
} }
TEST(PIString_Tests, operator_symbol){ TEST(PIString_Tests, operator_symbol){
PIString str1 = "testing"; PIString str1 = "testing";
PIChar symbo = "i"; PIChar symbo = "i";
ASSERT_EQ(symbo, str1[4]); ASSERT_EQ(symbo, str1[4]);
} }
TEST(PIString_Tests, operator_compare_pistring_true){ TEST(PIString_Tests, operator_compare_pistring_true){
PIString str1 = "testing"; PIString str1 = "testing";
PIString str2 = "testing"; PIString str2 = "testing";
ASSERT_TRUE(str1 == str2); ASSERT_TRUE(str1 == str2);
} }