improve the code

This commit is contained in:
2020-10-08 21:47:40 +03:00
parent 735b24574a
commit 9af990c2f0
2 changed files with 70 additions and 79 deletions

View File

@@ -1,9 +1,15 @@
#include "gtest/gtest.h"
#include "pistring.h"
#include "pistringlist.h"
#include "math.h"
using namespace std;
template <typename T>
bool is_equal(T x, T y) {
return std::fabs(x - y) < std::numeric_limits<T>::epsilon();
}
TEST(PIString_Tests, constructor_empty){
PIString str1;
ASSERT_TRUE(str1.isEmpty());
@@ -114,10 +120,16 @@ TEST(PIString_Tests, operator_concatenation_piByteArray_zero_zero){
TEST(PIString_Tests, construct_pistring){
PIString str1 = "New";
PIString str(str1);
ASSERT_EQ(str1, str);
}
TEST(PIString_Tests, construct_pistring_move){
PIString str1 = "New";
PIString res = str1;
PIString str(move(str1));
ASSERT_EQ(res, str);
}
TEST(PIString_Tests, construct_pichar){
PIChar str1 = 'n';
PIString res = "n";
@@ -176,6 +188,20 @@ TEST(PIString_Tests, construct_pichar_len){
ASSERT_EQ(res, PIString(5, str1));
}
TEST(PIString_Tests, operator_assignment){
PIString str1 = "testing";
PIString str;
str = str1;
ASSERT_EQ(PIString("testing"), str);
}
TEST(PIString_Tests, operator_assignment_move){
PIString str1 = "testing";
PIString str;
str = move(str1);
ASSERT_EQ(PIString("testing"), str);
}
TEST(PIString_Tests, operator_symbol){
PIString str1 = "testing";
PIChar symbo = "i";
@@ -218,37 +244,37 @@ TEST(PIString_Tests, operator_compare_char_false){
ASSERT_FALSE(str1 == str2);
}
TEST(PIString_Tests, operator_encompare_pistring_false){
TEST(PIString_Tests, operator_enq_compare_pistring_false){
PIString str1 = "testing";
PIString str2 = "testing";
ASSERT_FALSE(str1 != str2);
}
TEST(PIString_Tests, operator_encompare_pistring_true){
TEST(PIString_Tests, operator_enq_compare_pistring_true){
PIString str1 = "tes";
PIString str2 = "testing";
ASSERT_TRUE(str1 != str2);
}
TEST(PIString_Tests, operator_encompare_pichar_false){
TEST(PIString_Tests, operator_enq_compare_pichar_false){
PIString str1 = "t";
PIChar str2 = "t";
ASSERT_FALSE(str1 != str2);
}
TEST(PIString_Tests, operator_encompare_pichar_true){
TEST(PIString_Tests, operator_enq_compare_pichar_true){
PIString str1 = "t";
PIChar str2 = "p";
ASSERT_TRUE(str1 != str2);
}
TEST(PIString_Tests, operator_encompare_char_false){
TEST(PIString_Tests, operator_enq_compare_char_false){
PIString str1 = "test";
char str2[] = "test";
ASSERT_FALSE(str1 != str2);
}
TEST(PIString_Tests, operator_encompare_char_true){
TEST(PIString_Tests, operator_enq_compare_char_true){
PIString str1 = "t";
char str2[] = "test";
ASSERT_TRUE(str1 != str2);
@@ -2099,19 +2125,19 @@ TEST(PIString_Tests, to_ullong_false_base){
TEST(PIString_Tests, to_float){
PIString str1 = "-7765,54";
float f = -7765.54f;
ASSERT_EQ(f, str1.toFloat());
ASSERT_TRUE(is_equal(f, str1.toFloat()));
}
TEST(PIString_Tests, to_double){
PIString str1 = "-7765,54656";
double f = -7765.54656;
ASSERT_EQ(f, str1.toDouble());
ASSERT_TRUE(is_equal(f, str1.toDouble()));
}
TEST(DISABLED_PIString_Tests, to_ldouble){
PIString str1 = "-7765,55";
ldouble f = -7765.55l;
ASSERT_TRUE(f == str1.toLDouble());
TEST(PIString_Tests, to_ldouble){
PIString str1 = "7765,555445";
ldouble f = 7765.555445l;
ASSERT_TRUE(fabs(f - str1.toLDouble()) < 1e-10l);
}
TEST(PIString_Tests, setNumber){
@@ -2546,7 +2572,7 @@ TEST(PIString_Tests, setNumber_double){
ASSERT_EQ(res, str1);
}
TEST(DISABLED_PIString_Tests, setNumber_ldouble){
TEST(PIString_Tests, setNumber_ldouble){
PIString str1 = " String";
const ldouble val = 131.1324334l;
str1.setNumber(val, 'f', 7);