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

@@ -3,9 +3,15 @@
#include "pistring.h"
#include "pideque.h"
#include "piflags.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(PIByteArray_Tests, construct_empty_BA){
PIByteArray arr;
ASSERT_TRUE(arr.isEmpty());
@@ -426,7 +432,7 @@ TEST(PIByteArray_Tests, operator_shift_int){
const int v = -1;
arr1 << v;
PIByteArray arr(4);
for (short i = 0; i < 4; i ++) arr[i] = 255;
for (size_t i = 0; i < 4; i ++) arr[i] = 255;
ASSERT_EQ(arr1, arr);
}
@@ -435,7 +441,7 @@ TEST(PIByteArray_Tests, operator_shift_long){
const long v = -1;
arr1 << v;
PIByteArray arr(4);
for (short i = 0; i < 4; i ++) arr[i] = 255;
for (size_t i = 0; i < 4; i ++) arr[i] = 255;
ASSERT_EQ(arr1, arr);
}
@@ -444,7 +450,7 @@ TEST(PIByteArray_Tests, operator_shift_llong){
const llong v = -1;
arr1 << v;
PIByteArray arr(8);
for (short i = 0; i < 8; i ++) arr[i] = 255;
for (size_t i = 0; i < 8; i ++) arr[i] = 255;
ASSERT_EQ(arr1, arr);
}
@@ -464,7 +470,7 @@ TEST(PIByteArray_Tests, operator_shift_uint){
arr1 << v;
PIByteArray arr(4);
arr[0] = 254;
for (short i = 1; i < 4; i ++) arr[i] = 0;
for (size_t i = 1; i < 4; i ++) arr[i] = 0;
ASSERT_EQ(arr1, arr);
}
@@ -474,7 +480,7 @@ TEST(PIByteArray_Tests, operator_shift_ulong){
arr1 << v;
PIByteArray arr(4);
arr[0] = 254;
for (short i = 1; i < 4; i ++) arr[i] = 0;
for (size_t i = 1; i < 4; i ++) arr[i] = 0;
ASSERT_EQ(arr1, arr);
}
@@ -484,13 +490,13 @@ TEST(PIByteArray_Tests, operator_shift_ullong){
arr1 << v;
PIByteArray arr(8);
arr[0] = 254;
for (short i = 1; i < 8; i ++) arr[i] = 0;
for (size_t i = 1; i < 8; i ++) arr[i] = 0;
ASSERT_EQ(arr, arr1);
}
TEST(PIByteArray_Tests, operator_shift_float){
PIByteArray arr1;
const float v = 31.764;
const float v = 31.764f;
arr1 << v;
PIByteArray arr(4);
arr[0] = 172;
@@ -516,30 +522,13 @@ TEST(PIByteArray_Tests, operator_shift_double){
ASSERT_EQ(arr, arr1);
}
TEST(PIByteArray_Tests, operator_shift_ldouble){ //хуевый тест
TEST(PIByteArray_Tests, operator_shift_ldouble){
PIByteArray arr1;
const ldouble v = 334451.761422;
const ldouble v = 334451.761422l;
ldouble res;
arr1 << v;
PIByteArray arr(16);
arr[0] = 0;
arr[1] = 144;
arr[2] = 171;
arr[3] = 145;
arr[4] = 93;
arr[5] = 120;
arr[6] = 78;
arr[7] = 163;
arr[8] = 17;
arr[9] = 64;
arr[10] = 218;
arr[11] = 0;
arr[12] = 0;
arr[13] = 0;
arr[14] = 0;
arr[15] = 0;
piCout << arr1 << (arr == arr1);
//ASSERT_EQ(arr, arr1);
arr1 >> res;
ASSERT_TRUE(is_equal(res, v));
}
TEST(PIByteArray_Tests, operator_shift_PIFlags){
@@ -586,7 +575,7 @@ TEST(PIByteArray_Tests, operator_shift_right_bool){
}
TEST(PIByteArray_Tests, operator_shift_right_char){
PIByteArray arr((void*)"n", 1);
PIByteArray arr((void*)"n", 1);
char v;
arr >> v;
@@ -611,7 +600,7 @@ TEST(PIByteArray_Tests, operator_shift_right_short){
TEST(PIByteArray_Tests, operator_shift_right_int){
PIByteArray arr(4);
for (short i = 0; i < 4; i ++) arr[i] = 255;
for (size_t i = 0; i < 4; i ++) arr[i] = 255;
int v;
arr >> v;
ASSERT_EQ(v, -1);
@@ -619,7 +608,7 @@ TEST(PIByteArray_Tests, operator_shift_right_int){
TEST(PIByteArray_Tests, operator_shift_right_long){
PIByteArray arr(4);
for (short i = 0; i < 4; i ++) arr[i] = 255;
for (size_t i = 0; i < 4; i ++) arr[i] = 255;
long v = -1;
arr >> v;
ASSERT_EQ(v, -1);
@@ -627,7 +616,7 @@ TEST(PIByteArray_Tests, operator_shift_right_long){
TEST(PIByteArray_Tests, operator_shift_right_llong){
PIByteArray arr(8);
for (short i = 0; i < 8; i ++) arr[i] = 255;
for (size_t i = 0; i < 8; i ++) arr[i] = 255;
llong v = -1;
arr >> v;
ASSERT_EQ(v, -1);
@@ -645,7 +634,7 @@ TEST(PIByteArray_Tests, operator_shift_right_ushort){
TEST(PIByteArray_Tests, operator_shift_right_uint){
PIByteArray arr(4);
arr[0] = 254;
for (short i = 1; i < 4; i ++) arr[i] = 0;
for (size_t i = 1; i < 4; i ++) arr[i] = 0;
uint v;
arr >> v;
ASSERT_EQ(v, 254);
@@ -654,7 +643,7 @@ TEST(PIByteArray_Tests, operator_shift_right_uint){
TEST(PIByteArray_Tests, operator_shift_right_ulong){
PIByteArray arr(4);
arr[0] = 254;
for (short i = 1; i < 4; i ++) arr[i] = 0;
for (size_t i = 1; i < 4; i ++) arr[i] = 0;
ulong v;
arr >> v;
ASSERT_EQ(v, 254);
@@ -663,7 +652,7 @@ TEST(PIByteArray_Tests, operator_shift_right_ulong){
TEST(PIByteArray_Tests, operator_shift_right_ullong){
PIByteArray arr(8);
arr[0] = 254;
for (short i = 1; i < 8; i ++) arr[i] = 0;
for (size_t i = 1; i < 8; i ++) arr[i] = 0;
ullong v;
arr >> v;
ASSERT_EQ(v, 254);
@@ -676,13 +665,13 @@ TEST(PIByteArray_Tests, operator_shift_right_float){
arr[2] = 254;
arr[3] = 65;
float v;
float res = 31.764;
float res = 31.764f;
arr >> v;
ASSERT_EQ(v, res);
ASSERT_TRUE(is_equal(res, v));
}
/*TEST(DISABLEDPIByteArray_Tests, operator_shift_right_double){ //хуевый тест
PIByteArray arr(7);
TEST(PIByteArray_Tests, operator_shift_right_double){
PIByteArray arr(8);
const double res = 3341.76422;
double v;
arr[0] = 230;
@@ -694,31 +683,7 @@ TEST(PIByteArray_Tests, operator_shift_right_float){
arr[6] = 170;
arr[7] = 64;
arr >> v;
ASSERT_EQ(v, res);
}*/
TEST(PIByteArray_Tests, operator_shift_right_ldouble){
PIByteArray arr(16);
const ldouble res = 334451.761422;
ldouble v;
arr[0] = 0;
arr[1] = 144;
arr[2] = 171;
arr[3] = 145;
arr[4] = 93;
arr[5] = 120;
arr[6] = 78;
arr[7] = 163;
arr[8] = 17;
arr[9] = 64;
arr[10] = 0;
arr[11] = 0;
arr[12] = 0;
arr[13] = 0;
arr[14] = 0;
arr[15] = 0;
arr >> v;
ASSERT_EQ(v, res);
ASSERT_TRUE(is_equal(v,res));
}
TEST(PIByteArray_Tests, operator_shift_right_PIFlags){

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);