From c3abd747f2bad7a2419b646447728e122727dcbf Mon Sep 17 00:00:00 2001 From: maakshishov Date: Thu, 17 Sep 2020 17:07:29 +0300 Subject: [PATCH 01/14] PIMathVector Tests and bug fixes in PIMathMatrixT --- tests/CMakeLists.txt | 2 +- tests/core/pistringTest.cpp | 2978 ------------------------------ tests/math/testpimathmatrix.cpp | 145 +- tests/math/testpimathmatrixt.cpp | 12 +- tests/math/testpimathvector.cpp | 364 ++++ tests/math/testpimathvectort.cpp | 427 +++++ 6 files changed, 870 insertions(+), 3058 deletions(-) delete mode 100644 tests/core/pistringTest.cpp create mode 100644 tests/math/testpimathvector.cpp create mode 100644 tests/math/testpimathvectort.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 68c51388..07693426 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,4 +17,4 @@ endmacro() # Concurrent tests pip_test(concurrent "") pip_test(math "") -pip_test(core "") +#pip_test(core "") diff --git a/tests/core/pistringTest.cpp b/tests/core/pistringTest.cpp deleted file mode 100644 index 900b2cfd..00000000 --- a/tests/core/pistringTest.cpp +++ /dev/null @@ -1,2978 +0,0 @@ -#include "gtest/gtest.h" -#include "pistring.h" -#include "pistringlist.h" - -using namespace std; - -TEST(PIString_Tests, operator_concatenation_pichar){ - PIString str1 = "AB C"; - const PIChar str2 = " "; - str1 += str2; - ASSERT_STREQ(str1, "AB C "); -} - -TEST(PIString_Tests, operator_concatenation_pichar_zero1){ - PIString str1 = ""; - const PIChar str2 = "D"; - str1 += str2; - ASSERT_STREQ(str1, "D"); -} - -TEST(PIString_Tests, operator_concatenation_pichar_zero2){ - PIString str1 = "AB C"; - const PIChar str2 = ""; - str1 += str2; - ASSERT_STREQ(str1, "AB C"); -} - -TEST(PIString_Tests, operator_concatenation_pichar_zero_zero){ - PIString str1; - const PIChar str2; - str1 += str2; - ASSERT_STREQ(str1, ""); -} - -TEST(PIString_Tests, operator_concatenation_char){ - PIString str1 = "AB C"; - const char *str2 = "D D "; - str1 += str2; - ASSERT_STREQ(str1, "AB CD D "); -} - -TEST(PIString_Tests, operator_concatenation_char_zero1){ - PIString str1 = ""; - const char *str2 = "D D "; - str1 += str2; - ASSERT_STREQ(str1, "D D "); -} - -TEST(PIString_Tests, operator_concatenation_wchar){ - PIString str1= "AB C"; - wchar_t str2[] = L"C"; - str1 += str2; - ASSERT_STREQ(str1, "AB CC"); -} - -TEST(PIString_Tests, operator_concatenation_wchar_zero1){ - PIString str1 = ""; - wchar_t str2[] = L"C"; - str1 += str2; - ASSERT_STREQ(str1, "C"); -} - -TEST(PIString_Tests, operator_concatenation_pistring){ - PIString str1 = "AB C"; - PIString str2 = " CD "; - str1 += str2; - ASSERT_STREQ(str1, "AB C CD "); -} - -TEST(PIString_Tests, operator_concatenation_pistring_zero1){ - PIString str1 = ""; - PIString str2 = "D DD"; - str1 += str2; - ASSERT_STREQ(str1, "D DD"); -} - -TEST(PIString_Tests, operator_concatenation_pistring_zero2){ - PIString str1 = "AB C"; - PIString str2 = ""; - str1 += str2; - ASSERT_STREQ(str1, "AB C"); -} - -TEST(PIString_Tests, operator_concatenation_pistring_zero_zero){ - PIString str1; - PIString str2; - str1 += str2; - ASSERT_STREQ(str1, ""); -} - -TEST(PIString_Tests, operator_concatenation_piByteArray){ - PIString str1 = "AB C"; - PIByteArray str2; - str2.append('g'); - str1 += str2; - ASSERT_STREQ(str1, "AB Cg"); -} - -TEST(PIString_Tests, operator_concatenation_piByteArray_zero1){ - PIString str1 = ""; - PIByteArray str2; - str2.append('0'); - str1 += str2; - ASSERT_STREQ(str1, "0"); -} - -TEST(PIString_Tests, operator_concatenation_piByteArray_zero2){ - PIString str1 = "AB C"; - PIByteArray str2; - str1 += str2; - ASSERT_STREQ(str1, "AB C"); -} - -TEST(PIString_Tests, operator_concatenation_piByteArray_zero_zero){ - PIString str1; - PIByteArray str2; - str1 += str2; - ASSERT_STREQ(str1, ""); -} - -TEST(PIString_Tests, construct_pistring){ - PIString str1 = "New"; - ASSERT_STREQ(str1, PIString("New")); -} - -TEST(PIString_Tests, construct_pichar){ - PIChar str1 = 'n'; - ASSERT_STREQ("n", PIString(str1)); -} - -TEST(PIString_Tests, construct_char){ - char str1 = 'n'; - ASSERT_STREQ("n", PIString(str1)); -} - -TEST(PIString_Tests, construct_chars){ - char str1[] = "mew"; - ASSERT_STREQ("mew", PIString(str1)); -} - -TEST(PIString_Tests, construct_wchar_t){ - wchar_t str1[] = L"gav"; - ASSERT_STREQ("gav", PIString(str1)); -} - -TEST(PIString_Tests, construct_pibyte_array){ - PIByteArray str1; - str1.append('m'); - ASSERT_STREQ("m", PIString(str1)); -} - -TEST(PIString_Tests, construct_pichar_size){ - PIChar *str1 = new PIChar[3]; - str1[0] = 'n'; - str1[1] = 'e'; - str1[2] = 'w'; - ASSERT_STREQ("new", PIString(str1, 3)); -} - -TEST(PIString_Tests, construct_char_size){ - char str1[] = "good"; - ASSERT_STREQ("good", PIString(str1, 4)); -} - -TEST(PIString_Tests, construct_char_len){ - char str1 = 'n'; - ASSERT_STREQ("nnn", PIString(3, str1)); -} - -TEST(PIString_Tests, construct_pichar_len){ - PIChar str1 = 'n'; - ASSERT_STREQ("nnnnn", PIString(5, str1)); -} - -TEST(PIString_Tests, operator_pointer){ - PIString str1 = "testing"; - const char *point = str1.operator const char *(); - ASSERT_STREQ("testing", point); -} - -TEST(PIString_Tests, operator_symbol){ - PIString str1 = "testing"; - PIChar symbo = "i"; - ASSERT_EQ(symbo, str1[4]); -} - -TEST(PIString_Tests, operator_compare_pistring_true){ - PIString str1 = "testing"; - PIString str2 = "testing"; - ASSERT_TRUE(str1 == str2); -} - -TEST(PIString_Tests, operator_compare_pistring_false){ - PIString str1 = "tes"; - PIString str2 = "testing"; - ASSERT_FALSE(str1 == str2); -} - -TEST(PIString_Tests, operator_compare_pichar_true){ - PIString str1 = "t"; - PIChar str2 = "t"; - ASSERT_TRUE(str1 == str2); -} - -TEST(PIString_Tests, operator_compare_pichar_false){ - PIString str1 = "t"; - PIChar str2 = "p"; - ASSERT_FALSE(str1 == str2); -} - -TEST(PIString_Tests, operator_compare_char_true){ - PIString str1 = "test"; - char str2[] = "test"; - ASSERT_TRUE(str1 == str2); -} - -TEST(PIString_Tests, operator_compare_char_false){ - PIString str1 = "t"; - char str2[] = "test"; - ASSERT_FALSE(str1 == str2); -} - -TEST(PIString_Tests, operator_encompare_pistring_false){ - PIString str1 = "testing"; - PIString str2 = "testing"; - ASSERT_FALSE(str1 != str2); -} - -TEST(PIString_Tests, operator_encompare_pistring_true){ - PIString str1 = "tes"; - PIString str2 = "testing"; - ASSERT_TRUE(str1 != str2); -} - -TEST(PIString_Tests, operator_encompare_pichar_false){ - PIString str1 = "t"; - PIChar str2 = "t"; - ASSERT_FALSE(str1 != str2); -} - -TEST(PIString_Tests, operator_encompare_pichar_true){ - PIString str1 = "t"; - PIChar str2 = "p"; - ASSERT_TRUE(str1 != str2); -} - -TEST(PIString_Tests, operator_encompare_char_false){ - PIString str1 = "test"; - char str2[] = "test"; - ASSERT_FALSE(str1 != str2); -} - -TEST(PIString_Tests, operator_encompare_char_true){ - PIString str1 = "t"; - char str2[] = "test"; - ASSERT_TRUE(str1 != str2); -} - -TEST(PIString_Tests, operator_less_pistring_true){ - PIString str1 = "testin"; - PIString str2 = "testing"; - ASSERT_TRUE(str1 < str2); -} - -TEST(PIString_Tests, operator_less_pistring_false){ - PIString str1 = "testing"; - PIString str2 = "testin"; - ASSERT_FALSE(str1 < str2); -} - -TEST(PIString_Tests, operator_less_pistring_false_equal){ - PIString str1 = "testing"; - PIString str2 = "testing"; - ASSERT_FALSE(str1 < str2); -} - -TEST(PIString_Tests, operator_less_pichar_true){ - PIString str1 = "a"; - PIChar str2 = "t"; - ASSERT_TRUE(str1 < str2); -} - -TEST(PIString_Tests, operator_less_pichar_false){ - PIString str1 = "t"; - PIChar str2 = "a"; - ASSERT_FALSE(str1 < str2); -} - -TEST(PIString_Tests, operator_less_pichar_false_equal){ - PIString str1 = "t"; - PIChar str2 = "t"; - ASSERT_FALSE(str1 < str2); -} - -TEST(PIString_Tests, operator_less_char_true){ - PIString str1 = "a"; - char str2[] = "t"; - ASSERT_TRUE(str1 < str2); -} - -TEST(PIString_Tests, operator_less_char_false){ - PIString str1 = "t"; - char str2[] = "a"; - ASSERT_FALSE(str1 < str2); -} - -TEST(PIString_Tests, operator_less_char_false_equal){ - PIString str1 = "t"; - char str2[] = "t"; - ASSERT_FALSE(str1 < str2); -} - -TEST(PIString_Tests, operator_more_pistring_true){ - PIString str1 = "testin"; - PIString str2 = "testing"; - ASSERT_TRUE(str2 > str1); -} - -TEST(PIString_Tests, operator_more_pistring_false){ - PIString str1 = "testing"; - PIString str2 = "testin"; - ASSERT_FALSE(str2 > str1); -} - -TEST(PIString_Tests, operator_more_pistring_false_equal){ - PIString str1 = "testing"; - PIString str2 = "testing"; - ASSERT_FALSE(str1 > str2); -} - -TEST(PIString_Tests, operator_more_pichar_true){ - PIString str1 = "t"; - PIChar str2 = "a"; - ASSERT_TRUE(str1 > str2); -} - -TEST(PIString_Tests, operator_more_pichar_false){ - PIString str1 = "a"; - PIChar str2 = "t"; - ASSERT_FALSE(str1 > str2); -} - -TEST(PIString_Tests, operator_more_pichar_false_equal){ - PIString str1 = "t"; - PIChar str2 = "t"; - ASSERT_FALSE(str1 > str2); -} - -TEST(PIString_Tests, operator_more_char_true){ - PIString str1 = "t"; - char str2[] = "a"; - ASSERT_TRUE(str1 > str2); -} - -TEST(PIString_Tests, operator_more_char_false){ - PIString str1 = "a"; - char str2[] = "t"; - ASSERT_FALSE(str1 > str2); -} - -TEST(PIString_Tests, operator_more_char_false_equal){ - PIString str1 = "t"; - char str2[] = "t"; - ASSERT_FALSE(str1 > str2); -} - -TEST(PIString_Tests, operator_less_eq_pistring_true){ - PIString str1 = "testin"; - PIString str2 = "testing"; - ASSERT_TRUE(str1 <= str2); -} - -TEST(PIString_Tests, operator_less_eq_pistring_false){ - PIString str1 = "testing"; - PIString str2 = "testin"; - ASSERT_FALSE(str1 <= str2); -} - -TEST(PIString_Tests, operator_less_pistring_true_equal){ - PIString str1 = "testing"; - PIString str2 = "testing"; - ASSERT_TRUE(str1 <= str2); -} - -TEST(PIString_Tests, operator_less_eq_pichar_true){ - PIString str1 = "a"; - PIChar str2 = "t"; - ASSERT_TRUE(str1 <= str2); -} - -TEST(PIString_Tests, operator_less_eq_pichar_false){ - PIString str1 = "t"; - PIChar str2 = "a"; - ASSERT_FALSE(str1 <= str2); -} - -TEST(PIString_Tests, operator_less_eq_pichar_true_equal){ - PIString str1 = "t"; - PIChar str2 = "t"; - ASSERT_TRUE(str1 <= str2); -} - -TEST(PIString_Tests, operator_less_eq_char_true){ - PIString str1 = "a"; - char str2[] = "t"; - ASSERT_TRUE(str1 <= str2); -} - -TEST(PIString_Tests, operator_less_eq_char_false){ - PIString str1 = "t"; - char str2[] = "a"; - ASSERT_FALSE(str1 <= str2); -} - -TEST(PIString_Tests, operator_less_eq_char_true_equal){ - PIString str1 = "t"; - char str2[] = "t"; - ASSERT_TRUE(str1 <= str2); -} - -TEST(PIString_Tests, operator_more_eq_pistring_true){ - PIString str1 = "testin"; - PIString str2 = "testing"; - ASSERT_TRUE(str2 >= str1); -} - -TEST(PIString_Tests, operator_more_eq_pistring_false){ - PIString str1 = "testing"; - PIString str2 = "testin"; - ASSERT_FALSE(str2 >= str1); -} - -TEST(PIString_Tests, operator_more_eq_pistring_true_equal){ - PIString str1 = "testing"; - PIString str2 = "testing"; - ASSERT_TRUE(str1 >= str2); -} - -TEST(PIString_Tests, operator_more_eq_pichar_true){ - PIString str1 = "t"; - PIChar str2 = "a"; - ASSERT_TRUE(str1 >= str2); -} - -TEST(PIString_Tests, operator_more_eq_pichar_false){ - PIString str1 = "a"; - PIChar str2 = "t"; - ASSERT_FALSE(str1 >= str2); -} - -TEST(PIString_Tests, operator_more_eq_pichar_true_equal){ - PIString str1 = "t"; - PIChar str2 = "t"; - ASSERT_TRUE(str1 >= str2); -} - -TEST(PIString_Tests, operator_more_eq_char_true){ - PIString str1 = "t"; - char str2[] = "a"; - ASSERT_TRUE(str1 >= str2); -} - -TEST(PIString_Tests, operator_more_eq_char_false){ - PIString str1 = "a"; - char str2[] = "t"; - ASSERT_FALSE(str1 >= str2); -} - -TEST(PIString_Tests, operator_more_eq_char_true_equal){ - PIString str1 = "t"; - char str2[] = "t"; - ASSERT_TRUE(str1 >= str2); -} - -TEST(PIString_Tests, operator_shift_pistring){ - PIString str1 = "shift"; - PIString str2 = " good"; - str1 << str2; - ASSERT_STREQ("shift good", str1); -} - -TEST(PIString_Tests, operator_shift_pichar){ - PIString str1 = "shif"; - PIChar str2 = 't'; - str1 << str2; - ASSERT_STREQ("shift", str1); -} - -TEST(PIString_Tests, operator_shift_char){ - PIString str1 = "shif"; - char str2[] = "t chat"; - str1 << str2; - ASSERT_STREQ("shift chat", str1); -} - -TEST(PIString_Tests, operator_shift_wchar_t){ - PIString str1 = "shif"; - wchar_t str2[] = L"t cc"; - str1 << str2; - ASSERT_STREQ("shift cc", str1); -} - -TEST(PIString_Tests, operator_shift_int){ - PIString str1 = "shift "; - int numb = -2147483648; - str1 << numb; - ASSERT_STREQ("shift -2147483648", str1); -} - -TEST(PIString_Tests, operator_shift_uint){ - PIString str1 = "shift "; - uint numb = 4294967295; - str1 << numb; - ASSERT_STREQ("shift 4294967295", str1); -} - -TEST(PIString_Tests, operator_shift_short){ - PIString str1 = "shift "; - short numb = -32768; - str1 << numb; - ASSERT_STREQ("shift -32768", str1); -} - -TEST(PIString_Tests, operator_shift_ushort){ - PIString str1 = "shift "; - ushort numb = 65535; - str1 << numb; - ASSERT_STREQ("shift 65535", str1); -} - -TEST(PIString_Tests, operator_shift_long){ - PIString str1 = "shift "; - long numb = -2147483648; - str1 << numb; - ASSERT_STREQ("shift -2147483648", str1); -} - -TEST(PIString_Tests, operator_shift_ulong){ - PIString str1 = "shift "; - ulong numb = 4294967295; - str1 << numb; - ASSERT_STREQ("shift 4294967295", str1); -} - -TEST(PIString_Tests, operator_shift_llong){ - PIString str1 = "shift "; - llong numb = -9223372036854775807; - str1 << numb; - ASSERT_STREQ("shift -9223372036854775807", str1); -} - -TEST(PIString_Tests, operator_shift_ullong){ - PIString str1 = "shift "; - ullong numb = 1844674407370955161; - str1 << numb; - ASSERT_STREQ("shift 1844674407370955161", str1); -} - -TEST(PIString_Tests, operator_shift_float){ - PIString str1 = "shift "; - float numb = -67.88999939; - str1 << numb; - ASSERT_STREQ("shift -67.88999939", str1); -} - -TEST(PIString_Tests, operator_shift_double){ - PIString str1 = "shift "; - double numb = 13.34300000; - str1 << numb; - - ASSERT_STREQ("shift 13.34300000", str1); -} - -TEST(PIString_Tests, prepend){ - PIString str1 = "idea"; - PIString str2 = "Good "; - str1.prepend(str2); - ASSERT_STREQ("Good idea", str1); -} - -TEST(PIString_Tests, append){ - PIString str1 = "Good"; - PIString str2 = " idea"; - str1.append(str2); - ASSERT_STREQ("Good idea", str1); -} - -TEST(PIString_Tests, mid){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("fo", str1.mid(10, 2)); -} - -TEST(PIString_Tests, mid_len_0){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("", str1.mid(10, 0)); -} - - -TEST(PIString_Tests, mid_start_more){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("", str1.mid(1000, 0)); -} - -TEST(PIString_Tests, mid_len_minus){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("for new project 144", str1.mid(10, -2)); -} - -TEST(PIString_Tests, mid_len_more){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("for new project 144", str1.mid(10, 100)); -} - -TEST(PIString_Tests, subString){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("for new project 144", str1.mid(10, 46)); -} - -TEST(PIString_Tests, mid_minus){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Good idea for new project 144", str1.mid(-10, 47)); -} - -TEST(PIString_Tests, subString_minus){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Go", str1.mid(-10, 12)); -} - -TEST(PIString_Tests, left){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Go", str1.left(2)); -} - -TEST(PIString_Tests, left_minus){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("", str1.left(-2)); -} - -TEST(PIString_Tests, right){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("44", str1.right(2)); -} - -TEST(PIString_Tests, right_minus){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("", str1.right(-2)); -} - -TEST(PIString_Tests, cutMid){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Good for new project 144", str1.cutMid(5,5)); -} - -TEST(PIString_Tests, cutMid_len_zero){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Good idea for new project 144", str1.cutMid(5,0)); -} - -TEST(PIString_Tests, cutMid_len_min){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Good ", str1.cutMid(5,-2)); -} - -TEST(PIString_Tests, cutMid_minus){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("ood idea for new project 144", str1.cutMid(-5, 6)); -} - -TEST(PIString_Tests, cutMid_zero){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Good idea for new project 144", str1.cutMid(-5, 5)); -} - -TEST(PIString_Tests, cutleft){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("od idea for new project 144", str1.cutLeft(2)); -} - -TEST(PIString_Tests, cutleft_minus){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Good idea for new project 144", str1.cutLeft(-2)); -} - -TEST(PIString_Tests, cutright){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Good idea for new project 1", str1.cutRight(2)); -} - -TEST(PIString_Tests, cutright_minus){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Good idea for new project 144", str1.cutRight(-2)); -} - -TEST(PIString_Tests, trim){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ("Good idea for new project 144", str1.trim()); -} - -TEST(PIString_Tests, trim_without){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Good idea for new project 144", str1.trim()); -} - -TEST(PIString_Tests, trim_link){ - PIString str1 = " Good idea for new project 144 "; - PIString &str2 = str1.trim(); - str1 = "link"; - ASSERT_STREQ("link", str2); -} - -TEST(PIString_Tests, trimmed){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ("Good idea for new project 144", str1.trimmed()); -} - -TEST(PIString_Tests, trimmed_without){ - PIString str1 = "Good idea for new project 144"; - ASSERT_STREQ("Good idea for new project 144", str1.trimmed()); -} - -TEST(PIString_Tests, replace){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ(" Good thin for new project 144 ", str1.replace(6,4, "thin")); -} - -TEST(PIString_Tests, replace_more){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ(" Good thin", str1.replace(6,100, "thin")); -} - -TEST(PIString_Tests, replace_link){ - PIString str1 = " Good idea for new project 144 "; - PIString &str2 = str1.replace(6,4, "thin"); - str1 = "link"; - ASSERT_STREQ("link", str2); -} - -TEST(PIString_Tests, replace_minus){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ("BAD idea for new project 144 ", str1.replace(0, 5, "BAD")); -} - -TEST(PIString_Tests, replace_zero){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ("thin Good idea for new project 144 ", str1.replace(0, 0, "thin")); -} - -TEST(PIString_Tests, replace_all){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ("BAD", str1.replaced(0, 100, "BAD")); -} - -TEST(PIString_Tests, replaced){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ(" Good thin for new project 144 ", str1.replaced(6,4, "thin")); -} - -TEST(PIString_Tests, replaced_minus){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ("BAD idea for new project 144 ", str1.replaced(0, 5, "BAD")); -} - -TEST(PIString_Tests, replaced_zero){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ("thin Good idea for new project 144 ", str1.replaced(0, 0, "thin")); -} - - -TEST(PIString_Tests, replaced_all){ - PIString str1 = " Good idea for new project 144 "; - ASSERT_STREQ("thin", str1.replaced(0, 100, "thin")); -} - -TEST(PIString_Tests, replace_str){ - PIString str1 = " Good idea for new Good project 144 "; - bool ok = 1; - str1.replace("Good", "bad", &ok); - ASSERT_STREQ(" bad idea for new Good project 144 ", str1); -} - -TEST(PIString_Tests, replace_str_link){ - PIString str1 = " Good idea for new Good project 144 "; - bool ok = 1; - PIString &str2 = str1.replace("Good", "bad", &ok); - str1 = "link"; - ASSERT_STREQ("link", str2); -} - -TEST(PIString_Tests, replace_str_zero){ - PIString str1 = " Good idea for new Good project 144 "; - bool ok = 1; - str1.replace("", "bad", &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, replace_str_true){ - PIString str1 = " Good idea for new Good project 144 "; - bool ok = 1; - str1.replace("Good", "bad", &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, replace_str_delete){ - PIString str1 = " Good idea for new Good project 144 "; - bool ok = 1; - str1.replace("Good", "", &ok); - ASSERT_STREQ(" idea for new Good project 144 ", str1); -} - -TEST(PIString_Tests, replaced_str){ - PIString str1 = " Good idea for new Good project 144 "; - bool ok = 1; - PIString str2 = str1.replaced("Good", "bad", &ok); - ASSERT_STREQ(" bad idea for new Good project 144 ", str2); -} - -TEST(PIString_Tests, replaced_str_zero){ - PIString str1 = " Good idea for new Good project 144 "; - bool ok = 1; - str1.replaced("", "bad", &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, replaced_str_true){ - PIString str1 = " Good idea for new Good project 144 "; - bool ok = 1; - str1.replaced("Good", "bad", &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, replaced_delete){ - PIString str1 = " Good idea for new Good project 144 "; - bool ok = 1; - PIString str2 = str1.replaced("Good", "", &ok); - ASSERT_STREQ(" idea for new Good project 144 ", str2); -} - -TEST(PIString_Tests, replaceall){ - PIString str1 = " Good idea for new Good project 144 "; - str1.replaceAll("Good", "bad"); - ASSERT_STREQ(" bad idea for new bad project 144 ", str1); -} - -TEST(PIString_Tests, replaceall_no_find){ - PIString str1 = " Good idea for new Good project 144 "; - str1.replaceAll("God", "bad"); - ASSERT_STREQ(" Good idea for new Good project 144 ", str1); -} - -TEST(PIString_Tests, replaceall_str){ - PIString str1 = " Good idea for new Good project 144 "; - PIString str2 = str1.replaceAll("Good", "bad"); - ASSERT_STREQ(" bad idea for new bad project 144 ", str2); -} - -TEST(PIString_Tests, replaceall_str_no_find){ - PIString str1 = " Good idea for new Good project 144 "; - PIString str2 = str1.replaceAll("God", "bad"); - ASSERT_STREQ(" Good idea for new Good project 144 ", str2); -} - -TEST(PIString_Tests, replaceall_link){ - PIString str1 = " Good idea for new Good project 144 "; - PIString &str2 = str1.replaceAll("Good", "bad"); - ASSERT_STREQ(" bad idea for new bad project 144 ", str2); -} - -TEST(PIString_Tests, replaceall_link_change){ - PIString str1 = " Good idea for new Good project 144 "; - PIString &str2 = str1.replaceAll("Good", "bad"); - str1 = "link"; - ASSERT_STREQ("link", str2); -} - -TEST(PIString_Tests, repeat){ - PIString str1 = "string "; - PIString str2 = str1.repeat(6); - ASSERT_STREQ("string string string string string string ", str2); -} - -TEST(PIString_Tests, repeat_zero){ - PIString str1 = "string "; - PIString str2 = str1.repeat(0); - ASSERT_STREQ("string ", str2); -} - -TEST(PIString_Tests, repeat_link){ - PIString str1 = "string "; - PIString &str2 = str1.repeat(6); - str1 = "link"; - ASSERT_STREQ("link", str2); -} - -TEST(PIString_Tests, repeated){ - PIString str1 = "string "; - str1.repeat(6); - ASSERT_STREQ("string string string string string string ", str1); -} - -TEST(PIString_Tests, repeated_zero){ - PIString str1 = "string "; - str1.repeat(0); - ASSERT_STREQ("string ", str1); -} - -TEST(PIString_Tests, insert_char){ - PIString str1 = "strng "; - char sym = 'i'; - str1.insert(3, sym); - ASSERT_STREQ("string ", str1); -} - -TEST(PIString_Tests, insert_pichar){ - PIString str1 = "strng "; - PIChar sym = 'i'; - str1.insert(3, sym); - ASSERT_STREQ("string ", str1); -} - -TEST(PIString_Tests, insert_pistring){ - PIString str1 = "string out"; - PIString str2 = " go"; - str1.insert(6, str2); - ASSERT_STREQ("string go out", str1); -} - -TEST(PIString_Tests, insert_chars){ - PIString str1 = "see boy"; - char str2[] = " big"; - str1.insert(3, str2); - ASSERT_STREQ("see big boy", str1); -} - -TEST(PIString_Tests, expandRightTo){ - PIString str1 = "see boy "; - PIChar symbol = "x"; - str1.expandRightTo(11, symbol); - ASSERT_STREQ("see boy xxx", str1); -} - -TEST(PIString_Tests, expandRightTo_null){ - PIString str1 = "see boy "; - PIChar symbol = "x"; - str1.expandRightTo(0, symbol); - ASSERT_STREQ("see boy ", str1); -} - -TEST(PIString_Tests, expandLeftTo){ - PIString str1 = " see boy"; - PIChar symbol = "x"; - str1.expandLeftTo(11, symbol); - ASSERT_STREQ("xxx see boy", str1); -} - -TEST(PIString_Tests, expandLeftTo_null){ - PIString str1 = "see boy "; - PIChar symbol = "x"; - str1.expandLeftTo(0, symbol); - ASSERT_STREQ("see boy ", str1); -} - -TEST(PIString_Tests, quote){ - PIString str1 = "see boy"; - PIChar symbol = " "; - str1.quote(symbol); - ASSERT_STREQ(" see boy ", str1); -} - -TEST(PIString_Tests, quote_link){ - PIString str1 = "see boy"; - PIChar symbol = " "; - PIString &str2 = str1.quote(symbol); - str1 = "link"; - ASSERT_STREQ("link", str2); -} - -TEST(PIString_Tests, quoted){ - PIString str1 = "see boy"; - PIChar symbol = " "; - PIString str2 = str1.quoted(symbol); - ASSERT_STREQ(" see boy ", str2); -} - -TEST(PIString_Tests, reverse){ - PIString str1 = "see boy"; - PIString &str2 = str1.reverse(); - ASSERT_STREQ("yob ees", str2); -} - -TEST(PIString_Tests, reverse_link){ - PIString str1 = "see boy"; - PIString &str2 = str1.reverse(); - str1 = "yes"; - ASSERT_STREQ("yes", str2); -} - -TEST(PIString_Tests, reversed){ - PIString str1 = "see boy"; - PIString str2 = str1.reversed(); - ASSERT_STREQ("yob ees", str2); -} - -TEST(PIString_Tests, elide){ - PIString str1 = "BMSTU is best university in space"; - PIString &str2 = str1.elide(8, 1); - ASSERT_STREQ("BMSTU ..", str2); -} - -TEST(PIString_Tests, elide_small){ - PIString str1 = "BMSTU is best university in space"; - PIString &str2 = str1.elide(2, 1); - ASSERT_STREQ("..", str2); -} - -TEST(PIString_Tests, elide_all){ - PIString str1 = "BMSTU is best university in space"; - PIString &str2 = str1.elide(100, 1); - ASSERT_STREQ("BMSTU is best university in space", str2); -} - -TEST(PIString_Tests, elide_link){ - PIString str1 = "BMSTU is best university in space"; - PIString &str2 = str1.elide(8, 1); - str1 = "space"; - ASSERT_STREQ("space", str2); -} - -TEST(PIString_Tests, elided){ - PIString str1 = "BMSTU is best university in space"; - PIString str2 = str1.elided(8, 1); - ASSERT_STREQ("BMSTU ..", str2); -} - -TEST(PIString_Tests, takemid){ - PIString str1 = "BMSTU is best university in space"; - PIString str2 = str1.takeMid(9, 4); - ASSERT_STREQ("best", str2); -} - -TEST(PIString_Tests, takeleft){ - PIString str1 = "BMSTU is best university in space"; - PIString str2 = str1.takeLeft(5); - ASSERT_STREQ("BMSTU", str2); -} - -TEST(PIString_Tests, takeright){ - PIString str1 = "BMSTU is best university in space"; - PIString str2 = str1.takeRight(5); - ASSERT_STREQ("space", str2); -} - -TEST(PIString_Tests, takesymbol){ - PIString str1 = "BMSTU is best university in space"; - PIString str2 = str1.takeSymbol(); - ASSERT_STREQ("B", str2); -} - -TEST(PIString_Tests, takesymbol_with_rubbish){ - PIString str1 = " \t \n \r BMSTU is best university in space"; - PIString str2 = str1.takeSymbol(); - ASSERT_STREQ("B", str2); -} - -TEST(PIString_Tests, takesymbol_without){ - PIString str1 = " \t \n \r "; - PIString str2 = str1.takeSymbol(); - ASSERT_STREQ("", str2); -} - -TEST(PIString_Tests, takeword){ - PIString str1 = "BMSTU is best university in space"; - PIString str2 = str1.takeWord(); - ASSERT_STREQ("BMSTU", str2); -} - -TEST(PIString_Tests, takeword_space){ - PIString str1 = " \r\n\tBMSTU is best university in space"; - PIString str2 = str1.takeWord(); - ASSERT_STREQ("BMSTU", str2); -} - -TEST(PIString_Tests, takeword_without_word){ - PIString str1 = " \r\n\t"; - PIString str2 = str1.takeWord(); - ASSERT_STREQ("", str2); -} - -TEST(PIString_Tests, takecword){ - PIString str1 = "_6 BMSTU is best university in space"; - PIString str2 = str1.takeCWord(); - ASSERT_STREQ("_6", str2); -} - -TEST(PIString_Tests, takecword_space){ - PIString str1 = " \t\r\n_6 BMSTU is best university in space"; - PIString str2 = str1.takeCWord(); - ASSERT_STREQ("_6", str2); -} - -TEST(PIString_Tests, takecword_space_w){ - PIString str1 = " \t\r\n BMSTU is best university in space"; - PIString str2 = str1.takeCWord(); - ASSERT_STREQ("BMSTU", str2); -} - -TEST(PIString_Tests, takecword_not_cword){ - PIString str1 = " \t\r\n "; - PIString str2 = str1.takeCWord(); - ASSERT_STREQ("", str2); -} - -TEST(PIString_Tests, takeline){ - PIString str1 = "BMSTU is best\n university in space"; - PIString str2 = str1.takeLine(); - ASSERT_STREQ("BMSTU is best", str2); -} - -TEST(PIString_Tests, takeline_without){ - PIString str1 = "BMSTU is best"; - PIString str2 = str1.takeLine(); - ASSERT_STREQ("", str2); -} - -TEST(PIString_Tests, takeline_first){ - PIString str1 = "\nBMSTU is best"; - PIString str2 = str1.takeLine(); - ASSERT_STREQ("", str2); -} - -TEST(PIString_Tests, takenumber){ - PIString str1 = "6.6"; - PIString str2 = str1.takeNumber(); - ASSERT_STREQ("6.6", str2); -} - -TEST(PIString_Tests, takenumber_sign){ - PIString str1 = "-66"; - PIString str2 = str1.takeNumber(); - ASSERT_STREQ("-66", str2); -} - -TEST(PIString_Tests, takenumber_suffix){ - PIString str1 = "66L"; - PIString str2 = str1.takeNumber(); - ASSERT_STREQ("66L", str2); -} - -TEST(PIString_Tests, takerange){ - PIString str1 = "BMSTU is best university in space"; - PIString str2 = str1.takeRange('B', 'i', ' '); - ASSERT_STREQ("MSTU is best un", str2); -} - -TEST(PIString_Tests, takerange_without_shield){ - PIString str1 = "BMSTU is best university in space"; - PIString str2 = str1.takeRange('B', 'i'); - ASSERT_STREQ("MSTU ", str2); -} - -TEST(PIString_Tests, takerange_space){ - PIString str1 = " \t\r\nBMSTU is best university in space"; - PIString str2 = str1.takeRange('B', 'i', ' '); - ASSERT_STREQ("MSTU is best un", str2); -} - -TEST(PIString_Tests, takerange_without_shield_space){ - PIString str1 = " \t\r\nBMSTU is best university in space"; - PIString str2 = str1.takeRange('B', 'i'); - ASSERT_STREQ("MSTU ", str2); -} - -TEST(PIString_Tests, inBrackets){ - PIString str1 = "BMSTU is (best) university in space"; - PIString str2 = str1.inBrackets('(', ')'); - ASSERT_STREQ("best", str2); -} - -TEST(PIString_Tests, inBrackets_end_start){ - PIString str1 = "BMSTU )is (best) university in space"; - PIString str2 = str1.inBrackets('(', ')'); - ASSERT_STREQ("best", str2); -} - -TEST(PIString_Tests, inBrackets_without){ - PIString str1 = "BMSTU )is (best) university in space"; - PIString str2 = str1.inBrackets('0', '1'); - ASSERT_STREQ("", str2); -} - -TEST(PIString_Tests, lenghtascii){ - PIString str1 = "BMSTU is (best) university in space"; - int size = str1.lengthAscii(); - ASSERT_EQ(35, size); -} - -TEST(PIString_Tests, data){ - PIString str1 = "BMSTU is (best) university in space\n"; - const char *data = str1.data(); - ASSERT_STREQ("BMSTU is (best) university in space\n", data); -} - -TEST(PIString_Tests, dataconsole){ - PIString str1 = "BMSTU is (best) university in space\n"; - const char *data = str1.dataConsole(); - ASSERT_STREQ("BMSTU is (best) university in space\n", data); -} - -TEST(PIString_Tests, dataUTF8){ - PIString str1 = "BMSTU is (best) university in space\n"; - const char *data = str1.dataUTF8(); - ASSERT_STREQ("BMSTU is (best) university in space\n", data); -} - -TEST(PIString_Tests, dataAScii){ - PIString str1 = "BMSTU is (best) university in space\n"; - const char *data = str1.dataAscii(); - ASSERT_STREQ("BMSTU is (best) university in space\n", data); -} - -TEST(PIString_Tests, hash){ - const PIString str1 = "B"; - uint h = str1.hash(); - ASSERT_EQ(3912571919, h); -} - -TEST(PIString_Tests, toByteArray){ - const PIString str1 = "C"; - PIByteArray h = str1.toByteArray(); - ASSERT_EQ(67, h.at(0)); -} - -TEST(PIString_Tests, toUTF8){ - const PIString str1 = "C"; - PIByteArray h = str1.toUTF8(); - ASSERT_EQ(67, h.at(0)); -} - -TEST(PIString_Tests, tocharset){ - const PIString str1 = "B"; - PIByteArray h = str1.toCharset("c"); - ASSERT_EQ(66, h.at(0)); -} - -TEST(PIString_Tests, toUTF8_empty){ - PIString str1; - str1.toUTF8(); - ASSERT_EQ(0, str1.size()); -} - -TEST(PIString_Tests, tocharset_empty){ - PIString str1 = ""; - str1.toCharset("c"); - ASSERT_EQ(0, str1.size()); -} - -TEST(PIString_Tests, split){ - PIString str1 = " mirrow best mirrow "; - PIStringList list = str1.split("best"); - ASSERT_STREQ(list[1], list[0]); -} - -TEST(PIString_Tests, split_sec){ - PIString str1 = " mirrow best detail "; - PIStringList list = str1.split("best"); - ASSERT_STREQ(" mirrow ", list[0]); - ASSERT_STREQ(list[1], " detail "); -} - -TEST(PIString_Tests, split_empty){ - PIString str1 = ""; - PIStringList list = str1.split("best"); - ASSERT_EQ(0, list.size()); -} - -TEST(PIString_Tests, split_empty_delim){ - PIString str1 = " mirrow best mirrow "; - PIStringList list = str1.split(""); - ASSERT_EQ(0, list.size()); -} - -TEST(PIString_Tests, split_not_delim){ - PIString str1 = " mirrow best mirrow "; - PIStringList list = str1.split("tr"); - ASSERT_STREQ(list[0], " mirrow best mirrow "); -} - -TEST(PIString_Tests, toUpperCase){ - PIString str1 = " miRrow "; - PIString str2 = str1.toUpperCase(); - ASSERT_STREQ(" MIRROW ", str2); -} - -TEST(PIString_Tests, toLowerCase){ - PIString str1 = " MIrROW "; - PIString str2 = str1.toLowerCase(); - ASSERT_STREQ(" mirrow ", str2); -} - -TEST(PIString_Tests, toNativeDecimalPoints){ - PIString str1 = "4546,878"; - PIString str2 = str1.toNativeDecimalPoints(); - ASSERT_STREQ("4546.878", str2); -} - -TEST(PIString_Tests, contains_char){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s = '\n'; - ASSERT_TRUE(str1.contains(s)); -} - -TEST(PIString_Tests, contains_char_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s = '0'; - ASSERT_FALSE(str1.contains(s)); -} - -TEST(PIString_Tests, contains_picahr){ - PIString str1 = "BMSTU is (best) university in space\n"; - PIChar s = 'i'; - ASSERT_TRUE(str1.contains(s)); -} - -TEST(PIString_Tests, contains_pichar_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - PIChar s = '0'; - ASSERT_FALSE(str1.contains(s)); -} - -TEST(PIString_Tests, contains_cahrs){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s[] = "BMSTU"; - ASSERT_TRUE(str1.contains(s)); -} - -TEST(PIString_Tests, contains_chars_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s[] = "out"; - ASSERT_FALSE(str1.contains(s)); -} - - -TEST(PIString_Tests, contains_pistring){ - PIString str1 = "BMSTU is (best) university in space\n"; - PIString s = "univer"; - ASSERT_TRUE(str1.contains(s)); -} - -TEST(PIString_Tests, contains_pistring_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - PIString s = "new"; - ASSERT_FALSE(str1.contains(s)); -} - -TEST(PIString_Tests, find_char){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s = 'i'; - ASSERT_EQ(6, str1.find(s)); -} - -TEST(PIString_Tests, find_char_start){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s = 'i'; - ASSERT_EQ(18, str1.find(s, 7)); -} - -TEST(PIString_Tests, find_char_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s = 'o'; - ASSERT_EQ(-1, str1.find(s)); -} - -TEST(PIString_Tests, find_chars){ - PIString str1 = "BMSTU is (best) university in space\n"; - char str2[] = "is"; - ASSERT_EQ(6, str1.find(str2)); -} - -TEST(PIString_Tests, find_chars_start){ - PIString str1 = "BMSTU is (best) university in space\n"; - char str2[] = "iv"; - ASSERT_EQ(18, str1.find(str2, 7)); -} - -TEST(PIString_Tests, find_chars_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s[] = "ouc"; - ASSERT_EQ(-1, str1.find(s)); -} - -TEST(PIString_Tests, find_pistring){ - PIString str1 = "BMSTU is (best) university in space\n"; - PIString str2 = "is"; - ASSERT_EQ(6, str1.find(str2)); -} - -TEST(PIString_Tests, find_pistring_start){ - PIString str1 = "BMSTU is (best) university in space\n"; - PIString str2 = "iv"; - ASSERT_EQ(18, str1.find(str2, 7)); -} - -TEST(PIString_Tests, find_pistring_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - PIString str2 = "ouc"; - ASSERT_EQ(-1, str1.find(str2)); -} - -TEST(PIString_Tests, find_last_char){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s = 'i'; - ASSERT_EQ(27, str1.findLast(s)); -} - -TEST(PIString_Tests, find_last_char_start){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s = 'i'; - ASSERT_EQ(27, str1.findLast(s, 20)); -} - -TEST(PIString_Tests, find_last_char_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - char s = 'o'; - ASSERT_EQ(-1, str1.findLast(s)); -} - -TEST(PIString_Tests, find_last_chars){ - PIString str1 = "BMSTU is (best) university in is space\n"; - char str2[] = "is"; - ASSERT_EQ(30, str1.findLast(str2)); -} - -TEST(PIString_Tests, find_last_chars_start){ - PIString str1 = "BMSTU is (best) university in iv space\n"; - char str2[] = "iv"; - ASSERT_EQ(30, str1.findLast(str2, 25)); -} - -TEST(PIString_Tests, find_last_chars_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - char str2[] = "ouc"; - ASSERT_EQ(-1, str1.findLast(str2)); -} - -TEST(PIString_Tests, find_last_pistring){ - PIString str1 = "BMSTU is (best) university in is space\n"; - PIString str2 = "is"; - ASSERT_EQ(30, str1.findLast(str2)); -} - -TEST(PIString_Tests, find_last_pistring_start){ - PIString str1 = "BMSTU is (best) university in iv space\n"; - PIString str2 = "iv"; - ASSERT_EQ(30, str1.findLast(str2, 10)); -} - -TEST(PIString_Tests, find_last_pistring_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - PIString str2 = "ouc"; - ASSERT_EQ(-1, str1.findLast(str2)); -} - -TEST(PIString_Tests, find_word){ - PIString str1 = "BMSTU is (best) university in iv space\n"; - PIString str2 = "university"; - ASSERT_EQ(16, str1.findWord(str2)); -} - -TEST(PIString_Tests, find_word_start){ - PIString str1 = "BMSTU is (best) university in iv space\n"; - PIString str2 = "university"; - ASSERT_EQ(16, str1.findWord(str2, 10)); -} - -TEST(PIString_Tests, find_word_space_before){ - PIString str1 = "BMSTU is (best) university in iv space\n"; - PIString str2 = " university"; - ASSERT_EQ(-1, str1.findWord(str2, 10)); -} - -TEST(PIString_Tests, find_word_space_after){ - PIString str1 = "BMSTU is (best) university in iv space\n"; - PIString str2 = "university "; - ASSERT_EQ(-1, str1.findWord(str2, 10)); -} - -TEST(PIString_Tests, find_word_digit_before){ - PIString str1 = "BMSTU is (best) _university_ in iv space\n"; - PIString str2 = "_university"; - ASSERT_EQ(-1, str1.findWord(str2, 10)); -} - -TEST(PIString_Tests, find_word_digit_after){ - PIString str1 = "BMSTU is (best) _university_ in iv space\n"; - PIString str2 = "university_"; - ASSERT_EQ(-1, str1.findWord(str2, 10)); -} - -TEST(PIString_Tests, find_word_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - PIString str2 = "university"; - ASSERT_EQ(-1, str1.findWord(str2, 37)); -} - -TEST(PIString_Tests, find_cword){ - PIString str1 = "BMSTU is (best) university in iv space\n"; - PIString str2 = "university"; - ASSERT_EQ(16, str1.findCWord(str2)); -} - -TEST(PIString_Tests, find_cword_start){ - PIString str1 = "BMSTU is (best) university in iv space\n"; - PIString str2 = "university"; - ASSERT_EQ(16, str1.findCWord(str2, 10)); -} - -TEST(PIString_Tests, find_cword_space_before){ - PIString str1 = "BMSTU is (best) university in iv space\n"; - PIString str2 = " university"; - ASSERT_EQ(15, str1.findCWord(str2, 10)); -} - -TEST(PIString_Tests, find_cword_space_after){ - PIString str1 = "BMSTU is (best) university in iv space\n"; - PIString str2 = "university "; - ASSERT_EQ(-1, str1.findCWord(str2, 10)); -} - -TEST(PIString_Tests, find_cword_digit_before){ - PIString str1 = "BMSTU is (best) _university_ in iv space\n"; - PIString str2 = "_university"; - ASSERT_EQ(-1, str1.findCWord(str2, 10)); -} - -TEST(PIString_Tests, find_cword_digit_after){ - PIString str1 = "BMSTU is (best) _university_ in iv space\n"; - PIString str2 = "university_"; - ASSERT_EQ(-1, str1.findCWord(str2, 10)); -} - -TEST(PIString_Tests, find_cword_false){ - PIString str1 = "BMSTU is (best) university in space\n"; - PIString str2 = "university"; - ASSERT_EQ(-1, str1.findCWord(str2, 37)); -} - -TEST(PIString_Tests, find_range){ - PIString str1 = "A very strong programmer wrote this code"; - PIChar start = "v"; - PIChar end = "g"; - ASSERT_EQ(3, str1.findRange(start, end, "n", 1)); -} - -TEST(PIString_Tests, find_range_len){ - PIString str1 = "A very strong programmer wrote this code"; - PIChar start = "v"; - PIChar end = "g"; - int len; - str1.findRange(start, end, "n", 1, &len); - ASSERT_EQ(14, len); -} - -TEST(PIString_Tests, find_range_len_without_shield){ - PIString str1 = "A very strong programmer wrote this code"; - PIChar start = "v"; - PIChar end = "g"; - int len; - str1.findRange(start, end, "/", 1, &len); - ASSERT_EQ(9, len); -} - -TEST(PIString_Tests, find_range_start){ - PIString str1 = "A very strong programmer wrote this code"; - PIChar start = "g"; - PIChar end = "o"; - int len; - str1.findRange(start, end, " ", 17, &len); - ASSERT_EQ(9, len); -} - -TEST(PIString_Tests, find_range_eq){ - PIString str1 = "A very strong programmer wrote this code"; - PIChar start = "v"; - PIChar end = "v"; - int len; - str1.findRange(start, end, "n", 1, &len); - ASSERT_EQ(0, len); -} - -TEST(PIString_Tests, find_range_trim){ - PIString str1 = " A very strong programmer wrote this code"; - PIChar start = "A"; - PIChar end = "v"; - int len; - ASSERT_EQ(2, str1.findRange(start, end, "n", 0, &len)); -} - -TEST(PIString_Tests, find_any){ - PIString str1 = " A very strong programmer wrote this code"; - PIString str2 = "doip"; - ASSERT_EQ(11, str1.findAny(str2, 0)); -} - -TEST(PIString_Tests, find_any_not){ - PIString str1 = " A very strong programmer wrote this code"; - PIString str2 = "q"; - ASSERT_EQ(-1, str1.findAny(str2, 0)); -} - -TEST(PIString_Tests, find_any_start){ - PIString str1 = " A very strong programmer wrote this code"; - PIString str2 = "doip"; - ASSERT_EQ(15, str1.findAny(str2, 12)); -} - -TEST(PIString_Tests, find_any_chars){ - PIString str1 = " A very strong programmer wrote this code"; - char str2[] = "doip"; - ASSERT_EQ(11, str1.findAny(str2, 0)); -} - -TEST(PIString_Tests, find_any_chars_not){ - PIString str1 = " A very strong programmer wrote this code"; - char str2[] = "q"; - ASSERT_EQ(-1, str1.findAny(str2, 0)); -} - -TEST(PIString_Tests, find_any_chars_start){ - PIString str1 = " A very strong programmer wrote this code"; - char str2[] = "doip"; - ASSERT_EQ(15, str1.findAny(str2, 12)); -} - -TEST(PIString_Tests, find_any_last){ - PIString str1 = " A very strong programmer wrote this code"; - PIString str2 = "doip"; - ASSERT_EQ(39, str1.findAnyLast(str2, 0)); -} - -TEST(PIString_Tests, find_any_last_not){ - PIString str1 = " A very strong programmer wrote this code"; - PIString str2 = "q"; - ASSERT_EQ(-1, str1.findAnyLast(str2, 0)); -} - -TEST(PIString_Tests, find_any_last_start){ - PIString str1 = " A very strong programmer wrote this code"; - PIString str2 = "doip"; - ASSERT_EQ(39, str1.findAnyLast(str2, 12)); -} - -TEST(PIString_Tests, find_any_last_chars){ - PIString str1 = " A very strong programmer wrote this code"; - char str2[] = "doip"; - ASSERT_EQ(39, str1.findAnyLast(str2, 0)); -} - -TEST(PIString_Tests, find_any_last_chars_not){ - PIString str1 = " A very strong programmer wrote this code"; - char str2[] = "q"; - ASSERT_EQ(-1, str1.findAnyLast(str2, 0)); -} - -TEST(PIString_Tests, find_any_last_chars_start){ - PIString str1 = " A very strong programmer wrote this code"; - char str2[] = "doip"; - ASSERT_EQ(39, str1.findAnyLast(str2, 12)); -} - -TEST(PIString_Tests, entries){ - PIString str1 = " A very strong programmer wrote this code"; - PIChar c = "A"; - ASSERT_EQ(1, str1.entries(c)); -} - -TEST(PIString_Tests, entries_char){ - PIString str1 = " A very strong programmer wrote this code"; - char c = 'A'; - ASSERT_EQ(1, str1.entries(c)); -} - -TEST(PIString_Tests, starts_with){ - PIString str1 = " A very strong programmer wrote this code"; - PIString str2 = " A very"; - ASSERT_TRUE(str1.startsWith(str2)); -} - -TEST(PIString_Tests, starts_with_false){ - PIString str1 = " A very strong programmer wrote this code"; - PIString str2 = " A veru"; - ASSERT_FALSE(str1.startsWith(str2)); -} - -TEST(PIString_Tests, ends_with){ - PIString str1 = " A very strong programmer wrote this code"; - PIString str2 = " code"; - ASSERT_TRUE(str1.endsWith(str2)); -} - -TEST(PIString_Tests, ends_with_false){ - PIString str1 = " A very strong programmer wrote this code"; - PIString str2 = "c code"; - ASSERT_FALSE(str1.endsWith(str2)); -} - -TEST(PIString_Tests, length){ - PIString str1 = " A very strong programmer wrote this code"; - ASSERT_EQ(41, str1.length()); -} - -TEST(PIString_Tests, is_empty_false){ - PIString str1 = " A very strong programmer wrote this code"; - ASSERT_FALSE(str1.isEmpty()); -} - -TEST(PIString_Tests, is_empty_true){ - PIString str1 = ""; - ASSERT_TRUE(str1.isEmpty()); -} - -TEST(PIString_Tests, to_bool){ - PIString str1 = "1"; - ASSERT_TRUE(str1.toBool()); -} - -TEST(PIString_Tests, to_bool_yes){ - PIString str1 = "yes"; - ASSERT_TRUE(str1.toBool()); -} - -TEST(PIString_Tests, to_bool_false){ - PIString str1 = "no"; - ASSERT_FALSE(str1.toBool()); -} - -TEST(PIString_Tests, to_bool_false_zero){ - PIString str1 = "0"; - ASSERT_FALSE(str1.toBool()); -} - -TEST(PIString_Tests, to_char){ - PIString str1 = "A very strong programmer wrote this code"; - ASSERT_EQ(65, str1.toChar()); -} - -TEST(PIString_Tests, to_short){ - PIString str1 = "133"; - ASSERT_EQ(133, str1.toShort(-1)); -} - -TEST(PIString_Tests, to_short_0x){ - PIString str1 = "0x133"; - ASSERT_EQ(307, str1.toShort(-1)); -} - -TEST(PIString_Tests, to_short_false){ - PIString str1 = "0x133"; - bool ok; - str1.toShort(1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_short_false_base){ - PIString str1 = "7"; - bool ok; - str1.toShort(6, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_short_neg){ - PIString str1 = "-7"; - bool ok; - ASSERT_EQ(-7, str1.toShort(10, &ok)); -} - -TEST(PIString_Tests, to_ushort){ - PIString str1 = "133.1"; - ASSERT_EQ(133, str1.toUShort(-1)); -} - -TEST(PIString_Tests, to_ushort_0x){ - PIString str1 = "0x133"; - ASSERT_EQ(307, str1.toUShort(-1)); -} - -TEST(PIString_Tests, to_ushort_false){ - PIString str1 = "0x133"; - bool ok; - str1.toUShort(1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_ushort_false_base){ - PIString str1 = "7"; - bool ok; - str1.toUShort(6, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_ushort_neg){ - PIString str1 = "-7"; - bool ok; - ASSERT_EQ(65529, str1.toUShort(10, &ok)); -} - -TEST(PIString_Tests, to_int){ - PIString str1 = "133"; - ASSERT_EQ(133, str1.toInt(-1)); -} - -TEST(PIString_Tests, to_int_0x){ - PIString str1 = "0x133"; - ASSERT_EQ(307, str1.toInt(-1)); -} - -TEST(PIString_Tests, to_int_false){ - PIString str1 = "0x133"; - bool ok; - str1.toInt(1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_int_false_base){ - PIString str1 = "7"; - bool ok; - str1.toInt(6, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_int_neg){ - PIString str1 = "-7"; - bool ok; - ASSERT_EQ(-7, str1.toShort(10, &ok)); -} - -TEST(PIString_Tests, to_uint){ - PIString str1 = "133.1"; - ASSERT_EQ(133, str1.toUInt(-1)); -} - -TEST(PIString_Tests, to_uint_0x){ - PIString str1 = "0x133"; - ASSERT_EQ(307, str1.toUInt(-1)); -} - -TEST(PIString_Tests, to_uint_false){ - PIString str1 = "0x133"; - bool ok; - str1.toUInt(1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_uint_false_base){ - PIString str1 = "7"; - bool ok; - str1.toUInt(6, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_uint_neg){ - PIString str1 = "-7"; - bool ok; - ASSERT_EQ(4294967289, str1.toUInt(10, &ok)); -} - -TEST(PIString_Tests, to_long){ - PIString str1 = "133"; - ASSERT_EQ(133, str1.toLong(-1)); -} - -TEST(PIString_Tests, to_long_0x){ - PIString str1 = "0x133"; - ASSERT_EQ(307, str1.toLong(-1)); -} - -TEST(PIString_Tests, to_long_false){ - PIString str1 = "0x133"; - bool ok; - str1.toLong(1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_long_false_base){ - PIString str1 = "7"; - bool ok; - str1.toLong(6, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_long_neg){ - PIString str1 = "-7"; - bool ok; - ASSERT_EQ(-7, str1.toLong(10, &ok)); -} - -TEST(PIString_Tests, to_ulong){ - PIString str1 = "133.1"; - ASSERT_EQ(133, str1.toULong(-1)); -} - -TEST(PIString_Tests, to_ulong_0x){ - PIString str1 = "0x133"; - ASSERT_EQ(307, str1.toULong(-1)); -} - -TEST(PIString_Tests, to_ulong_false){ - PIString str1 = "0x133"; - bool ok; - str1.toULong(1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_ulong_false_base){ - PIString str1 = "7"; - bool ok; - str1.toULong(6, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_ulong_neg){ - PIString str1 = "-7"; - bool ok; - ASSERT_EQ(4294967289, str1.toULong(10, &ok)); -} - -TEST(PIString_Tests, to_llong){ - PIString str1 = "133"; - ASSERT_EQ(133, str1.toLLong(-1)); -} - -TEST(PIString_Tests, to_llong_0x){ - PIString str1 = "0x133"; - ASSERT_EQ(307, str1.toLLong(-1)); -} - -TEST(PIString_Tests, to_llong_false){ - PIString str1 = "0x133"; - bool ok; - str1.toLLong(1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_llong_false_base){ - PIString str1 = "7"; - bool ok; - str1.toLLong(6, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_llong_neg){ - PIString str1 = "-7"; - bool ok; - ASSERT_EQ(-7, str1.toLLong(10, &ok)); -} - -TEST(PIString_Tests, to_ullong){ - PIString str1 = "133.1"; - ASSERT_EQ(133, str1.toULLong(-1)); -} - -TEST(PIString_Tests, to_ullong_0x){ - PIString str1 = "0x133"; - ASSERT_EQ(307, str1.toULLong(-1)); -} - -TEST(PIString_Tests, to_ullong_false){ - PIString str1 = "0x133"; - bool ok; - str1.toULLong(1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_ullong_false_base){ - PIString str1 = "7"; - bool ok; - str1.toULLong(6, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, to_float){ - PIString str1 = "-7765,54"; - float f = -7765.54; - ASSERT_EQ(f, str1.toFloat()); -} - -TEST(PIString_Tests, to_double){ - PIString str1 = "-7765,54656"; - double f = -7765.54656; - ASSERT_EQ(f, str1.toDouble()); -} - -TEST(PIString_Tests, to_ldouble){ - PIString str1 = "-7765,54656"; - ldouble f = -7765.54656; - ASSERT_EQ(f, str1.toLDouble()); -} - -TEST(PIString_Tests, setNumber){ - PIString str1 = " String"; - const short val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("131", str1); -} - -TEST(PIString_Tests, setNumber_zero){ - PIString str1 = " String"; - const short val = 0; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("0", str1); -} - -TEST(PIString_Tests, setNumber_false_base){ - PIString str1 = " String"; - const short val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, setNumber_true){ - PIString str1 = " String"; - const short val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, setNumber_false_base_str){ - PIString str1 = " String"; - const short val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_STREQ("", str1); -} - -TEST(PIString_Tests, setNumber_base_minus){ - PIString str1 = " String"; - const short val = -10; - bool ok; - str1.setNumber(val, 16, &ok); - ASSERT_STREQ("-A", str1); -} - -TEST(PIString_Tests, setNumber_ushort){ - PIString str1 = " String"; - const ushort val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("131", str1); -} - -TEST(PIString_Tests, setNumber_ushort_true){ - PIString str1 = " String"; - const ushort val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, setNumber_ushort_zero){ - PIString str1 = " String"; - const ushort val = 0; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("0", str1); -} - -TEST(PIString_Tests, setNumber_ushort_false_base){ - PIString str1 = " String"; - const ushort val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, setNumber_ushort_false_base_str){ - PIString str1 = " String"; - const ushort val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_STREQ("", str1); -} - -TEST(PIString_Tests, setNumber_ushort_base_minus){ - PIString str1 = " String"; - const ushort val = 10; - bool ok; - str1.setNumber(val, 16, &ok); - ASSERT_STREQ("A", str1); -} - -TEST(PIString_Tests, setNumber_int){ - PIString str1 = " String"; - const int val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("131", str1); -} - -TEST(PIString_Tests, setNumber_int_zero){ - PIString str1 = " String"; - const int val = 0; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("0", str1); -} - -TEST(PIString_Tests, setNumber_int_false_base){ - PIString str1 = " String"; - const int val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, setNumber_int_true){ - PIString str1 = " String"; - const int val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, setNumber_int_false_base_str){ - PIString str1 = " String"; - const int val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_STREQ("", str1); -} - -TEST(PIString_Tests, setNumber_int_base_minus){ - PIString str1 = " String"; - const int val = -10; - bool ok; - str1.setNumber(val, 16, &ok); - ASSERT_STREQ("-A", str1); -} - -TEST(PIString_Tests, setNumber_uint){ - PIString str1 = " String"; - const uint val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("131", str1); -} - -TEST(PIString_Tests, setNumber_uint_true){ - PIString str1 = " String"; - const uint val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, setNumber_uintt_zero){ - PIString str1 = " String"; - const uint val = 0; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("0", str1); -} - -TEST(PIString_Tests, setNumber_uint_false_base){ - PIString str1 = " String"; - const uint val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, setNumber_uint_false_base_str){ - PIString str1 = " String"; - const uint val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_STREQ("", str1); -} - -TEST(PIString_Tests, setNumber_uint_base_minus){ - PIString str1 = " String"; - const uint val = 10; - bool ok; - str1.setNumber(val, 16, &ok); - ASSERT_STREQ("A", str1); -} - -TEST(PIString_Tests, setNumber_long){ - PIString str1 = " String"; - const long val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("131", str1); -} - -TEST(PIString_Tests, setNumber_long_zero){ - PIString str1 = " String"; - const long val = 0; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("0", str1); -} - -TEST(PIString_Tests, setNumber_long_false_base){ - PIString str1 = " String"; - const long val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, setNumber_long_true){ - PIString str1 = " String"; - const long val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, setNumber_long_false_base_str){ - PIString str1 = " String"; - const long val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_STREQ("", str1); -} - -TEST(PIString_Tests, setNumber_long_base_minus){ - PIString str1 = " String"; - const long val = -10; - bool ok; - str1.setNumber(val, 16, &ok); - ASSERT_STREQ("-A", str1); -} - -TEST(PIString_Tests, setNumber_ulong){ - PIString str1 = " String"; - const ulong val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("131", str1); -} - -TEST(PIString_Tests, setNumber_ulong_true){ - PIString str1 = " String"; - const ulong val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, setNumber_ulong_zero){ - PIString str1 = " String"; - const ulong val = 0; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("0", str1); -} - -TEST(PIString_Tests, setNumber_ulong_false_base){ - PIString str1 = " String"; - const ulong val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, setNumber_ulong_false_base_str){ - PIString str1 = " String"; - const ulong val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_STREQ("", str1); -} - -TEST(PIString_Tests, setNumber_ulong_base_minus){ - PIString str1 = " String"; - const ulong val = 10; - bool ok; - str1.setNumber(val, 16, &ok); - ASSERT_STREQ("A", str1); -} - -TEST(PIString_Tests, setNumber_llong){ - PIString str1 = " String"; - const llong val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("131", str1); -} - -TEST(PIString_Tests, setNumber_llong_zero){ - PIString str1 = " String"; - const llong val = 0; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("0", str1); -} - -TEST(PIString_Tests, setNumber_llong_false_base){ - PIString str1 = " String"; - const llong val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, setNumber_llong_true){ - PIString str1 = " String"; - const llong val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, setNumber_llong_false_base_str){ - PIString str1 = " String"; - const llong val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_STREQ("", str1); -} - -TEST(PIString_Tests, setNumber_llong_base_minus){ - PIString str1 = " String"; - const llong val = -10; - bool ok; - str1.setNumber(val, 16, &ok); - ASSERT_STREQ("-A", str1); -} - -TEST(PIString_Tests, setNumber_ullong){ - PIString str1 = " String"; - const ullong val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("131", str1); -} - -TEST(PIString_Tests, setNumber_ullong_true){ - PIString str1 = " String"; - const ullong val = 131; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, setNumber_ullong_zero){ - PIString str1 = " String"; - const ullong val = 0; - bool ok; - str1.setNumber(val, 10, &ok); - ASSERT_STREQ("0", str1); -} - -TEST(PIString_Tests, setNumber_ullong_false_base){ - PIString str1 = " String"; - const ullong val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, setNumber_ullong_false_base_str){ - PIString str1 = " String"; - const ullong val = 131; - bool ok; - str1.setNumber(val, 1, &ok); - ASSERT_STREQ("", str1); -} - -TEST(PIString_Tests, setNumber_ullong_base_minus){ - PIString str1 = " String"; - const ullong val = 10; - bool ok; - str1.setNumber(val, 16, &ok); - ASSERT_STREQ("A", str1); -} - -TEST(PIString_Tests, setNumber_float){ - PIString str1 = " String"; - const float val = 131.132; - str1.setNumber(val, 'f', 3); - ASSERT_STREQ("131.132", str1); -} - -TEST(PIString_Tests, setNumber_double){ - PIString str1 = " String"; - const double val = 131.1324334; - str1.setNumber(val, 'f', 7); - ASSERT_STREQ("131.1324334", str1); -} - -TEST(PIString_Tests, setNumber_ldouble){ - PIString str1 = " String"; - const ldouble val = 131.1324334; - str1.setNumber(val, 'f', 7); - ASSERT_STREQ("131.1324334", str1); -} - -TEST(PIString_Tests, setReadableSize){ - PIString str1 = " ITELMA"; - ASSERT_STREQ("1023 B", str1.setReadableSize(1023)); -} - -TEST(PIString_Tests, setReadableSize_kb){ - PIString str1 = " ITELMA"; - ASSERT_STREQ("1.0 kB", str1.setReadableSize(1024)); -} - -TEST(PIString_Tests, setReadableSize_mb){ - PIString str1 = " ITELMA"; - ASSERT_STREQ("1.0 MB", str1.setReadableSize(1024*1024)); -} - -TEST(PIString_Tests, setReadableSize_gb){ - PIString str1 = " ITELMA"; - ASSERT_STREQ("1.0 GB", str1.setReadableSize(1024*1024*1024)); -} - -TEST(PIString_Tests, setReadableSize_tb){ - PIString str1 = " ITELMA"; - llong val = 99999999999999; - ASSERT_STREQ("90.9 TB", str1.setReadableSize(val)); -} - -TEST(PIString_Tests, setReadableSize_pb){ - PIString str1 = " ITELMA"; - llong val = 999999999999999999; - ASSERT_STREQ("888.1 PB", str1.setReadableSize(val)); -} - -TEST(PIString_Tests, fromNumber){ - PIString str1 = " String"; - const short val = 131; - bool ok; - ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumberr_zero){ - PIString str1 = " String"; - const short val = 0; - bool ok; - ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_false_base){ - PIString str1 = " String"; - const short val = 131; - bool ok; - str1.fromNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, fromNumber_true){ - PIString str1 = " String"; - const short val = 131; - bool ok; - str1.fromNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, fromNumber_false_base_str){ - PIString str1 = " String"; - const short val = 131; - bool ok; - ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); -} - -TEST(PIString_Tests, fromNumber_base_minus){ - PIString str1 = " String"; - const short val = -10; - bool ok; - ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); -} - -TEST(PIString_Tests, fromNumber_ushort){ - PIString str1 = " String"; - const ushort val = 131; - bool ok; - ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_ushort_true){ - PIString str1 = " String"; - const ushort val = 131; - bool ok; - str1.fromNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, fromNumber_ushort_zero){ - PIString str1 = " String"; - const ushort val = 0; - bool ok; - ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_ushort_false_base){ - PIString str1 = " String"; - const ushort val = 131; - bool ok; - str1.fromNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, fromNumber_ushort_false_base_str){ - PIString str1 = " String"; - const ushort val = 131; - bool ok; - ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); -} - -TEST(PIString_Tests, fromNumber_ushort_base_minus){ - PIString str1 = " String"; - const ushort val = 10; - bool ok; - ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); -} - -TEST(PIString_Tests, fromNumber_int){ - PIString str1 = " String"; - const int val = 131; - bool ok; - ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_int_zero){ - PIString str1 = " String"; - const int val = 0; - bool ok; - ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_int_false_base){ - PIString str1 = " String"; - const int val = 131; - bool ok; - str1.fromNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, fromNumber_int_true){ - PIString str1 = " String"; - const int val = 131; - bool ok; - str1.fromNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, fromNumber_int_false_base_str){ - PIString str1 = " String"; - const int val = 131; - bool ok; - ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); -} - -TEST(PIString_Tests, fromNumber_int_base_minus){ - PIString str1 = " String"; - const int val = -10; - bool ok; - ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); -} - -TEST(PIString_Tests, fromNumber_uint){ - PIString str1 = " String"; - const uint val = 131; - bool ok; - ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_uint_true){ - PIString str1 = " String"; - const uint val = 131; - bool ok; - str1.fromNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, fromNumber_uintt_zero){ - PIString str1 = " String"; - const uint val = 0; - bool ok; - ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_uint_false_base){ - PIString str1 = " String"; - const uint val = 131; - bool ok; - str1.fromNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, fromNumber_uint_false_base_str){ - PIString str1 = " String"; - const uint val = 131; - bool ok; - ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); -} - -TEST(PIString_Tests, fromNumber_uint_base_minus){ - PIString str1 = " String"; - const uint val = 10; - bool ok; - ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); -} - -TEST(PIString_Tests, fromNumber_long){ - PIString str1 = " String"; - const long val = 131; - bool ok; - ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_long_zero){ - PIString str1 = " String"; - const long val = 0; - bool ok; - ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_long_false_base){ - PIString str1 = " String"; - const long val = 131; - bool ok; - str1.fromNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, fromNumber_long_true){ - PIString str1 = " String"; - const long val = 131; - bool ok; - str1.fromNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, fromNumber_long_false_base_str){ - PIString str1 = " String"; - const long val = 131; - bool ok; - ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); -} - -TEST(PIString_Tests, fromNumber_long_base_minus){ - PIString str1 = " String"; - const long val = -10; - bool ok; - ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); -} - -TEST(PIString_Tests, fromNumber_ulong){ - PIString str1 = " String"; - const ulong val = 131; - bool ok; - ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_ulong_true){ - PIString str1 = " String"; - const ulong val = 131; - bool ok; - str1.fromNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, fromNumber_ulong_zero){ - PIString str1 = " String"; - const ulong val = 0; - bool ok; - ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_ulong_false_base){ - PIString str1 = " String"; - const ulong val = 131; - bool ok; - str1.fromNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, fromNumber_ulong_false_base_str){ - PIString str1 = " String"; - const ulong val = 131; - bool ok; - ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); -} - -TEST(PIString_Tests, fromNumber_ulong_base_minus){ - PIString str1 = " String"; - const ulong val = 10; - bool ok; - ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); -} - -TEST(PIString_Tests, fromNumber_llong){ - PIString str1 = " String"; - const llong val = 131; - bool ok; - ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_llong_zero){ - PIString str1 = " String"; - const llong val = 0; - bool ok; - ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_llong_false_base){ - PIString str1 = " String"; - const llong val = 131; - bool ok; - str1.fromNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, fromNumber_llong_true){ - PIString str1 = " String"; - const llong val = 131; - bool ok; - str1.fromNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, fromNumber_llong_false_base_str){ - PIString str1 = " String"; - const llong val = 131; - bool ok; - ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); -} - -TEST(PIString_Tests, fromNumber_llong_base_minus){ - PIString str1 = " String"; - const llong val = -10; - bool ok; - ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok)); -} - -TEST(PIString_Tests, fromNumber_ullong){ - PIString str1 = " String"; - const ullong val = 131; - bool ok; - ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_ullong_true){ - PIString str1 = " String"; - const ullong val = 131; - bool ok; - str1.fromNumber(val, 10, &ok); - ASSERT_TRUE(ok); -} - -TEST(PIString_Tests, fromNumber_ullong_zero){ - PIString str1 = " String"; - const ullong val = 0; - bool ok; - ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok)); -} - -TEST(PIString_Tests, fromNumber_ullong_false_base){ - PIString str1 = " String"; - const ullong val = 131; - bool ok; - str1.fromNumber(val, 1, &ok); - ASSERT_FALSE(ok); -} - -TEST(PIString_Tests, fromNumber_ullong_false_base_str){ - PIString str1 = " String"; - const ullong val = 131; - bool ok; - ASSERT_STREQ("", str1.fromNumber(val, 1, &ok)); -} - -TEST(PIString_Tests, fromNumber_ullong_base_minus){ - PIString str1 = " String"; - const ullong val = 10; - bool ok; - ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok)); -} - -TEST(PIString_Tests, fromNumber_float){ - PIString str1 = " String"; - const float val = 131.132; - ASSERT_STREQ("131.132", str1.fromNumber(val, 'f', 3)); -} - -TEST(PIString_Tests, fromNumber_double){ - PIString str1 = " String"; - const double val = 131.1324334; - ASSERT_STREQ("131.1324334", str1.fromNumber(val, 'f', 7)); -} - -TEST(PIString_Tests, fromNumber_ldouble){ - PIString str1 = " String"; - const ldouble val = 131.1324334; - ASSERT_STREQ("131.1324334", str1.fromNumber(val, 'f', 7)); -} - -TEST(PIString_Tests, fromBool_true){ - PIString str1; - bool val = true; - ASSERT_STREQ("true", str1.fromBool(val)); -} - -TEST(PIString_Tests, fromBool_false){ - PIString str1; - bool val = false; - ASSERT_STREQ("false", str1.fromBool(val)); -} - -TEST(PIString_Tests, from_Console){ - PIString str1; - char s[] = "true boy"; - ASSERT_STREQ("true boy", str1.fromConsole(s)); -} - -TEST(PIString_Tests, from_System){ - PIString str1; - char s[] = "true boy"; - ASSERT_STREQ("true boy", str1.fromSystem(s)); -} - -TEST(PIString_Tests, from_UTF8){ - PIString str1; - char s[] = "true boy"; - ASSERT_STREQ("true boy", str1.fromUTF8(s)); -} - -TEST(PIString_Tests, from_UTF8_ba){ - PIString str1; - PIByteArray s; - s.append('t'); - s.append('r'); - s.append('u'); - s.append('e'); - ASSERT_STREQ("true", str1.fromUTF8(s)); -} - -TEST(PIString_Tests, from_Ascii){ - PIString str1; - char s[] = "true boy"; - ASSERT_STREQ("true boy", str1.fromAscii(s)); -} - -TEST(PIString_Tests, from_Codepage){ - PIString str1 = "Nul"; - char s[] = "true"; - char c[] = "utf8"; - PIString str2 = str1.fromCodepage(s, c); - ASSERT_STREQ("true", str2); -} - -TEST(PIString_Tests, ReadableSize){ - PIString str1 = " ITELMA"; - ASSERT_STREQ("1023 B", str1.readableSize(1023)); -} - -TEST(PIString_Tests, readableSize_kb){ - PIString str1 = " ITELMA"; - ASSERT_STREQ("1.0 kB", str1.readableSize(1024)); -} - -TEST(PIString_Tests, readableSize_mb){ - PIString str1 = " ITELMA"; - ASSERT_STREQ("1.0 MB", str1.readableSize(1024*1024)); -} - -TEST(PIString_Tests, readableSize_gb){ - PIString str1 = " ITELMA"; - ASSERT_STREQ("1.0 GB", str1.readableSize(1024*1024*1024)); -} - -TEST(PIString_Tests, readableSize_tb){ - PIString str1 = " ITELMA"; - llong val = 99999999999999; - ASSERT_STREQ("90.9 TB", str1.readableSize(val)); -} - -TEST(PIString_Tests, readableSize_pb){ - PIString str1 = " ITELMA"; - llong val = 999999999999999999; - ASSERT_STREQ("888.1 PB", str1.readableSize(val)); -} - -TEST(PIString_Tests, removeAll_char){ - PIString str1 = "A very strong programmer wrote this code"; - char v = ' '; - ASSERT_STREQ("Averystrongprogrammerwrotethiscode", str1.removeAll(v)); -} - -TEST(PIString_Tests, removeAll_pistring){ - PIString str1 = "A very strong programmer wrote this code"; - PIString v = "very strong "; - ASSERT_STREQ("A programmer wrote this code", str1.removeAll(v)); -} - -TEST(PIString_Tests, operator_ba_pstr){ - PIString str1 = '1'; - PIByteArray s; - s << str1; - ASSERT_STREQ("010000003100", s.toHex()); -} - -TEST(PIString_Tests, operator_pstr_ba){ - PIString str1 = "1"; - PIByteArray s; - s.append('t'); - s.append('r'); - s.append('u'); - s.append('e'); - str1 << s; - ASSERT_STREQ("1true", str1); -} - -TEST(PIString_Tests, operator_plus_pstr_pstr){ - PIString str1 = "first "; - PIString str2 = "second"; - ASSERT_STREQ("first second", str1 + str2); -} - -TEST(PIString_Tests, operator_plus_pstr_chars){ - PIString str1 = "first "; - char str2[] = "second"; - ASSERT_STREQ("first second", str1 + str2); -} - -TEST(PIString_Tests, operator_plus_chars_pstr){ - PIString str1 = "first"; - char str2[] = "second "; - ASSERT_STREQ("second first", str2 + str1); -} - -TEST(PIString_Tests, versionCompare2){ //дописать - PIString str1 = "first"; - PIString str2 = "first 1"; - versionCompare(str1, str2, 0); - ASSERT_EQ(898448032, piHash(str1)); -} - -TEST(PIString_Tests, versionNormalize2){ - PIString str1 = "first second"; - ASSERT_STREQ("0.0_first second", versionNormalize(str1)); -} - -TEST(PIString_Tests, piHash){ - PIString str1 = "first"; - ASSERT_EQ(898448032, piHash(str1)); -} - -TEST(PIString_Tests, piSwap){ - PIString str1 = "first"; - PIString str2 = "second"; - piSwap(str1, str2); - ASSERT_STREQ("first", str2); -} - -TEST(PIString_Tests, piSwap_sec){ - PIString str1 = "first"; - PIString str2 = "second"; - piSwap(str1, str2); - ASSERT_STREQ("second", str1); -} - - - - - - - - - - - diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index fb7109fb..f2c8cc10 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -111,18 +111,18 @@ TEST(PIMathMatrix_Test, swapCols) { double a1[3], a2[3], a3[3]; double b1[3], b2[3], b3[3]; vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; matrix1 = origMatr.identity(3, 3); matrix1.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; matrix1.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; matrix1.setCol(2, vector); for(int i = 0; i < 3; i++) { a1[i] = matrix1.element(i, 0); @@ -146,18 +146,18 @@ TEST(PIMathMatrix_Test, swapRows) { double a1[3], a2[3], a3[3]; double b1[3], b2[3], b3[3]; vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; matrix1 = origMatr.identity(3, 3); matrix1.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; matrix1.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; matrix1.setCol(2, vector); for(int i = 0; i < 3; i++) { a1[i] = matrix1.element(0, i); @@ -339,17 +339,17 @@ TEST(PIMathMatrix_Test, determinantIfSquare) { PIMathMatrix matrix(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; matrix.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; matrix.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; matrix.setCol(2, vector); d = matrix.determinant(); ASSERT_DOUBLE_EQ(d, i); @@ -367,17 +367,17 @@ TEST(PIMathMatrix_Test, trace) { double i = 9.0; PIMathVector vector; vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; matrix.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; matrix.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; matrix.setCol(2, vector); t = matrix.trace(); ASSERT_DOUBLE_EQ(t, i); @@ -395,17 +395,17 @@ TEST(PIMathMatrix_Test, toUpperTriangular) { int i; PIMathVector vector; vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; matrix.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; matrix.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; matrix.setCol(2, vector); d1 = matrix.determinant(); matrix.toUpperTriangular(); @@ -424,17 +424,17 @@ TEST(PIMathMatrix_Test, invert) { PIMathMatrix matrix4(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; matrix1.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; matrix1.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; matrix1.setCol(2, vector); d1 = matrix1.determinant(); matrix2 = matrix1; @@ -452,17 +452,17 @@ TEST(PIMathMatrix_Test, inverted) { PIMathMatrix matrix4(3, 3, 0.0); PIMathVector vector; vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; matrix1.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; matrix1.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; matrix1.setCol(2, vector); d1 = matrix1.determinant(); matrix2 = matrix1; @@ -480,18 +480,17 @@ TEST(PIMathMatrix_Test, transposed) { PIMathMatrix matrix3; PIMathVector vector; vector.resize(3, 3.0); - vector.at(0) = 3.0; - vector.at(1) = 6.0; - vector.at(2) = 8.0; - matrix1 = origMatr.identity(3, 3); + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; matrix1.setCol(0, vector); - vector.at(0) = 2.0; - vector.at(1) = 1.0; - vector.at(2) = 4.0; + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; matrix1.setCol(1, vector); - vector.at(0) = 6.0; - vector.at(1) = 2.0; - vector.at(2) = 5.0; + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; matrix1.setCol(2, vector); d1 = matrix1.determinant(); matrix2 = matrix1.transposed(); diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index df96a01c..ff9afc8c 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -106,9 +106,9 @@ TEST(PIMathMatrixT_Test, row) { TEST(PIMathMatrixT_Test, setCol) { PIMathMatrixT matr; PIMathVectorT vect; - vect.at(0) = 1.0; - vect.at(1) = 3.0; - vect.at(2) = 5.0; + vect[0] = 1.0; + vect[1] = 3.0; + vect[2] = 5.0; uint g = 1; matr.setCol(g, vect); for(uint i = 0; i < vect.size(); i++) { @@ -122,9 +122,9 @@ TEST(PIMathMatrixT_Test, setCol) { TEST(PIMathMatrixT_Test, setRow) { PIMathMatrixT matr; PIMathVectorT vect; - vect.at(0) = 1.0; - vect.at(1) = 3.0; - vect.at(2) = 5.0; + vect[0] = 1.0; + vect[1] = 3.0; + vect[2] = 5.0; uint g = 1; matr.setRow(g, vect); for(uint i = 0; i < vect.size(); i++) { diff --git a/tests/math/testpimathvector.cpp b/tests/math/testpimathvector.cpp new file mode 100644 index 00000000..b12ba4bb --- /dev/null +++ b/tests/math/testpimathvector.cpp @@ -0,0 +1,364 @@ +#include "gtest/gtest.h" +#include "pimathvector.h" + +bool cmpVectorWithValue(PIMathVector vector, double val, int num) { + bool b = true; + for(int i = 0; i < num; i++) { + if(vector[i] != val) { + b = false; + } + } + return b; +} + +TEST(PIMathVector_Test, size) { + auto vector = PIMathVector(3u); + ASSERT_TRUE(vector.size() == 3u); +} + +TEST(PIMathVector_Test, resize) { + PIMathVector vector; + vector.resize(4u, 5.0); + ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, vector.size())); +} + +TEST(PIMathVector_Test, resized) { + PIMathVector vector; + vector.resized(4u, 5.0); + ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, vector.size())); +} + +TEST(PIMathVector_Test, fill) { + PIMathVector vector(3u); + vector.fill(5.0); + ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3u)); +} + +TEST(PIMathVector_Test, moveVal) { + PIMathVector vector(3u); + vector.fill(5.0); + vector.move(5.0); + ASSERT_TRUE(cmpVectorWithValue(vector, 10.0, 3u)); +} + +TEST(PIMathVector_Test, moveVec) { + PIMathVector vector(3u); + PIMathVector vec(3u); + vector.fill(5.0); + vec.fill(7.0); + vector.move(vec); + ASSERT_TRUE(cmpVectorWithValue(vector, 12.0, 3u)); +} + +TEST(PIMathVector_Test, swap) { + PIMathVector vector(3u); + double a[3]; + vector[0] = 5.12; + vector[1] = 3.32; + vector[2] = 7.12; + a[0] = vector[0]; + a[1] = vector[1]; + a[2] = vector[2]; + vector.swap(0u, 1u); + ASSERT_TRUE((a[0] == vector[1]) && (a[1] == vector[0]) && (a[2] == vector[2])); +} + +TEST(PIMathVector_Test, lengthSqr) { + PIMathVector vector(3u); + vector.fill(1.0); + ASSERT_EQ(3.0, vector.lengthSqr()); +} + +TEST(PIMathVector_Test, length) { + PIMathVector vector(3u); + vector.fill(1.0); + ASSERT_DOUBLE_EQ(sqrt(3.0), vector.length()); +} + +TEST(PIMathVector_Test, manhattanLength) { + PIMathVector vector(3u); + vector.fill(5.0); + ASSERT_DOUBLE_EQ(15.0, vector.manhattanLength()); +} + +TEST(PIMathVector_Test, angleCos) { + PIMathVector vector(3u); + PIMathVector vec(3u); + vector[0] = 1.0; + vector[1] = 1.0; + vec[1] = 1.0; + ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleCos(vec)); +} + +TEST(PIMathVector_Test, angleSin) { + PIMathVector vector(3u); + PIMathVector vec(3u); + vector[0] = 1.0; + vector[1] = 1.0; + vec[1] = 1.0; + ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleSin(vec)); +} + +TEST(PIMathVector_Test, angleRad) { + PIMathVector vector(3u); + PIMathVector vec(3u); + vector[0] = 1.0; + vector[1] = 1.0; + vec[1] = 1.0; + ASSERT_DOUBLE_EQ(0.78539816339744830961566084581988, vector.angleRad(vec)); +} + +TEST(PIMathVector_Test, angleDeg) { + PIMathVector vector(3u); + PIMathVector vec(3u); + vector[0] = 1.0; + vector[1] = 1.0; + vec[1] = 1.0; + ASSERT_DOUBLE_EQ(45.0, vector.angleDeg(vec)); +} + +TEST(PIMathVector_Test, projection) { + PIMathVector vector(2u); + PIMathVector vec(2u); + vec[0] = 1.0; + vector[0] = 1.0; + vector[1] = 1.0; + auto vecProj = vector.projection(vec); + ASSERT_TRUE(vecProj == vec); +} + +TEST(PIMathVector_Test, normalize) { + PIMathVector vector(3u); + vector.fill(5.0); + ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), 5.0 / sqrt(75.0), 3u)); +} + +TEST(PIMathVector_Test, normalized) { + PIMathVector vector(3u); + vector.fill(5.0); + ASSERT_TRUE(cmpVectorWithValue(vector.normalized(), 5.0 / sqrt(75.0), 3u)); +} + +TEST(PIMathVector_Test, isNullTrue) { + PIMathVector vector(3u); + ASSERT_TRUE(vector.isNull()); +} + +TEST(PIMathVector_Test, isNullFalse) { + PIMathVector vector(3u); + vector[0] = 6.273; + ASSERT_FALSE(vector.isNull()); +} + +TEST(PIMathVector_Test, isValidTrue) { + PIMathVector vector(3u); + ASSERT_TRUE(vector.isValid()); +} + +TEST(PIMathVector_Test, isValidFalse) { + PIMathVector vector; + ASSERT_FALSE(vector.isValid()); +} + +TEST(PIMathVector_Test, isOrthoTrue) { + PIMathVector vector(2u); + PIMathVector vect(2u); + vector[0] = 2.0; + vect[1] = 1.0; + ASSERT_TRUE(vector.isOrtho(vect)); +} + +TEST(PIMathVector_Test, isOrthoFalse) { + PIMathVector vector(2u); + PIMathVector vect(2u); + vector[0] = 2.0; + vect[0] = 5.0; + vect[1] = 1.0; + ASSERT_FALSE(vector.isOrtho(vect)); +} + +TEST(PIMathVector_Test, at) { + PIMathVector vector(3u); + vector.fill(5.5); + for(uint i = 0; i < 3u; i++){ + if(vector.at(i) != 5.5){ + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathVector_Test, operator_AssignmentValue) { + PIMathVector vector(3u); + vector = 3.0; + ASSERT_TRUE(cmpVectorWithValue(vector, 3.0, 3)); +} + +TEST(PIMathVector_Test, operator_AssignmentVector) { + PIMathVector vector(3u); + PIMathVector vec(3u); + vec = 5.0; + vector = vec; + ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3)); +} + +TEST(PIMathVector_Test, operator_EqualTrue) { + PIMathVector vector(2u); + PIMathVector vec(2u); + vector[0] = 5.12; + vector[1] = 7.34; + vec[0] = 5.12; + vec[1] = 7.34; + ASSERT_TRUE(vec == vector); +} + +TEST(PIMathVector_Test, operator_EqualFalse) { + PIMathVector vector(2u); + PIMathVector vec(2u); + vector[0] = 5.12; + vector[1] = 7.34; + vec[0] = 5.12; + vec[1] = 0.34; + ASSERT_FALSE(vec == vector); +} + +TEST(PIMathVector_Test, operator_Not_EqualTrue) { + PIMathVector vector(2u); + PIMathVector vec(2u); + vector[0] = 5.12; + vector[1] = 7.34; + vec[0] = 5.12; + vec[1] = 0.34; + ASSERT_TRUE(vec != vector); +} + +TEST(PIMathVector_Test, operator_Not_EqualFalse) { + PIMathVector vector(2u); + PIMathVector vec(2u); + vector[0] = 5.12; + vector[1] = 7.34; + vec[0] = 5.12; + vec[1] = 7.34; + ASSERT_FALSE(vec != vector); +} + +TEST(PIMathVector_Test, operator_Addition_Aassignment) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1.fill(6.0); + vector2.fill(1.72); + vector1 += vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, 7.72, 3)); +} + +TEST(PIMathVector_Test, operator_Subtraction_Assignment) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1.fill(6.0); + vector2.fill(1.72); + vector1 -= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, 4.28, 3)); +} + +TEST(PIMathVector_Test, operator_Multiplication_AssignmentValue) { + PIMathVector vector1(3u); + vector1.fill(6.0); + vector1 *= 4.0; + ASSERT_TRUE(cmpVectorWithValue(vector1, 24.0, 3)); +} + +TEST(PIMathVector_Test, operator_Multiplication_AssignmentVector) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1.fill(6.0); + vector2.fill(1.72); + vector1 *= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, 10.32, 3)); +} + +TEST(PIMathVector_Test, operator_Division_AssignmentValue) { + PIMathVector vector1(3u); + vector1.fill(6.0); + vector1 /= 4.0; + ASSERT_TRUE(cmpVectorWithValue(vector1, 1.5, 3)); +} + +TEST(PIMathVector_Test, operator_Division_AssignmentVector) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1.fill(6.0); + vector2.fill(1.5); + vector1 /= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, 4.0, 3)); +} + +TEST(PIMathVector_Test, operator_Addition) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1.fill(6.0); + vector2.fill(1.72); + ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, 7.72, 3)); +} + +TEST(PIMathVector_Test, operator_Subtraction) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1.fill(6.0); + vector2.fill(1.72); + ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, 4.28, 3)); +} + +TEST(PIMathVector_Test, operator_MultiplicationValue) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1.fill(6.0); + ASSERT_TRUE(cmpVectorWithValue(vector1 * 4.0, 24.0, 3)); +} + +TEST(PIMathVector_Test, operator_MultiplicationVector1) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1.fill(6.0); + vector2.fill(1.72); + ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, 3)); +} + +TEST(PIMathVector_Test, operator_MultiplicationVector2) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1[0] = 1.0; + vector2[1] = 1.0; + ASSERT_TRUE(((vector1 * vector2)[0] == 0.0) && ((vector1 * vector2)[1] == 0.0) && ((vector1 * vector2)[2] == 1.0)); +} + +TEST(PIMathVector_Test, operator_DivisionVector) { + PIMathVector vector1(3u); + vector1.fill(6.0); + ASSERT_TRUE(cmpVectorWithValue(vector1 / 4.0, 1.5, 3)); +} + +TEST(PIMathVector_Test, operator_MultiplVect) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1.fill(6.0); + vector2.fill(5.0); + ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, 30.0, 3)); +} + +TEST(PIMathVector_Test, operator_absDotProduct) { + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vector1.fill(6.0); + vector2.fill(5.0); + ASSERT_TRUE(90.0 == (vector1 ^ vector2)); +} + +TEST(PIMathVector_Test, distToLine) { + PIMathVector vect(3u); + PIMathVector vector1(3u); + PIMathVector vector2(3u); + vect.fill(6.0); + vector1[0] = 1.0; + vector2[1] = -1.0; + ASSERT_DOUBLE_EQ(vect.distToLine(vector1, vector2), sqrt(2.0)/2.0); +} diff --git a/tests/math/testpimathvectort.cpp b/tests/math/testpimathvectort.cpp new file mode 100644 index 00000000..82125a28 --- /dev/null +++ b/tests/math/testpimathvectort.cpp @@ -0,0 +1,427 @@ +#include "gtest/gtest.h" +#include "pimathvector.h" +#include "pimathmatrix.h" + +const uint size = 3u; + +bool cmpVectorWithValue(PIMathVectorT vector, double val, int num) { + bool b = true; + for(int i = 0; i < num; i++) { + if(vector[i] != val) { + b = false; + } + } + return b; +} + +TEST(PIMathVectorT_Test, size) { + PIMathVectorT vector; + ASSERT_TRUE(vector.size() == 3u); +} + +TEST(PIMathVectorT_Test, fill) { + PIMathVectorT vector; + ASSERT_TRUE(cmpVectorWithValue(vector.fill(5.0), 5.0, 3)); +} + +TEST(PIMathVectorT_Test, set) { + PIMathVectorT vector; + PIMathVectorT vector1; + PIMathVectorT vector2; + ASSERT_TRUE(cmpVectorWithValue(vector.set(vector1.fill(5.0), vector2.fill(3.0)), -2.0, 3)); +} + +TEST(PIMathVectorT_Test, MoveVal) { + PIMathVectorT vector; + ASSERT_TRUE(cmpVectorWithValue(vector.move(4.0), 4.0, 3)); +} + +TEST(PIMathVectorT_Test, MoveVector) { + PIMathVectorT vector; + PIMathVectorT vector1; + ASSERT_TRUE(cmpVectorWithValue(vector.move(vector1.fill(5.0)), 5.0, 3)); +} + +TEST(PIMathVectorT_Test, lengthSqr) { + PIMathVectorT vector; + vector.fill(1.0); + ASSERT_EQ(3.0, vector.lengthSqr()); +} + +TEST(PIMathVectorT_Test, length) { + PIMathVectorT vector; + vector.fill(1.0); + ASSERT_DOUBLE_EQ(sqrt(3.0), vector.length()); +} + +TEST(PIMathVectorT_Test, manhattanLength) { + PIMathVectorT vector; + vector.fill(5.0); + ASSERT_DOUBLE_EQ(15.0, vector.manhattanLength()); +} + +TEST(PIMathVectorT_Test, angleCos) { + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = 1.0; + vector[1] = 1.0; + vec[1] = 1.0; + ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleCos(vec)); +} + +TEST(PIMathVectorT_Test, angleSin) { + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = 1.0; + vector[1] = 1.0; + vec[1] = 1.0; + ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleSin(vec)); +} + +TEST(PIMathVectorT_Test, angleRad) { + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = 1.0; + vector[1] = 1.0; + vec[1] = 1.0; + ASSERT_DOUBLE_EQ(0.78539816339744830961566084581988, vector.angleRad(vec)); +} + +TEST(PIMathVectorT_Test, angleDeg) { + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = 1.0; + vector[1] = 1.0; + vec[1] = 1.0; + ASSERT_DOUBLE_EQ(45.0, vector.angleDeg(vec)); +} + +TEST(PIMathVectorT_Test, angleElevation) { + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = 1.0; + vector[1] = 1.0; + vec[1] = 1.0; + ASSERT_DOUBLE_EQ(-45.0, vector.angleElevation(vec)); +} + +TEST(PIMathVectorT_Test, projection) { + PIMathVectorT vector; + PIMathVectorT vec; + vec[0] = 1.0; + vector[0] = 1.0; + vector[1] = 1.0; + auto vecProj = vector.projection(vec); + ASSERT_TRUE(vecProj == vec); +} + +TEST(PIMathVectorT_Test, normalize) { + PIMathVectorT vector; + vector.fill(5.0); + ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), 5.0 / sqrt(75.0), 3u)); +} + +TEST(PIMathVectorT_Test, normalized) { + PIMathVectorT vector; + vector.fill(5.0); + ASSERT_TRUE(cmpVectorWithValue(vector.normalized(), 5.0 / sqrt(75.0), 3u)); +} + +TEST(PIMathVectorT_Test, cross1) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(1.72); + ASSERT_TRUE(cmpVectorWithValue(vector1.cross(vector2), 0.0, 3)); +} + +TEST(PIMathVectorT_Test, cross2) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1[0] = 1.0; + vector2[1] = 1.0; + ASSERT_TRUE(((vector1 * vector2)[0] == 0.0) && ((vector1 * vector2)[1] == 0.0) && ((vector1 * vector2)[2] == 1.0)); +} + +TEST(PIMathVectorT_Test, dot) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(5.0); + ASSERT_EQ(vector1.dot(vector2), 90.0); +} + +TEST(PIMathVectorT_Test, isNullTrue) { + PIMathVectorT vector; + ASSERT_TRUE(vector.isNull()); +} + +TEST(PIMathVectorT_Test, isNullFalse) { + PIMathVectorT vector; + vector[0] = 6.273; + ASSERT_FALSE(vector.isNull()); +} + +TEST(PIMathVectorT_Test, isOrthoTrue) { + PIMathVectorT vector; + PIMathVectorT vect; + vector[0] = 2.0; + vect[1] = 1.0; + ASSERT_TRUE(vector.isOrtho(vect)); +} + +TEST(PIMathVectorT_Test, isOrthoFalse) { + PIMathVectorT vector; + PIMathVectorT vect; + vector[0] = 2.0; + vect[0] = 5.0; + vect[1] = 1.0; + ASSERT_FALSE(vector.isOrtho(vect)); +} + +TEST(PIMathVectorT_Test, at) { + PIMathVectorT vector; + vector.fill(5.5); + for(uint i = 0; i < 3u; i++){ + if(vector.at(i) != 5.5){ + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathVectorT_Test, operator_AssignmentValue) { + PIMathVectorT vector; + vector = 3.0; + ASSERT_TRUE(cmpVectorWithValue(vector, 3.0, 3)); +} + +TEST(PIMathVectorT_Test, operator_AssignmentVector) { + PIMathVectorT vector; + PIMathVectorT vec; + vec = 5.0; + vector = vec; + ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3)); +} + +TEST(PIMathVectorT_Test, operator_EqualTrue) { + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = 5.12; + vector[1] = 7.34; + vec[0] = 5.12; + vec[1] = 7.34; + ASSERT_TRUE(vec == vector); +} + +TEST(PIMathVectorT_Test, operator_EqualFalse) { + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = 5.12; + vector[1] = 7.34; + vec[0] = 5.12; + vec[1] = 0.34; + ASSERT_FALSE(vec == vector); +} + +TEST(PIMathVectorT_Test, operator_Not_EqualTrue) { + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = 5.12; + vector[1] = 7.34; + vec[0] = 5.12; + vec[1] = 0.34; + ASSERT_TRUE(vec != vector); +} + +TEST(PIMathVectorT_Test, operator_Not_EqualFalse) { + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = 5.12; + vector[1] = 7.34; + vec[0] = 5.12; + vec[1] = 7.34; + ASSERT_FALSE(vec != vector); +} + +TEST(PIMathVectorT_Test, operator_Addition_Aassignment) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(1.72); + vector1 += vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, 7.72, 3)); +} + +TEST(PIMathVectorT_Test, operator_Subtraction_Assignment) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(1.72); + vector1 -= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, 4.28, 3)); +} + +TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentValue) { + PIMathVectorT vector1; + vector1.fill(6.0); + vector1 *= 4.0; + ASSERT_TRUE(cmpVectorWithValue(vector1, 24.0, 3)); +} + +TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentVector) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(1.72); + vector1 *= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, 10.32, 3)); +} + +TEST(PIMathVectorT_Test, operator_Division_AssignmentValue) { + PIMathVectorT vector1; + vector1.fill(6.0); + vector1 /= 4.0; + ASSERT_TRUE(cmpVectorWithValue(vector1, 1.5, 3)); +} + +TEST(PIMathVectorT_Test, operator_Division_AssignmentVector) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(1.5); + vector1 /= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, 4.0, 3)); +} + +TEST(PIMathVectorT_Test, operator_Addition) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(1.72); + ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, 7.72, 3)); +} + +TEST(PIMathVectorT_Test, operator_Subtraction) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(1.72); + ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, 4.28, 3)); +} + +TEST(PIMathVectorT_Test, operator_MultiplicationValue) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + ASSERT_TRUE(cmpVectorWithValue(vector1 * 4.0, 24.0, 3)); +} + +TEST(PIMathVectorT_Test, operator_MultiplicationVector1) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(1.72); + ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, 3)); +} + +TEST(PIMathVectorT_Test, operator_MultiplicationVector2) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1[0] = 1.0; + vector2[1] = 1.0; + ASSERT_TRUE(((vector1 * vector2)[0] == 0.0) && ((vector1 * vector2)[1] == 0.0) && ((vector1 * vector2)[2] == 1.0)); +} + +TEST(PIMathVectorT_Test, operator_DivisionVal) { + PIMathVectorT vector1; + vector1.fill(6.0); + ASSERT_TRUE(cmpVectorWithValue(vector1 / 4.0, 1.5, 3)); +} + +TEST(PIMathVectorT_Test, operator_DivisionVector) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(4.0); + ASSERT_TRUE(cmpVectorWithValue(vector1 / vector2, 1.5, 3)); +} + +TEST(PIMathVectorT_Test, operator_MultiplVect) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(5.0); + ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, 30.0, 3)); +} + +TEST(PIMathVectorT_Test, operator_absDotProduct) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(5.0); + ASSERT_TRUE(90.0 == (vector1 ^ vector2)); +} + +TEST(PIMathVectorT_Test, transposed) { + PIMathVectorT vector; + vector.fill(6.0); + auto matrix = vector.transposed(); + for(int i = 0; i < size; i++){ + if(matrix[0][i] != 6.0) + { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathVectorT_Test, filled) { + auto vector = PIMathVectorT::filled(6.0); + ASSERT_TRUE(cmpVectorWithValue(vector, 6.0, 3)); +} + +TEST(PIMathVectorT_Test, distToLine) { + PIMathVectorT vect; + PIMathVectorT vector1; + PIMathVectorT vector2; + vect.fill(6.0); + vector1[0] = 1.0; + vector2[1] = -1.0; + ASSERT_DOUBLE_EQ(vect.distToLine(vector1, vector2), sqrt(2.0)/2.0); +} + +TEST(PIMathVectorT_Test, turnTo) { + PIMathVectorT vect; + vect.fill(6.0); + auto vector = vect.turnTo<2u, double>(); + ASSERT_TRUE((vector.size() == 2) && (vector.size() == 2)); +} + +TEST(PIMathVectorT_Test, LogicalOrTrue) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(6.0); + vector2.fill(1.72); + ASSERT_TRUE(vector1 || vector2); +} + +TEST(PIMathVectorT_Test, LogicalOrFalse) { + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1[0] = 1.0; + vector2[1] = 1.0; + ASSERT_FALSE(vector1 || vector2); +} + +TEST(PIMathVectorT_Test, sqrt) { + PIMathVectorT vector1; + vector1.fill(36.0); + ASSERT_TRUE(cmpVectorWithValue(sqrt(vector1), 6.0, 3u)); +} + +TEST(PIMathVectorT_Test, sqr) { + PIMathVectorT vector1; + vector1.fill(6.0); + ASSERT_TRUE(cmpVectorWithValue(sqr(vector1), 36.0, 3u)); +} -- 2.43.0 From 0a458d28f35fe5e29192c8be172ce283082dadf7 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Thu, 17 Sep 2020 17:09:07 +0300 Subject: [PATCH 02/14] bug fixes in pimathvector.h --- libs/main/math/pimathvector.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index 7c4a9b41..190da7a9 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -37,7 +37,6 @@ template class PIP_EXPORT PIMathVectorT { typedef PIMathVectorT _CVector; static_assert(std::is_arithmetic::value, "Type must be arithmetic"); - static_assert(Size > 0, "Size count must be > 0"); public: PIMathVectorT() {resize();} PIMathVectorT(const PIVector & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];} @@ -64,14 +63,13 @@ public: bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;} bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);} - Type & at(uint index) {return c[index];} - Type at(uint index) const {return c[index];} + const Type & at(uint index) {return c[index];} Type & operator [](uint index) {return c[index];} Type operator [](uint index) const {return c[index];} _CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;} _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;} - bool operator !=(const _CVector & v) const {return !(*this == c);} + bool operator !=(const _CVector & v) const {return !(*this == v);} void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} @@ -191,14 +189,13 @@ public: bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);} - Type & at(uint index) {return c[index];} - Type at(uint index) const {return c[index];} + const Type & at(uint index) {return c[index];} Type & operator [](uint index) {return c[index];} Type operator [](uint index) const {return c[index];} _CVector & operator =(const _CVector & v) {c = v.c; return *this;} _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;} - bool operator !=(const _CVector & v) const {return !(*this == c);} + bool operator !=(const _CVector & v) const {return !(*this == v);} void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} @@ -210,7 +207,7 @@ public: _CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} _CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;} _CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;} - _CVector operator *(const _CVector & v) const {if (c.size() < 3) return _CVector(); _CVector tv; tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} + _CVector operator *(const _CVector & v) const {if ((c.size() != 3) && (v.size() != 3)) return _CVector(); _CVector tv(3); tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} _CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} @@ -220,8 +217,6 @@ public: return f; } - template - PIMathVector turnTo(uint size) const {PIMathVector tv; uint sz = piMin(c.size(), size); for (uint i = 0; i < sz; ++i) tv[i] = c[i]; return tv;} PIVector toVector() const {return c;} inline Type * data() {return c.data();} -- 2.43.0 From 2b73c106e7589eb6a0359a96749e0a880b822fbf Mon Sep 17 00:00:00 2001 From: maakshishov Date: Thu, 17 Sep 2020 18:28:28 +0300 Subject: [PATCH 03/14] bug fixes in pimathmatrix and begin of docs in pimathvector --- libs/main/math/pimathmatrix.h | 4 ++-- libs/main/math/pimathvector.h | 37 ++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 897fe6ae..7d42fbc3 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -92,7 +92,7 @@ public: /** * @brief Constructor that calls the private resize method * - * @return identitied matrix of type PIMathMatrixT + * @return resized matrix of type PIMathMatrixT */ PIMathMatrixT() { resize(Rows, Cols); } @@ -100,7 +100,7 @@ public: * @brief Constructor that calls the private resize method * * @param val is the PIVector with which the matrix is ​​filled - * @return identitied matrix of type PIMathMatrixT + * @return resized matrix of type PIMathMatrixT */ PIMathMatrixT(const PIVector &val) { resize(Rows, Cols); diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index 190da7a9..09659fb2 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -1,5 +1,7 @@ /*! \file pimathvector.h * \brief PIMathVector + * + * This file declare math vector class, which performs various vector operations */ /* PIP - Platform Independent Primitives @@ -33,15 +35,44 @@ class PIMathMatrixT; #define PIMV_FOR(v, s) for (uint v = s; v < Size; ++v) +//! \brief A class that works with vector operations, the input data of which are size and the data type of the vector +//! @tparam Size number of matrix elements +//! @tparam Type is the data type of the vector. There are can be basic C++ language data and different classes where the arithmetic operators(=, +=, -=, *=, /=, ==, !=, +, -, *, /) +//! of the C++ language are implemented template class PIP_EXPORT PIMathVectorT { typedef PIMathVectorT _CVector; static_assert(std::is_arithmetic::value, "Type must be arithmetic"); public: + /** + * @brief Constructor that calls the private resize method + * + * @return resized vector of type PIMathMatrixT + */ PIMathVectorT() {resize();} + + /** + * @brief Constructor that fills a vector "PIMathVectorT" with the values ​​of another vector "PIVector" + * + * @tparam val vector of type PIVector which is identified PIMathVectorT + * @return vector of type PIMathVectorT with values ​​of vector val + */ PIMathVectorT(const PIVector & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];} + + /** + * @brief Constructor that fills a vector "PIMathVectorT" with the subtraction of two vectors + * + * @tparam st vector of type _CVector + * @tparam fn vector of type _CVector + * @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st" + */ PIMathVectorT(const _CVector & st, const _CVector & fn) {resize(); set(st, fn);} + /** + * @brief Method which returns size of the vector + * + * @return type uint shows number of elements in this vector + */ uint size() const {return Size;} _CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} _CVector & set(const _CVector & st, const _CVector & fn) {PIMV_FOR(i, 0) c[i] = fn[i] - st[i]; return *this;} @@ -69,7 +100,7 @@ public: _CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;} _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;} - bool operator !=(const _CVector & v) const {return !(*this == v);} + bool operator !=(const _CVector & v) const {return !(*this == v);} void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} @@ -195,7 +226,7 @@ public: _CVector & operator =(const _CVector & v) {c = v.c; return *this;} _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;} - bool operator !=(const _CVector & v) const {return !(*this == v);} + bool operator !=(const _CVector & v) const {return !(*this == v);} void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} @@ -207,7 +238,7 @@ public: _CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} _CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;} _CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;} - _CVector operator *(const _CVector & v) const {if ((c.size() != 3) && (v.size() != 3)) return _CVector(); _CVector tv(3); tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} + _CVector operator *(const _CVector & v) const {if ((c.size() != 3) && (v.size() != 3)) return _CVector(); _CVector tv(3); tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} _CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} -- 2.43.0 From f9ea27a46ad9f0c68f9d49aadac5ad44bb6401a6 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Thu, 17 Sep 2020 19:17:03 +0300 Subject: [PATCH 04/14] another part of docs for PIMathVector --- libs/main/math/pimathvector.h | 95 +++++++++++++++++++++++++++++++++-- tests/CMakeLists.txt | 1 - 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index 09659fb2..49b60540 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -1,4 +1,4 @@ -/*! \file pimathvector.h + /*! \file pimathvector.h * \brief PIMathVector * * This file declare math vector class, which performs various vector operations @@ -54,7 +54,7 @@ public: /** * @brief Constructor that fills a vector "PIMathVectorT" with the values ​​of another vector "PIVector" * - * @tparam val vector of type PIVector which is identified PIMathVectorT + * @param val vector of type PIVector which is identified PIMathVectorT * @return vector of type PIMathVectorT with values ​​of vector val */ PIMathVectorT(const PIVector & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];} @@ -62,8 +62,7 @@ public: /** * @brief Constructor that fills a vector "PIMathVectorT" with the subtraction of two vectors * - * @tparam st vector of type _CVector - * @tparam fn vector of type _CVector + * @param st vector of type PIMathVect * @param fn vector of type PIMathVectorT * @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st" */ PIMathVectorT(const _CVector & st, const _CVector & fn) {resize(); set(st, fn);} @@ -74,18 +73,106 @@ public: * @return type uint shows number of elements in this vector */ uint size() const {return Size;} + + /** + * @brief Method that fills a vector with a value + * + * @param v value of which the vector is filled + * @return vector of type PIMathVector filled with "v" + */ _CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} + + /** + * @brief Method that fills a vector with the subtraction of two vectors + * + * @param st vector of type PIMathVectorT + * @param fn vector of type PIMathVectorT + * @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st" + */ _CVector & set(const _CVector & st, const _CVector & fn) {PIMV_FOR(i, 0) c[i] = fn[i] - st[i]; return *this;} + + /** + * @brief Method that fills a vector with the adittion of vector value and "v" + * + * @param v value of which the vector is filled + * @return vector of type PIMathVectorT with values adittion of vector value and "v" + */ _CVector & move(const Type & v) {PIMV_FOR(i, 0) c[i] += v; return *this;} + + /** + * @brief Method that fills a vector with the adittion of vector value and "v" + * + * @param v vector of type PIMathVectorT + * @return vector of type PIMathVectorT with values adittion of vector value and "v" + */ _CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;} + + /** + * @brief Method that returns sum of the squares of all elements of the vector + * + * @return value equal to the sum of the squares of all elements of the vector + */ Type lengthSqr() const {Type tv(0); PIMV_FOR(i, 0) tv += (c[i] * c[i]); return tv;} + + /** + * @brief Method that returns length of a vector + * + * @return value equal to length of a vector + */ Type length() const {return sqrt(lengthSqr());} + + /** + * @brief Method that returns the sum of the absolute values ​​of all vector values + * + * @return value equal sum of the absolute values ​​of all vector values + */ Type manhattanLength() const {Type tv(0); PIMV_FOR(i, 0) tv += fabs(c[i]); return tv;} + + /** + * @brief method that returns the cos of the current vector and vector "v" + * + * @param v vector of type PIMathVectorT + * @return cos value of the angle between two vectors + */ Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} + + /** + * @brief method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements + * + * @param v vector of type PIMathVectorT * @return sin value of the angle between two vector + */ Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} + + /** + * @brief method that returns the angle between of the current vector and vector "v" in Rad + * + * @param v vector of type PIMathVectorT + * @return value of the angle between two vectors in Rad + */ Type angleRad(const _CVector & v) const {return acos(angleCos(v));} + + /** + * @brief method that returns the angle between of the current vector and vector "v" in Deg + * + * @param v vector of type PIMathVectorT + * @return value of the angle between two vectors in Deg + */ Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));} + + /** + * @brief method that returns the angle elevation between of the current vector and vector "v" in Deg + * + * @param v vector of type PIMathVectorT + * @return value of the angle elevation between two vectors in Deg + */ Type angleElevation(const _CVector & v) const {_CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;} + + /** + * @brief method that returns a vector equal to the projection of the current vector onto the vector "v" + * + * @param v vector of type PIMathVectorT + * @return vector of type PIMathVectorT equal to the projection of the current vector onto the vector "v" + */ _CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} _CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;} _CVector normalized() {_CVector tv(*this); tv.normalize(); return tv;} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 07693426..bebb15da 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,4 +17,3 @@ endmacro() # Concurrent tests pip_test(concurrent "") pip_test(math "") -#pip_test(core "") -- 2.43.0 From b60c147f9da20e730e98f1949e50c0934bd0c482 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Fri, 18 Sep 2020 16:41:57 +0300 Subject: [PATCH 05/14] PIMathVectorT docs update --- libs/main/math/pimathvector.h | 78 +++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index 49b60540..deefee7b 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -1,4 +1,4 @@ - /*! \file pimathvector.h + /*! \file pimathvector.h * \brief PIMathVector * * This file declare math vector class, which performs various vector operations @@ -129,7 +129,7 @@ public: Type manhattanLength() const {Type tv(0); PIMV_FOR(i, 0) tv += fabs(c[i]); return tv;} /** - * @brief method that returns the cos of the current vector and vector "v" + * @brief Method that returns the cos of the current vector and vector "v" * * @param v vector of type PIMathVectorT * @return cos value of the angle between two vectors @@ -137,14 +137,14 @@ public: Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} /** - * @brief method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements + * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements * * @param v vector of type PIMathVectorT * @return sin value of the angle between two vector */ Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} /** - * @brief method that returns the angle between of the current vector and vector "v" in Rad + * @brief Method that returns the angle between of the current vector and vector "v" in Rad * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Rad @@ -152,7 +152,7 @@ public: Type angleRad(const _CVector & v) const {return acos(angleCos(v));} /** - * @brief method that returns the angle between of the current vector and vector "v" in Deg + * @brief Method that returns the angle between of the current vector and vector "v" in Deg * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Deg @@ -160,29 +160,89 @@ public: Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));} /** - * @brief method that returns the angle elevation between of the current vector and vector "v" in Deg - * + * @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg + * * @param v vector of type PIMathVectorT * @return value of the angle elevation between two vectors in Deg */ Type angleElevation(const _CVector & v) const {_CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;} /** - * @brief method that returns a vector equal to the projection of the current vector onto the vector "v" + * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v" * * @param v vector of type PIMathVectorT * @return vector of type PIMathVectorT equal to the projection of the current vector onto the vector "v" */ _CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} + + /** + * @brief Method that returns a normalized vector + * + * @return copy of normalized vector of type PIMathVectorT + */ _CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;} + + /** + * @brief Method that returns a normalized vector + * + * @return normalized vector of type PIMathVectorT + */ _CVector normalized() {_CVector tv(*this); tv.normalize(); return tv;} + + /** + * @brief Method that returns a vector equal to vector product of current vector and vector "v". Works only with vectors which consists of 3 elements + * + * @param v vector of type PIMathVectorT + * @return vector equal to vector product of current vector and vector "v" type of PIMathVectorT + */ _CVector cross(const _CVector & v) {return (*this) * v;} + + /** + * @brief Method that returns a value equal to absolute value of dot product of current vector and vector "v" + * + * @param v vector of type PIMathVectorT + * @return value equal to absolute value of dot product of current vector and vector "v" + */ Type dot(const _CVector & v) const {return (*this) ^ v;} + + /** + * @brief Method which checks if every elements of vector are zeros + * + * @return true if vector is null, else false + */ bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;} + + /** + * @brief Method which checks if current vector is orthogonal to vector "v" + * + * @param v vector of type PIMathVectorT + * @return true if vectors are orthogonal, else false + */ bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);} - const Type & at(uint index) {return c[index];} + /** + * @brief Read-only access to elements reference by index of the vector element "index" + * If you enter an index out of the border of the vector there will be "undefined behavior" + * + * @param index is a parameter that shows the index number of the vector of the selected element + * @return reference to element of vector by index + */ + const Type & at(uint index) {return c[index];} + + /** + * @brief Full access to the element of vector by index. If you enter an index out of the border of the vector there will be "undefined behavior" + * + * @param index is the index of necessary element + * @return element of vector + */ Type & operator [](uint index) {return c[index];} + + /** + * @brief Read-only access to the element of vector by index. If you enter an index out of the border of the vector there will be "undefined behavior" + * + * @param index is the index of necessary element + * @return element of vector + */ Type operator [](uint index) const {return c[index];} _CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;} _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} -- 2.43.0 From c07b7efe65a7b3475a96944b1fddcc206a518c4f Mon Sep 17 00:00:00 2001 From: maakshishov Date: Tue, 22 Sep 2020 13:53:07 +0300 Subject: [PATCH 06/14] full documentacion for PIMathVectorT --- libs/main/math/pimathvector.h | 145 +++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-) diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index deefee7b..095b4598 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -1,4 +1,4 @@ - /*! \file pimathvector.h + /*! \file pimathvector.h * \brief PIMathVector * * This file declare math vector class, which performs various vector operations @@ -244,24 +244,149 @@ public: * @return element of vector */ Type operator [](uint index) const {return c[index];} + + /** + * @brief Vector assignment to vector "v" of type PIMathVectorT + * + * @param v vector for the assigment + * @return vector equal to vector "v" + */ _CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;} + + /** + * @brief Vector assignment to value "v" + * + * @param v value for the assigment + * @return vector, each element of which is equal to the value "v" + */ _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} + + /** + * @brief Compare with vector "v" + * + * @param v vector for the compare + * @return if vectors are equal true, else false + */ bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;} + + /** + * @brief Compare with vector "v" + * + * @param v vector for the compare + * @return if vectors are not equal true, else false + */ bool operator !=(const _CVector & v) const {return !(*this == v);} + + /** + * @brief Addition assignment with vector "v" + * + * @param v vector for the addition assigment + */ void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} + + /** + * @brief Subtraction assignment with vector "v" + * + * @param v vector for the subtraction assigment + */ void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} + + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} + + + * @brief Multiplication assignment with vector "v" + * + * @param v vector for the multiplication assigment + */ void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];} + + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;} + + /** + * @brief Division assignment with vector "v" + * + * @param v vector for the division assigment + */ void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];} + + /** + * @brief Vector substraction + * + * @return the result of vector substraction + */ _CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;} + + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} + + /** + * @brief Vector substraction + * + * @return the result of vector substraction + */ _CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} + + /** + * @brief Vector multiplication with value "v" + * + * @param v is value factor + * @return the result of vector multiplication + */ _CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;} + + /** + * @brief Vector division with value "v" + * + * @param v is value divider + * @return the result of vector division + */ _CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;} + + /** + * @brief Vector division with vector "v" + * + * @param v is vector divider + * @return the result of vector division + */ _CVector operator /(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;} + + /** + * @brief Cross product of two vectors. Works only with vector containing three elements, otherwise returns current vector + * + * @param v is vector for cross product + * @return the result vector equal of cross product + */ _CVector operator *(const _CVector & v) const {if (Size != 3) return _CVector(); _CVector tv; tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} + + /** + * @brief Elementwise assignment of multiplication of two vectors + * + * @param v is vector for multiplication + * @return resulting vector + */ _CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} + + /** + * @brief Absolute value of the dot product + * + * @param v is vector for dot product + * @return resulting vector + */ Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} PIMathMatrixT<1, Size, Type> transposed() const { @@ -270,14 +395,32 @@ public: return ret; } + /** + * @brief Returns the distance between two vectors. Works only for 2-element vectors + * + * @param lp0 is vector + * @param lp1 is vector + * @return resulting value + */ Type distToLine(const _CVector & lp0, const _CVector & lp1) { _CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this); Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length(); return f;} + /** + * @brief The method returns a part of the selected vector from the given vector + * + * @return the resulting vector that is part of this vector + */ template /// vector {Size, Type} to vector {Size1, Type1} PIMathVectorT turnTo() const {PIMathVectorT tv; uint sz = piMin(Size, Size1); for (uint i = 0; i < sz; ++i) tv[i] = c[i]; return tv;} + /** + * @brief Creates a vector filled with a value + * + * @param v this value fills the cells of the vector + * @return filled vector of type PIMathVectorT + */ static _CVector filled(const Type & v) {_CVector vv; PIMV_FOR(i, 0) vv[i] = v; return vv;} private: -- 2.43.0 From b7f035178f62ca6f3d7042cc39ebc9711904f6ac Mon Sep 17 00:00:00 2001 From: maakshishov Date: Tue, 22 Sep 2020 16:02:23 +0300 Subject: [PATCH 07/14] Final commit for docs and tests in pimathvector.h --- libs/main/math/pimathvector.h | 437 +++++++++++++++++++++++++++++++++- 1 file changed, 429 insertions(+), 8 deletions(-) diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index 095b4598..4ea2d8d0 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -52,7 +52,7 @@ public: PIMathVectorT() {resize();} /** - * @brief Constructor that fills a vector "PIMathVectorT" with the values ​​of another vector "PIVector" + * @brief Constructor that fills a vector PIMathVectorT with the values ​​of another vector "PIVector" * * @param val vector of type PIVector which is identified PIMathVectorT * @return vector of type PIMathVectorT with values ​​of vector val @@ -60,9 +60,10 @@ public: PIMathVectorT(const PIVector & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];} /** - * @brief Constructor that fills a vector "PIMathVectorT" with the subtraction of two vectors + * @brief Constructor that fills a vector PIMathVectorT with the subtraction of two vectors * - * @param st vector of type PIMathVect * @param fn vector of type PIMathVectorT + * @param st vector of type PIMathVectorT + * @param fn vector of type PIMathVectorT * @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st" */ PIMathVectorT(const _CVector & st, const _CVector & fn) {resize(); set(st, fn);} @@ -78,7 +79,7 @@ public: * @brief Method that fills a vector with a value * * @param v value of which the vector is filled - * @return vector of type PIMathVector filled with "v" + * @return vector of type PIMathVectorT filled with "v" */ _CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} @@ -139,7 +140,8 @@ public: /** * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements * - * @param v vector of type PIMathVectorT * @return sin value of the angle between two vector + * @param v vector of type PIMathVectorT + * @return sin value of the angle between two vector */ Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} @@ -208,7 +210,7 @@ public: /** * @brief Method which checks if every elements of vector are zeros * - * @return true if vector is null, else false + * @return true if vector is zero, else false */ bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;} @@ -298,7 +300,7 @@ public: */ void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} - + /** * @brief Multiplication assignment with vector "v" * * @param v vector for the multiplication assigment @@ -430,29 +432,106 @@ private: }; +/** +* @brief Inline operator which returns vector multiplication with value "x" +* +* @param x value for the multiplication +* @param v vector for the multiplication +* @return resulting vector +*/ template inline PIMathVectorT operator *(const Type & x, const PIMathVectorT & v) { return v * x; } +/** +* @brief Inline operator for outputting the vector to the console +* +* @param s PICout type +* @param the vector type PIMathVectorT that we print to the console +* @return PIMathVectorT printed to the console +*/ template inline PICout operator <<(PICout s, const PIMathVectorT & v) {s << "{"; PIMV_FOR(i, 0) {s << v[i]; if (i < Size - 1) s << ", ";} s << "}"; return s;} + +/** +* @brief Inline operator checking if the cross product is zero. Works only with vector containing three elements, otherwise returns current vector +* +* @param f vector of the first operand +* @param s vector of the second operand +* @return true if the cross product is zero, else false +*/ template inline bool operator ||(const PIMathVectorT & f, const PIMathVectorT & s) {return (f * s).isNull();} + +/** +* @brief Inline function which takes the square root of each element in the vector +* +* @param v vector of whose elements the square root is taken +* @return resulting vector +*/ template inline PIMathVectorT sqrt(const PIMathVectorT & v) {PIMathVectorT ret; PIMV_FOR(i, 0) {ret[i] = sqrt(v[i]);} return ret;} + +/** +* @brief Inline function which squares each element of the vector +* +* @param v vector whose elements are squared +* @return resulting vector +*/ template inline PIMathVectorT sqr(const PIMathVectorT & v) {PIMathVectorT ret; PIMV_FOR(i, 0) {ret[i] = sqr(v[i]);} return ret;} +/** +* @brief Inline operator for serializing a vector into a PIByteArray +* +* @param s PIByteArray type +* @param v PIMathVectorT type +* @return PIBiteArray serialized PIMathVectorT +*/ template inline PIByteArray & operator <<(PIByteArray & s, const PIMathVectorT & v) {for (uint i = 0; i < Size; ++i) s << v[i]; return s;} + +/** +* @brief Inline operator to deserialize vector from PIByteArray +* +* @param s PIByteArray type +* @param v PIMathVector type +* @return PIMathVector deserialized from PIByteArray +*/ template inline PIByteArray & operator >>(PIByteArray & s, PIMathVectorT & v) {for (uint i = 0; i < Size; ++i) s >> v[i]; return s;} +/** +* @brief Inline function which returns vector size 2 and type of T +* +* @param x first element of vector +* @param y second element of vector +* @return resulting vector +*/ template inline PIMathVectorT<2u, T> createVectorT2(T x, T y) {return PIMathVectorT<2u, T>(PIVector() << x << y);} + +/** +* @brief Inline function which returns vector size 3 and type of T +* +* @param x first element of vector +* @param y second element of vector +* @param z third element of vector +* @return resulting vector +*/ template inline PIMathVectorT<3u, T> createVectorT3(T x, T y, T z) {return PIMathVectorT<3u, T>(PIVector() << x << y << z);} + +/** +* @brief Inline function which returns vector size 4 and type of T +* +* @param x first element of vector +* @param y second element of vector +* @param z third element of vector +* @param w fouth element of vector +* @return resulting vector +*/ template inline PIMathVectorT<4u, T> createVectorT4(T x, T y, T z, T w) {return PIMathVectorT<4u, T>(PIVector() << x << y << z << w);} @@ -478,69 +557,389 @@ typedef PIMathVectorT<4u, double> PIMathVectorT4d; #define PIMV_FOR(v, s) for (uint v = s; v < c.size(); ++v) +//! \brief A class that works with vector operations, the input data of which is the data type of the vector +//! @tparam Type is the data type of the vector. There are can be basic C++ language data and different classes where the arithmetic operators(=, +=, -=, *=, /=, ==, !=, +, -, *, /) +//! of the C++ language are implemented template class PIP_EXPORT PIMathVector { typedef PIMathVector _CVector; template friend PIByteArray & operator <<(PIByteArray & s, const PIMathVector & v); template friend PIByteArray & operator >>(PIByteArray & s, PIMathVector & v); public: + /** + * @brief Constructor that calls the resize method + * + * @param size vector dimension + * @return resized vector of type PIMathMatrix + */ PIMathVector(const uint size = 0) {c.resize(size);} + + /** + * @brief Constructor that fills a vector PIMathVector with the values ​​of another vector "PIVector" + * + * @param val vector of type PIVector which is identified PIMathVector + * @return vector of type PIMathVector with values ​​of vector val + */ PIMathVector(const PIVector & val) {c.resize(val.size()); PIMV_FOR(i, 0) c[i] = val[i];} + + /** + * @brief Constructor that fills a vector PIMathVector with the subtraction of two vectors + * + * @param st vector of type PIMathVector + * @param fn vector of type PIMathVector + * @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st" + */ PIMathVector(const _CVector & st, const _CVector & fn) {c.resize(st.size()); PIMV_FOR(i, 0) c[i] = fn[i] - st[i];} + /** + * @brief Method which returns size of the vector + * + * @return type uint shows number of elements in this vector + */ uint size() const {return c.size();} + + /** + * @brief Returns self resized vector + * + * @param size new vector dimension + * @param new_value value with which the vector is filled + * @return resized vector + */ _CVector & resize(uint size, const Type & new_value = Type()) {c.resize(size, new_value); return *this;} + + /** + * @brief Returns copy of resized vector + * + * @param size new vector dimension + * @param new_value value with which the vector is filled + * @return resized vector + */ _CVector resized(uint size, const Type & new_value = Type()) {_CVector tv = _CVector(*this); tv.resize(size, new_value); return tv;} + + /** + * @brief Method that fills a vector with a value + * + * @param v value of which the vector is filled + * @return vector of type PIMathVector filled with "v" + */ _CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} + + /** + * @brief Method that fills a vector with the adittion of vector value and "v" + * + * @param v value of which the vector is filled + * @return vector of type PIMathVector with values adittion of vector value and "v" + */ _CVector & move(const Type & v) {PIMV_FOR(i, 0) c[i] += v; return *this;} + + /** + * @brief Method that fills a vector with the adittion of vector value and "v" + * + * @param v vector of type PIMathVectorT + * @return vector of type PIMathVectorT with values adittion of vector value and "v" + */ _CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;} + + /** + * @brief Method that replaces two elements in a vector by indices. You cannot use an index larger than the number vector dimension, + * otherwise there will be "undefined behavior" + * + * @param fe index of the first element + * @param se index of the second element + * @return resulting vector of type PIMathVector + */ _CVector & swap(uint fe, uint se) {piSwap(c[fe], c[se]); return *this;} + + /** + * @brief Method that returns sum of the squares of all elements of the vector + * + * @return value equal to the sum of the squares of all elements of the vector + */ Type lengthSqr() const {Type tv(0); PIMV_FOR(i, 0) tv += (c[i] * c[i]); return tv;} + + /** + * @brief Method that returns length of a vector + * + * @return value equal to length of a vector + */ Type length() const {return sqrt(lengthSqr());} + + /** + * @brief Method that returns the sum of the absolute values ​​of all vector values + * + * @return value equal sum of the absolute values ​​of all vector values + */ Type manhattanLength() const {Type tv(0); PIMV_FOR(i, 0) tv += fabs(c[i]); return tv;} + + /** + * @brief Method that returns the cos of the current vector and vector "v" + * + * @param v vector of type PIMathVector + * @return cos value of the angle between two vectors + */ Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} + + /** + * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements + * + * @param v vector of type PIMathVector + * @return sin value of the angle between two vector + */ Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} + + /** + * @brief Method that returns the angle between of the current vector and vector "v" in Rad + * + * @param v vector of type PIMathVector + * @return value of the angle between two vectors in Rad + */ Type angleRad(const _CVector & v) const {return acos(angleCos(v));} + + /** + * @brief Method that returns the angle between of the current vector and vector "v" in Deg + * + * @param v vector of type PIMathVectorT + * @return value of the angle between two vectors in Deg + */ Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));} + + /** + * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v" + * + * @param v vector of type PIMathVector + * @return vector of type PIMathVector equal to the projection of the current vector onto the vector "v" + */ _CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} + + /** + * @brief Method that returns a normalized vector + * + * @return copy of normalized vector of type PIMathVector + */ _CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;} + + /** + * @brief Method that returns a normalized vector + * + * @return normalized vector of type PIMathVector + */ _CVector normalized() {_CVector tv(*this); tv.normalize(); return tv;} + + /** + * @brief Method which checks if every elements of vector are zeros + * + * @return true if vector is zero, else false + */ bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;} + + /** + * @brief Method which checks if vector is valid + * + * @return true if vector is valid, else false + */ bool isValid() const {return !c.isEmpty();} + /** + * @brief Method which checks if current vector is orthogonal to vector "v" + * + * @param v vector of type PIMathVector + * @return true if vectors are orthogonal, else false + */ bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);} - const Type & at(uint index) {return c[index];} + /** + * @brief Read-only access to elements reference by index of the vector element "index" + * If you enter an index out of the border of the vector there will be "undefined behavior" + * + * @param index is a parameter that shows the index number of the vector of the selected element + * @return reference to element of vector by index + */ + const Type & at(uint index) {return c[index];} + + /** + * @brief Full access to the element of vector by index. If you enter an index out of the border of the vector there will be "undefined behavior" + * + * @param index is the index of necessary element + * @return element of vector + */ Type & operator [](uint index) {return c[index];} + + /** + * @brief Read-only access to the element of vector by index. If you enter an index out of the border of the vector there will be "undefined behavior" + * + * @param index is the index of necessary element + * @return element of vector + */ Type operator [](uint index) const {return c[index];} + + /** + * @brief Vector assignment to vector "v" of type PIMathVector + * + * @param v vector for the assigment + * @return vector equal to vector "v" + */ _CVector & operator =(const _CVector & v) {c = v.c; return *this;} + + /** + * @brief Vector assignment to value "v" + * + * @param v value for the assigment + * @return vector, each element of which is equal to the value "v" + */ _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} + + /** + * @brief Compare with vector "v" + * + * @param v vector for the compare + * @return if vectors are equal true, else false + */ bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;} + + /** + * @brief Compare with vector "v" + * + * @param v vector for the compare + * @return if vectors are not equal true, else false + */ bool operator !=(const _CVector & v) const {return !(*this == v);} + + /** + * @brief Addition assignment with vector "v" + * + * @param v vector for the addition assigment + */ void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} + + /** + * @brief Subtraction assignment with vector "v" + * + * @param v vector for the subtraction assigment + */ void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} + + /** + * @brief Multiplication assignment with value "v" + * + * @param v value for the multiplication assigment + */ void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} + + /** + * @brief Multiplication assignment with vector "v" + * + * @param v vector for the multiplication assigment + */ void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];} + + /** + * @brief Division assignment with value "v" + * + * @param v value for the division assigment + */ void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;} + + /** + * @brief Division assignment with vector "v" + * + * @param v vector for the division assigment + */ void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];} + + /** + * @brief Vector substraction + * + * @return the result of vector substraction + */ _CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;} + + /** + * @brief Matrix addition + * + * @param sm is matrix term + * @return the result of matrix addition + */ _CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} + + /** + * @brief Vector substraction + * + * @return the result of vector substraction + */ _CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} + + /** + * @brief Vector multiplication with value "v" + * + * @param v is value factor + * @return the result of vector multiplication + */ _CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;} + + /** + * @brief Vector division with value "v" + * + * @param v is value divider + * @return the result of vector division + */ _CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;} + + /** + * @brief Cross product of two vectors. Works only with vector containing three elements, otherwise returns current vector + * + * @param v is vector for cross product + * @return the result vector equal of cross product + */ _CVector operator *(const _CVector & v) const {if ((c.size() != 3) && (v.size() != 3)) return _CVector(); _CVector tv(3); tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} + + /** + * @brief Elementwise assignment of multiplication of two vectors + * + * @param v is vector for multiplication + * @return resulting vector + */ _CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} + + /** + * @brief Absolute value of the dot product + * + * @param v is vector for dot product + * @return resulting vector + */ Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} + /** + * @brief Returns the distance between two vectors. Works only for 2-element vectors + * + * @param lp0 is vector + * @param lp1 is vector + * @return resulting value + */ Type distToLine(const _CVector & lp0, const _CVector & lp1) { _CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this); Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length(); return f; } + /** + * @brief Converts PIMathVector to PIVector type + * + * @return vector equal PIMathVector but in PIVector type + */ PIVector toVector() const {return c;} + /** + * @brief Returns full access data of vector + * + * @return data of vector + */ inline Type * data() {return c.data();} + + /** + * @brief Returns read-only data of vector + * + * @return data of vector + */ inline const Type * data() const {return c.data();} private: @@ -555,11 +954,33 @@ template inline std::ostream & operator <<(std::ostream & s, const PIMathVector & v) {s << "{"; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;} #endif +/** +* @brief Inline operator for outputting the vector to the console +* +* @param s PICout type +* @param the vector type PIMathVector that we print to the console +* @return PIMathVector printed to the console +*/ template inline PICout operator <<(PICout s, const PIMathVector & v) {s << "Vector{"; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;} +/** +* @brief Inline operator for serializing a vector into a PIByteArray +* +* @param s PIByteArray type +* @param v PIMathVector type +* @return PIBiteArray serialized PIMathVector +*/ template inline PIByteArray & operator <<(PIByteArray & s, const PIMathVector & v) {s << v.c; return s;} + +/** +* @brief Inline operator to deserialize vector from PIByteArray +* +* @param s PIByteArray type +* @param v PIMathVector type +* @return PIMathVector deserialized from PIByteArray +*/ template inline PIByteArray & operator >>(PIByteArray & s, PIMathVector & v) {s >> v.c; return s;} -- 2.43.0 From 0940e8fa440a1accf85ebed7e77e9de303d5ce86 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Fri, 25 Sep 2020 12:36:05 +0300 Subject: [PATCH 08/14] documentation and tests bug fix for PIMathVector.h --- libs/main/math/pimathvector.h | 309 +++++++++-------- tests/math/testpimathmatrix.cpp | 2 +- tests/math/testpimathmatrixt.cpp | 2 +- tests/math/testpimathvector.cpp | 467 +++++++++++++++----------- tests/math/testpimathvectort.cpp | 550 ++++++++++++++++++------------- 5 files changed, 740 insertions(+), 590 deletions(-) diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index 4ea2d8d0..f624b2b2 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -47,7 +47,6 @@ public: /** * @brief Constructor that calls the private resize method * - * @return resized vector of type PIMathMatrixT */ PIMathVectorT() {resize();} @@ -55,7 +54,6 @@ public: * @brief Constructor that fills a vector PIMathVectorT with the values ​​of another vector "PIVector" * * @param val vector of type PIVector which is identified PIMathVectorT - * @return vector of type PIMathVectorT with values ​​of vector val */ PIMathVectorT(const PIVector & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];} @@ -64,49 +62,48 @@ public: * * @param st vector of type PIMathVectorT * @param fn vector of type PIMathVectorT - * @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st" */ PIMathVectorT(const _CVector & st, const _CVector & fn) {resize(); set(st, fn);} /** - * @brief Method which returns size of the vector + * @brief Method that returns the number of elements contained in the vector * * @return type uint shows number of elements in this vector */ uint size() const {return Size;} /** - * @brief Method that fills a vector with a value + * @brief Method that set this elements to value "v" * * @param v value of which the vector is filled - * @return vector of type PIMathVectorT filled with "v" + * @return reference to this */ _CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} /** - * @brief Method that fills a vector with the subtraction of two vectors + * @brief Method that set this with the subtraction of two vectors * * @param st vector of type PIMathVectorT * @param fn vector of type PIMathVectorT - * @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st" + * @return reference to this */ _CVector & set(const _CVector & st, const _CVector & fn) {PIMV_FOR(i, 0) c[i] = fn[i] - st[i]; return *this;} /** - * @brief Method that fills a vector with the adittion of vector value and "v" + * @brief Method that sets this using a vector, each element of which is added to the value of "v" * * @param v value of which the vector is filled - * @return vector of type PIMathVectorT with values adittion of vector value and "v" + * @return reference to this */ _CVector & move(const Type & v) {PIMV_FOR(i, 0) c[i] += v; return *this;} /** - * @brief Method that fills a vector with the adittion of vector value and "v" + * @brief Method that sets this with a vector, each element of which is added to each element of the vector "v" * * @param v vector of type PIMathVectorT - * @return vector of type PIMathVectorT with values adittion of vector value and "v" + * @return reference to this */ - _CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;} + _CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;} /** * @brief Method that returns sum of the squares of all elements of the vector @@ -116,7 +113,7 @@ public: Type lengthSqr() const {Type tv(0); PIMV_FOR(i, 0) tv += (c[i] * c[i]); return tv;} /** - * @brief Method that returns length of a vector + * @brief Method that returns a scalar physical value equal to the absolute value of vector * * @return value equal to length of a vector */ @@ -131,56 +128,62 @@ public: /** * @brief Method that returns the cos of the current vector and vector "v" + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return cos value of the angle between two vectors */ - Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} + Type angleCos(const _CVector & v) const {if(v.size() != Size) return false; Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} /** - * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements - * + * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements. + * If the vectors have different dimensions, it returns false + * * @param v vector of type PIMathVectorT * @return sin value of the angle between two vector */ - Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} + Type angleSin(const _CVector & v) const {if(v.size() != Size) return false; Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Rad + * @brief Method that returns the angle between of the current vector and vector "v" in Rad. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Rad */ - Type angleRad(const _CVector & v) const {return acos(angleCos(v));} + Type angleRad(const _CVector & v) const {if(v.size() != Size) return false; return acos(angleCos(v));} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Deg + * @brief Method that returns the angle between of the current vector and vector "v" in Deg. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Deg */ - Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));} + Type angleDeg(const _CVector & v) const {if(v.size() != Size) return false; return toDeg(acos(angleCos(v)));} /** - * @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg + * @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return value of the angle elevation between two vectors in Deg */ - Type angleElevation(const _CVector & v) const {_CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;} + Type angleElevation(const _CVector & v) const {if(v.size() != Size) return false; _CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;} /** - * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v" + * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v". + * If the vectors have different dimensions, it returns this without changing anything * * @param v vector of type PIMathVectorT * @return vector of type PIMathVectorT equal to the projection of the current vector onto the vector "v" */ - _CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} + _CVector projection(const _CVector & v) {if(v.size() != Size) return _CVector(*this); Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} /** - * @brief Method that returns a normalized vector + * @brief Method that returns this normalized vector * - * @return copy of normalized vector of type PIMathVectorT + * @return reference to this */ _CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;} @@ -215,12 +218,13 @@ public: bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;} /** - * @brief Method which checks if current vector is orthogonal to vector "v" + * @brief Method which checks if current vector is orthogonal to vector "v". + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return true if vectors are orthogonal, else false */ - bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);} + bool isOrtho(const _CVector & v) const {if(v.size() != Size) return false; return ((*this) ^ v) == Type(0);} /** * @brief Read-only access to elements reference by index of the vector element "index" @@ -245,10 +249,10 @@ public: * @param index is the index of necessary element * @return element of vector */ - Type operator [](uint index) const {return c[index];} + const Type & operator [](uint index) const {return c[index];} /** - * @brief Vector assignment to vector "v" of type PIMathVectorT + * @brief Vector assignment to vector "v" of type PIMathVectorT * * @param v vector for the assigment * @return vector equal to vector "v" @@ -256,12 +260,12 @@ public: _CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;} /** - * @brief Vector assignment to value "v" + * @brief Assignment operation. All vector values ​​become equal to "v" * * @param v value for the assigment - * @return vector, each element of which is equal to the value "v" + * @return reference to this */ - _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} + _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} /** * @brief Compare with vector "v" @@ -280,71 +284,72 @@ public: bool operator !=(const _CVector & v) const {return !(*this == v);} /** - * @brief Addition assignment with vector "v" + * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the addition assigment */ - void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} + void operator +=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] += v[i];} /** - * @brief Subtraction assignment with vector "v" + * @brief Subtraction assignmentthis vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the subtraction assigment */ - void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} + void operator -=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] -= v[i];} /** - * @brief Multiplication assignment with value "v" + * @brief Multiplication assignment this vector with value "v" * * @param v value for the multiplication assigment */ void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} /** - * @brief Multiplication assignment with vector "v" + * @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the multiplication assigment */ - void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];} + void operator *=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] *= v[i];} /** - * @brief Division assignment with value "v" + * @brief Division assignment with this vector value "v" * * @param v value for the division assigment */ void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;} /** - * @brief Division assignment with vector "v" + * @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the division assigment */ - void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];} + void operator /=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] /= v[i];} /** - * @brief Vector substraction + * @brief Vector substraction this vector * * @return the result of vector substraction */ _CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;} /** - * @brief Matrix addition + * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything * - * @param sm is matrix term - * @return the result of matrix addition + * @param v is vector term + * @return the result of vector addition */ - _CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} + _CVector operator +(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} /** - * @brief Vector substraction + * @brief Vector substraction this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything * + * @param v is vector term * @return the result of vector substraction */ - _CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} + _CVector operator -(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} /** - * @brief Vector multiplication with value "v" + * @brief Vector multiplication this vector with value "v" * * @param v is value factor * @return the result of vector multiplication @@ -352,7 +357,7 @@ public: _CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;} /** - * @brief Vector division with value "v" + * @brief Vector division this vector with value "v" * * @param v is value divider * @return the result of vector division @@ -360,12 +365,12 @@ public: _CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;} /** - * @brief Vector division with vector "v" + * @brief Vector division this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything * * @param v is vector divider * @return the result of vector division */ - _CVector operator /(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;} + _CVector operator /(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;} /** * @brief Cross product of two vectors. Works only with vector containing three elements, otherwise returns current vector @@ -376,20 +381,20 @@ public: _CVector operator *(const _CVector & v) const {if (Size != 3) return _CVector(); _CVector tv; tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} /** - * @brief Elementwise assignment of multiplication of two vectors + * @brief Elementwise assignment of multiplication of two vectors. If the vectors have different dimensions, it returns this without changing anything * * @param v is vector for multiplication * @return resulting vector */ - _CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} + _CVector operator &(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} /** - * @brief Absolute value of the dot product + * @brief Absolute value of the dot product. If the vectors have different dimensions, it returns false * * @param v is vector for dot product * @return resulting vector */ - Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} + Type operator ^(const _CVector & v) const {if(v.size() != Size) return false; Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} PIMathMatrixT<1, Size, Type> transposed() const { PIMathMatrixT<1, Size, Type> ret; @@ -397,18 +402,6 @@ public: return ret; } - /** - * @brief Returns the distance between two vectors. Works only for 2-element vectors - * - * @param lp0 is vector - * @param lp1 is vector - * @return resulting value - */ - Type distToLine(const _CVector & lp0, const _CVector & lp1) { - _CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this); - Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length(); - return f;} - /** * @brief The method returns a part of the selected vector from the given vector * @@ -418,7 +411,7 @@ public: PIMathVectorT turnTo() const {PIMathVectorT tv; uint sz = piMin(Size, Size1); for (uint i = 0; i < sz; ++i) tv[i] = c[i]; return tv;} /** - * @brief Creates a vector filled with a value + * @brief Creates a vector each element of which is equal to value "v" * * @param v this value fills the cells of the vector * @return filled vector of type PIMathVectorT @@ -570,7 +563,6 @@ public: * @brief Constructor that calls the resize method * * @param size vector dimension - * @return resized vector of type PIMathMatrix */ PIMathVector(const uint size = 0) {c.resize(size);} @@ -578,7 +570,6 @@ public: * @brief Constructor that fills a vector PIMathVector with the values ​​of another vector "PIVector" * * @param val vector of type PIVector which is identified PIMathVector - * @return vector of type PIMathVector with values ​​of vector val */ PIMathVector(const PIVector & val) {c.resize(val.size()); PIMV_FOR(i, 0) c[i] = val[i];} @@ -587,15 +578,14 @@ public: * * @param st vector of type PIMathVector * @param fn vector of type PIMathVector - * @return vector of type PIMathVectorT with values subtraction vectors "fn" and "st" */ PIMathVector(const _CVector & st, const _CVector & fn) {c.resize(st.size()); PIMV_FOR(i, 0) c[i] = fn[i] - st[i];} - /** - * @brief Method which returns size of the vector - * - * @return type uint shows number of elements in this vector - */ + /** + * @brief Method that returns the number of elements contained in the vector + * + * @return type uint shows number of elements in this vector + */ uint size() const {return c.size();} /** @@ -603,7 +593,7 @@ public: * * @param size new vector dimension * @param new_value value with which the vector is filled - * @return resized vector + * @return reference to this */ _CVector & resize(uint size, const Type & new_value = Type()) {c.resize(size, new_value); return *this;} @@ -616,37 +606,38 @@ public: */ _CVector resized(uint size, const Type & new_value = Type()) {_CVector tv = _CVector(*this); tv.resize(size, new_value); return tv;} - /** - * @brief Method that fills a vector with a value - * - * @param v value of which the vector is filled - * @return vector of type PIMathVector filled with "v" - */ + /** + * @brief Method that set this elements to value "v" + * + * @param v value of which the vector is filled + * @return reference to this + */ _CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} - /** - * @brief Method that fills a vector with the adittion of vector value and "v" - * - * @param v value of which the vector is filled - * @return vector of type PIMathVector with values adittion of vector value and "v" - */ + /** + * @brief Method that sets this using a vector, each element of which is added to the value of "v" + * + * @param v value of which the vector is filled + * @return reference to this + */ _CVector & move(const Type & v) {PIMV_FOR(i, 0) c[i] += v; return *this;} - /** - * @brief Method that fills a vector with the adittion of vector value and "v" - * - * @param v vector of type PIMathVectorT - * @return vector of type PIMathVectorT with values adittion of vector value and "v" - */ - _CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;} + /** + * @brief Method that sets this with a vector, each element of which is added to each element of the vector "v". + * If the vectors have different dimensions, it returns this without changing anything + * + * @param v vector of type PIMathVectorT + * @return reference to this + */ + _CVector & move(const _CVector & v) {if(v.size() != c.size()) return *this; PIMV_FOR(i, 0) c[i] += v[i]; return *this;} /** - * @brief Method that replaces two elements in a vector by indices. You cannot use an index larger than the number vector dimension, + * @brief Method that replaces two elements in this vector by indices. You cannot use an index larger than the number vector dimension, * otherwise there will be "undefined behavior" * * @param fe index of the first element * @param se index of the second element - * @return resulting vector of type PIMathVector + * @return reference to this */ _CVector & swap(uint fe, uint se) {piSwap(c[fe], c[se]); return *this;} @@ -657,11 +648,11 @@ public: */ Type lengthSqr() const {Type tv(0); PIMV_FOR(i, 0) tv += (c[i] * c[i]); return tv;} - /** - * @brief Method that returns length of a vector - * - * @return value equal to length of a vector - */ + /** + * @brief Method that returns a scalar physical value equal to the absolute value of vector + * + * @return value equal to length of a vector + */ Type length() const {return sqrt(lengthSqr());} /** @@ -672,44 +663,48 @@ public: Type manhattanLength() const {Type tv(0); PIMV_FOR(i, 0) tv += fabs(c[i]); return tv;} /** - * @brief Method that returns the cos of the current vector and vector "v" + * @brief Method that returns the cos of the current vector and vector "v". If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVector * @return cos value of the angle between two vectors */ - Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} + Type angleCos(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} /** - * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements + * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVector * @return sin value of the angle between two vector */ - Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} + Type angleSin(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Rad + * @brief Method that returns the angle between of the current vector and vector "v" in Rad. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVector * @return value of the angle between two vectors in Rad */ - Type angleRad(const _CVector & v) const {return acos(angleCos(v));} + Type angleRad(const _CVector & v) const {if(v.size() != c.size()) return false; return acos(angleCos(v));} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Deg + * @brief Method that returns the angle between of the current vector and vector "v" in Deg. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Deg */ - Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));} + Type angleDeg(const _CVector & v) const {if(v.size() != c.size()) return false; return toDeg(acos(angleCos(v)));} /** - * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v" + * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v". + * If the vectors have different dimensions, it returns this without changing anything * * @param v vector of type PIMathVector * @return vector of type PIMathVector equal to the projection of the current vector onto the vector "v" */ - _CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} + _CVector projection(const _CVector & v) {if(v.size() != c.size()) return *this; Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} /** * @brief Method that returns a normalized vector @@ -740,12 +735,13 @@ public: bool isValid() const {return !c.isEmpty();} /** - * @brief Method which checks if current vector is orthogonal to vector "v" + * @brief Method which checks if current vector is orthogonal to vector "v". + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVector * @return true if vectors are orthogonal, else false */ - bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);} + bool isOrtho(const _CVector & v) const {if(v.size() != c.size()) return false; return ((*this) ^ v) == Type(0);} /** * @brief Read-only access to elements reference by index of the vector element "index" @@ -770,21 +766,22 @@ public: * @param index is the index of necessary element * @return element of vector */ - Type operator [](uint index) const {return c[index];} + const Type & operator [](uint index) const {return c[index];} /** * @brief Vector assignment to vector "v" of type PIMathVector + * If the vectors have different dimensions, it returns this without changing anything * * @param v vector for the assigment - * @return vector equal to vector "v" + * @return reference to this */ - _CVector & operator =(const _CVector & v) {c = v.c; return *this;} + _CVector & operator =(const _CVector & v) {if(v.size() != c.size()) return *this; c = v.c; return *this;} /** * @brief Vector assignment to value "v" * * @param v value for the assigment - * @return vector, each element of which is equal to the value "v" + * @return reference to this */ _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} @@ -794,7 +791,7 @@ public: * @param v vector for the compare * @return if vectors are equal true, else false */ - bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;} + bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if ((c[i] != v[i]) || (v.size() != c.size())) return false; return true;} /** * @brief Compare with vector "v" @@ -805,71 +802,72 @@ public: bool operator !=(const _CVector & v) const {return !(*this == v);} /** - * @brief Addition assignment with vector "v" + * @brief Addition assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the addition assigment */ - void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} + void operator +=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] += v[i];} /** - * @brief Subtraction assignment with vector "v" + * @brief Subtraction assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the subtraction assigment */ - void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} + void operator -=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] -= v[i];} /** - * @brief Multiplication assignment with value "v" + * @brief Multiplication assignment this vector with value "v" * * @param v value for the multiplication assigment */ void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} /** - * @brief Multiplication assignment with vector "v" + * @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the multiplication assigment */ - void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];} + void operator *=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] *= v[i];} /** - * @brief Division assignment with value "v" + * @brief Division assignment this vector with value "v" * * @param v value for the division assigment */ void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;} /** - * @brief Division assignment with vector "v" + * @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the division assigment */ - void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];} + void operator /=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] /= v[i];} /** - * @brief Vector substraction + * @brief Vector substraction this vector * * @return the result of vector substraction */ _CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;} /** - * @brief Matrix addition + * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything * - * @param sm is matrix term + * @param v is vector term * @return the result of matrix addition */ - _CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} + _CVector operator +(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} /** - * @brief Vector substraction + * @brief Vector substraction this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything * + * @param v is vector term * @return the result of vector substraction */ - _CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} + _CVector operator -(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} /** - * @brief Vector multiplication with value "v" + * @brief Vector multiplicationthis vector with value "v" * * @param v is value factor * @return the result of vector multiplication @@ -877,7 +875,7 @@ public: _CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;} /** - * @brief Vector division with value "v" + * @brief Vector division this vector with value "v" * * @param v is value divider * @return the result of vector division @@ -890,36 +888,23 @@ public: * @param v is vector for cross product * @return the result vector equal of cross product */ - _CVector operator *(const _CVector & v) const {if ((c.size() != 3) && (v.size() != 3)) return _CVector(); _CVector tv(3); tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} + _CVector operator *(const _CVector & v) const {if ((c.size() != 3) || (v.size() != 3)) return _CVector(); _CVector tv(3); tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} /** - * @brief Elementwise assignment of multiplication of two vectors + * @brief Elementwise assignment of multiplication of two vectors. If the vectors have different dimensions, it returns this without changing anything * * @param v is vector for multiplication * @return resulting vector */ - _CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} + _CVector operator &(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} /** - * @brief Absolute value of the dot product + * @brief Value of the dot product. If the vectors have different dimensions, it returns false * * @param v is vector for dot product - * @return resulting vector + * @return resulting value */ - Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} - - /** - * @brief Returns the distance between two vectors. Works only for 2-element vectors - * - * @param lp0 is vector - * @param lp1 is vector - * @return resulting value - */ - Type distToLine(const _CVector & lp0, const _CVector & lp1) { - _CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this); - Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length(); - return f; - } + Type operator ^(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} /** * @brief Converts PIMathVector to PIVector type diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index f2c8cc10..c6a52ec7 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -5,7 +5,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrix matrix, double val, int num) bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { - if(matrix.element(i, j) != val) { + if(matrix.element(i, j) - val >= double(1E-200)) { b = false; } } diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index ff9afc8c..c9ba0ff7 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -8,7 +8,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, double v bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { - if(matrix.at(i, j) != val) { + if(matrix.at(i, j) - val >= double(1E-200)) { b = false; } } diff --git a/tests/math/testpimathvector.cpp b/tests/math/testpimathvector.cpp index b12ba4bb..4d0bf405 100644 --- a/tests/math/testpimathvector.cpp +++ b/tests/math/testpimathvector.cpp @@ -1,10 +1,12 @@ #include "gtest/gtest.h" #include "pimathvector.h" +const uint SIZE = 3u; + bool cmpVectorWithValue(PIMathVector vector, double val, int num) { bool b = true; for(int i = 0; i < num; i++) { - if(vector[i] != val) { + if(vector[i] - val >= double(1E-200)) { b = false; } } @@ -12,146 +14,181 @@ bool cmpVectorWithValue(PIMathVector vector, double val, int num) { } TEST(PIMathVector_Test, size) { - auto vector = PIMathVector(3u); - ASSERT_TRUE(vector.size() == 3u); + auto vector = PIMathVector(SIZE); + ASSERT_TRUE(vector.size() == SIZE); } TEST(PIMathVector_Test, resize) { + uint newSize = 4u; + double a = 5.0; PIMathVector vector; - vector.resize(4u, 5.0); - ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, vector.size())); + vector.resize(newSize, a); + ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size())); } TEST(PIMathVector_Test, resized) { + uint newSize = 4u; + double a = 5.0; PIMathVector vector; - vector.resized(4u, 5.0); - ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, vector.size())); + vector.resized(newSize, a); + ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size())); } TEST(PIMathVector_Test, fill) { - PIMathVector vector(3u); - vector.fill(5.0); - ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3u)); + double a = 5.0; + PIMathVector vector(SIZE); + vector.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVector_Test, moveVal) { - PIMathVector vector(3u); - vector.fill(5.0); - vector.move(5.0); - ASSERT_TRUE(cmpVectorWithValue(vector, 10.0, 3u)); + double a = 5.0; + PIMathVector vector(SIZE); + vector.fill(a); + vector.move(a); + ASSERT_TRUE(cmpVectorWithValue(vector, 2 * a, SIZE)); } TEST(PIMathVector_Test, moveVec) { - PIMathVector vector(3u); - PIMathVector vec(3u); - vector.fill(5.0); - vec.fill(7.0); + double a = 5.0; + double b = 7.0; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vector.fill(a); + vec.fill(b); vector.move(vec); - ASSERT_TRUE(cmpVectorWithValue(vector, 12.0, 3u)); + ASSERT_TRUE(cmpVectorWithValue(vector, a + b, SIZE)); } TEST(PIMathVector_Test, swap) { - PIMathVector vector(3u); + double b = 5.12; + double c = 3.32; + double d = 7.12; + PIMathVector vector(SIZE); double a[3]; - vector[0] = 5.12; - vector[1] = 3.32; - vector[2] = 7.12; + vector[0] = b; + vector[1] = c; + vector[2] = d; a[0] = vector[0]; a[1] = vector[1]; a[2] = vector[2]; vector.swap(0u, 1u); - ASSERT_TRUE((a[0] == vector[1]) && (a[1] == vector[0]) && (a[2] == vector[2])); + ASSERT_DOUBLE_EQ(a[0], vector[1]); + ASSERT_DOUBLE_EQ(a[1], vector[0]); + ASSERT_DOUBLE_EQ(a[2], vector[2]); } TEST(PIMathVector_Test, lengthSqr) { - PIMathVector vector(3u); - vector.fill(1.0); - ASSERT_EQ(3.0, vector.lengthSqr()); + double a = 3.0; + PIMathVector vector(SIZE); + vector.fill(a); + ASSERT_DOUBLE_EQ(SIZE * a * a, vector.lengthSqr()); } TEST(PIMathVector_Test, length) { - PIMathVector vector(3u); - vector.fill(1.0); - ASSERT_DOUBLE_EQ(sqrt(3.0), vector.length()); + double a = 3.32; + PIMathVector vector(SIZE); + vector.fill(a); + ASSERT_DOUBLE_EQ(sqrt(SIZE * a * a), vector.length()); } TEST(PIMathVector_Test, manhattanLength) { - PIMathVector vector(3u); - vector.fill(5.0); - ASSERT_DOUBLE_EQ(15.0, vector.manhattanLength()); + double a = 3.32; + PIMathVector vector(SIZE); + vector.fill(a); + ASSERT_DOUBLE_EQ(SIZE * a, vector.manhattanLength()); } TEST(PIMathVector_Test, angleCos) { - PIMathVector vector(3u); - PIMathVector vec(3u); - vector[0] = 1.0; - vector[1] = 1.0; - vec[1] = 1.0; - ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleCos(vec)); + double a = 3.32; + double angle = 0.78539816339744830961566084581988; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(cos(angle), vector.angleCos(vec)); } TEST(PIMathVector_Test, angleSin) { - PIMathVector vector(3u); - PIMathVector vec(3u); - vector[0] = 1.0; - vector[1] = 1.0; - vec[1] = 1.0; - ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleSin(vec)); + double a = 3.32; + double angle = 0.78539816339744830961566084581988; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(sin(angle), vector.angleSin(vec)); } TEST(PIMathVector_Test, angleRad) { - PIMathVector vector(3u); - PIMathVector vec(3u); - vector[0] = 1.0; - vector[1] = 1.0; - vec[1] = 1.0; - ASSERT_DOUBLE_EQ(0.78539816339744830961566084581988, vector.angleRad(vec)); + double a = 3.32; + double angle = 0.78539816339744830961566084581988; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(angle, vector.angleRad(vec)); } TEST(PIMathVector_Test, angleDeg) { - PIMathVector vector(3u); - PIMathVector vec(3u); - vector[0] = 1.0; - vector[1] = 1.0; - vec[1] = 1.0; - ASSERT_DOUBLE_EQ(45.0, vector.angleDeg(vec)); + double a = 3.32; + double angle = 45.0; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(angle, vector.angleDeg(vec)); } TEST(PIMathVector_Test, projection) { - PIMathVector vector(2u); - PIMathVector vec(2u); - vec[0] = 1.0; - vector[0] = 1.0; - vector[1] = 1.0; + double a = 2.0; + double b = 2.0; + double res = sqrt(32.0); + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vec[0] = a; + vec[2] = b; + vector[0] = a; + vector[1] = b; + vector[2] = a; auto vecProj = vector.projection(vec); - ASSERT_TRUE(vecProj == vec); + ASSERT_DOUBLE_EQ(res, vecProj[0]); + ASSERT_DOUBLE_EQ(0.0, vecProj[1]); + ASSERT_DOUBLE_EQ(res, vecProj[2]); } TEST(PIMathVector_Test, normalize) { - PIMathVector vector(3u); - vector.fill(5.0); - ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), 5.0 / sqrt(75.0), 3u)); + double a = 5.0; + PIMathVector vector(SIZE); + vector.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), a / sqrt(SIZE * a * a), SIZE)); } TEST(PIMathVector_Test, normalized) { - PIMathVector vector(3u); - vector.fill(5.0); - ASSERT_TRUE(cmpVectorWithValue(vector.normalized(), 5.0 / sqrt(75.0), 3u)); + double a = 5.0; + PIMathVector vector(SIZE); + PIMathVector vectorNew(SIZE); + vector.fill(a); + vectorNew = vector.normalized(); + ASSERT_TRUE(cmpVectorWithValue(vectorNew, a / sqrt(SIZE * a * a), SIZE)); } TEST(PIMathVector_Test, isNullTrue) { - PIMathVector vector(3u); + PIMathVector vector(SIZE); ASSERT_TRUE(vector.isNull()); } TEST(PIMathVector_Test, isNullFalse) { - PIMathVector vector(3u); + PIMathVector vector(SIZE); vector[0] = 6.273; ASSERT_FALSE(vector.isNull()); } TEST(PIMathVector_Test, isValidTrue) { - PIMathVector vector(3u); + PIMathVector vector(SIZE); ASSERT_TRUE(vector.isValid()); } @@ -161,27 +198,35 @@ TEST(PIMathVector_Test, isValidFalse) { } TEST(PIMathVector_Test, isOrthoTrue) { - PIMathVector vector(2u); - PIMathVector vect(2u); - vector[0] = 2.0; - vect[1] = 1.0; + uint sizeNew = 2u; + double a = 2.0; + double b = 1.0; + PIMathVector vector(sizeNew); + PIMathVector vect(sizeNew); + vector[0] = a; + vect[1] = b; ASSERT_TRUE(vector.isOrtho(vect)); } TEST(PIMathVector_Test, isOrthoFalse) { - PIMathVector vector(2u); - PIMathVector vect(2u); - vector[0] = 2.0; - vect[0] = 5.0; - vect[1] = 1.0; + uint sizeNew = 2u; + double a = 2.0; + double b = 1.0; + double c = 5.0; + PIMathVector vector(sizeNew); + PIMathVector vect(sizeNew); + vector[0] = a; + vect[0] = c; + vect[1] = b; ASSERT_FALSE(vector.isOrtho(vect)); } TEST(PIMathVector_Test, at) { - PIMathVector vector(3u); - vector.fill(5.5); - for(uint i = 0; i < 3u; i++){ - if(vector.at(i) != 5.5){ + double a = 5.5; + PIMathVector vector(SIZE); + vector.fill(a); + for(uint i = 0; i < SIZE; i++){ + if(vector.at(i) - a >= double(1E-200)){ ASSERT_TRUE(false); } } @@ -189,176 +234,212 @@ TEST(PIMathVector_Test, at) { } TEST(PIMathVector_Test, operator_AssignmentValue) { - PIMathVector vector(3u); - vector = 3.0; - ASSERT_TRUE(cmpVectorWithValue(vector, 3.0, 3)); + double a = 5.5; + PIMathVector vector(SIZE); + vector = a; + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVector_Test, operator_AssignmentVector) { - PIMathVector vector(3u); - PIMathVector vec(3u); - vec = 5.0; + double a = 5.5; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vec = a; vector = vec; - ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3)); + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVector_Test, operator_EqualTrue) { - PIMathVector vector(2u); - PIMathVector vec(2u); - vector[0] = 5.12; - vector[1] = 7.34; - vec[0] = 5.12; - vec[1] = 7.34; + double a = 5.12; + double b = 7.34; + uint newSize = 2u; + PIMathVector vector(newSize); + PIMathVector vec(newSize); + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = b; ASSERT_TRUE(vec == vector); } TEST(PIMathVector_Test, operator_EqualFalse) { - PIMathVector vector(2u); - PIMathVector vec(2u); - vector[0] = 5.12; - vector[1] = 7.34; - vec[0] = 5.12; - vec[1] = 0.34; + double a = 5.12; + double b = 7.34; + double c = 7.332; + uint newSize = 2u; + PIMathVector vector(newSize); + PIMathVector vec(newSize); + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = c; ASSERT_FALSE(vec == vector); } TEST(PIMathVector_Test, operator_Not_EqualTrue) { - PIMathVector vector(2u); - PIMathVector vec(2u); - vector[0] = 5.12; - vector[1] = 7.34; - vec[0] = 5.12; - vec[1] = 0.34; + double a = 5.12; + double b = 7.34; + double c = 7.332; + uint newSize = 2u; + PIMathVector vector(newSize); + PIMathVector vec(newSize); + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = c; ASSERT_TRUE(vec != vector); } TEST(PIMathVector_Test, operator_Not_EqualFalse) { - PIMathVector vector(2u); - PIMathVector vec(2u); - vector[0] = 5.12; - vector[1] = 7.34; - vec[0] = 5.12; - vec[1] = 7.34; + double a = 5.12; + double b = 7.34; + uint newSize = 2u; + PIMathVector vector(newSize); + PIMathVector vec(newSize); + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = b; ASSERT_FALSE(vec != vector); } TEST(PIMathVector_Test, operator_Addition_Aassignment) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1.fill(6.0); - vector2.fill(1.72); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); vector1 += vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, 7.72, 3)); + ASSERT_TRUE(cmpVectorWithValue(vector1, a + b, SIZE)); } TEST(PIMathVector_Test, operator_Subtraction_Assignment) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1.fill(6.0); - vector2.fill(1.72); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); vector1 -= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, 4.28, 3)); + ASSERT_TRUE(cmpVectorWithValue(vector1, a - b, SIZE)); } TEST(PIMathVector_Test, operator_Multiplication_AssignmentValue) { - PIMathVector vector1(3u); - vector1.fill(6.0); - vector1 *= 4.0; - ASSERT_TRUE(cmpVectorWithValue(vector1, 24.0, 3)); + double a = 6.0; + double b = 4.0; + PIMathVector vector1(SIZE); + vector1.fill(a); + vector1 *= b; + ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); } TEST(PIMathVector_Test, operator_Multiplication_AssignmentVector) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1.fill(6.0); - vector2.fill(1.72); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); vector1 *= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, 10.32, 3)); + ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); } TEST(PIMathVector_Test, operator_Division_AssignmentValue) { - PIMathVector vector1(3u); - vector1.fill(6.0); - vector1 /= 4.0; - ASSERT_TRUE(cmpVectorWithValue(vector1, 1.5, 3)); + double a = 6.0; + double b = 4.0; + PIMathVector vector1(SIZE); + vector1.fill(a); + vector1 /= b; + ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); } TEST(PIMathVector_Test, operator_Division_AssignmentVector) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1.fill(6.0); - vector2.fill(1.5); + double a = 6.0; + double b = 1.5; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); vector1 /= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, 4.0, 3)); + ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); } TEST(PIMathVector_Test, operator_Addition) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1.fill(6.0); - vector2.fill(1.72); - ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, 7.72, 3)); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, a + b, SIZE)); } TEST(PIMathVector_Test, operator_Subtraction) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1.fill(6.0); - vector2.fill(1.72); - ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, 4.28, 3)); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, a - b, SIZE)); } TEST(PIMathVector_Test, operator_MultiplicationValue) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1.fill(6.0); - ASSERT_TRUE(cmpVectorWithValue(vector1 * 4.0, 24.0, 3)); + double a = 6.0; + double b = 4.0; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector1 * b, a * b, SIZE)); } TEST(PIMathVector_Test, operator_MultiplicationVector1) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1.fill(6.0); - vector2.fill(1.72); - ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, 3)); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, SIZE)); } TEST(PIMathVector_Test, operator_MultiplicationVector2) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1[0] = 1.0; - vector2[1] = 1.0; - ASSERT_TRUE(((vector1 * vector2)[0] == 0.0) && ((vector1 * vector2)[1] == 0.0) && ((vector1 * vector2)[2] == 1.0)); + double a = 1.0; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1[0] = a; + vector2[1] = a; + auto crossVec = vector1 * vector2; + ASSERT_DOUBLE_EQ(crossVec[0], 0.0); + ASSERT_DOUBLE_EQ(crossVec[1], 0.0); + ASSERT_DOUBLE_EQ(crossVec[2], a); } -TEST(PIMathVector_Test, operator_DivisionVector) { - PIMathVector vector1(3u); - vector1.fill(6.0); - ASSERT_TRUE(cmpVectorWithValue(vector1 / 4.0, 1.5, 3)); +TEST(PIMathVector_Test, operator_DivisionValue) { + double a = 6.0; + double b = 4.0; + PIMathVector vector1(SIZE); + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector1 / b, a / b, SIZE)); } TEST(PIMathVector_Test, operator_MultiplVect) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1.fill(6.0); - vector2.fill(5.0); - ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, 30.0, 3)); + double a = 6.0; + double b = 5.0; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, a * b, SIZE)); } -TEST(PIMathVector_Test, operator_absDotProduct) { - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vector1.fill(6.0); - vector2.fill(5.0); - ASSERT_TRUE(90.0 == (vector1 ^ vector2)); -} - -TEST(PIMathVector_Test, distToLine) { - PIMathVector vect(3u); - PIMathVector vector1(3u); - PIMathVector vector2(3u); - vect.fill(6.0); - vector1[0] = 1.0; - vector2[1] = -1.0; - ASSERT_DOUBLE_EQ(vect.distToLine(vector1, vector2), sqrt(2.0)/2.0); +TEST(PIMathVector_Test, operator_DotProduct) { + double a = 6.0; + double b = 5.0; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(SIZE * a * b == (vector1 ^ vector2)); } diff --git a/tests/math/testpimathvectort.cpp b/tests/math/testpimathvectort.cpp index 82125a28..89905e97 100644 --- a/tests/math/testpimathvectort.cpp +++ b/tests/math/testpimathvectort.cpp @@ -2,188 +2,233 @@ #include "pimathvector.h" #include "pimathmatrix.h" -const uint size = 3u; +const uint SIZE = 3u; -bool cmpVectorWithValue(PIMathVectorT vector, double val, int num) { +bool cmpVectorWithValue(PIMathVectorT vector, double val, int num) { bool b = true; for(int i = 0; i < num; i++) { - if(vector[i] != val) { + if(vector[i] - val >= double(1E-200)) { b = false; } } return b; } -TEST(PIMathVectorT_Test, size) { - PIMathVectorT vector; - ASSERT_TRUE(vector.size() == 3u); +TEST(PIMathVectorT_Test, SIZE) { + PIMathVectorT vector; + ASSERT_TRUE(vector.size() == SIZE); } TEST(PIMathVectorT_Test, fill) { - PIMathVectorT vector; - ASSERT_TRUE(cmpVectorWithValue(vector.fill(5.0), 5.0, 3)); + double a = 5.0; + PIMathVectorT vector; + ASSERT_TRUE(cmpVectorWithValue(vector.fill(a), a, SIZE)); } TEST(PIMathVectorT_Test, set) { - PIMathVectorT vector; - PIMathVectorT vector1; - PIMathVectorT vector2; - ASSERT_TRUE(cmpVectorWithValue(vector.set(vector1.fill(5.0), vector2.fill(3.0)), -2.0, 3)); + double a = 5.0; + double b = 3.0; + PIMathVectorT vector; + PIMathVectorT vector1; + PIMathVectorT vector2; + ASSERT_TRUE(cmpVectorWithValue(vector.set(vector1.fill(a), vector2.fill(b)), b - a, SIZE)); } TEST(PIMathVectorT_Test, MoveVal) { - PIMathVectorT vector; - ASSERT_TRUE(cmpVectorWithValue(vector.move(4.0), 4.0, 3)); + double a = 4.0; + PIMathVectorT vector; + ASSERT_TRUE(cmpVectorWithValue(vector.move(a), a, SIZE)); } TEST(PIMathVectorT_Test, MoveVector) { - PIMathVectorT vector; - PIMathVectorT vector1; - ASSERT_TRUE(cmpVectorWithValue(vector.move(vector1.fill(5.0)), 5.0, 3)); + double a = 5.0; + PIMathVectorT vector; + PIMathVectorT vector1; + ASSERT_TRUE(cmpVectorWithValue(vector.move(vector1.fill(a)), a, SIZE)); } TEST(PIMathVectorT_Test, lengthSqr) { - PIMathVectorT vector; - vector.fill(1.0); - ASSERT_EQ(3.0, vector.lengthSqr()); + double a = 1.0; + PIMathVectorT vector; + vector.fill(a); + ASSERT_DOUBLE_EQ(SIZE * a, vector.lengthSqr()); } TEST(PIMathVectorT_Test, length) { - PIMathVectorT vector; - vector.fill(1.0); - ASSERT_DOUBLE_EQ(sqrt(3.0), vector.length()); + double a = 1.0; + PIMathVectorT vector; + vector.fill(a); + ASSERT_DOUBLE_EQ(sqrt(SIZE * a), vector.length()); } TEST(PIMathVectorT_Test, manhattanLength) { - PIMathVectorT vector; - vector.fill(5.0); - ASSERT_DOUBLE_EQ(15.0, vector.manhattanLength()); + double a = 5.0; + PIMathVectorT vector; + vector.fill(a); + ASSERT_DOUBLE_EQ(SIZE * a, vector.manhattanLength()); } TEST(PIMathVectorT_Test, angleCos) { - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = 1.0; - vector[1] = 1.0; - vec[1] = 1.0; - ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleCos(vec)); + double a = 1.0; + double angle = 0.78539816339744830961566084581988; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(cos(angle), vector.angleCos(vec)); } TEST(PIMathVectorT_Test, angleSin) { - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = 1.0; - vector[1] = 1.0; - vec[1] = 1.0; - ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleSin(vec)); + double a = 1.0; + double angle = 0.78539816339744830961566084581988; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(sin(angle), vector.angleSin(vec)); } TEST(PIMathVectorT_Test, angleRad) { - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = 1.0; - vector[1] = 1.0; - vec[1] = 1.0; - ASSERT_DOUBLE_EQ(0.78539816339744830961566084581988, vector.angleRad(vec)); + double a = 1.0; + double angle = 0.78539816339744830961566084581988; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(angle, vector.angleRad(vec)); } TEST(PIMathVectorT_Test, angleDeg) { - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = 1.0; - vector[1] = 1.0; - vec[1] = 1.0; - ASSERT_DOUBLE_EQ(45.0, vector.angleDeg(vec)); + double a = 1.0; + double angle = 45.0; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(angle, vector.angleDeg(vec)); } TEST(PIMathVectorT_Test, angleElevation) { - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = 1.0; - vector[1] = 1.0; - vec[1] = 1.0; - ASSERT_DOUBLE_EQ(-45.0, vector.angleElevation(vec)); + double a = 1.0; + double angle = 45.0; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(-angle, vector.angleElevation(vec)); } TEST(PIMathVectorT_Test, projection) { - PIMathVectorT vector; - PIMathVectorT vec; - vec[0] = 1.0; - vector[0] = 1.0; - vector[1] = 1.0; + double a = 2.0; + double b = 2.0; + double res = sqrt(32.0); + PIMathVectorT vector; + PIMathVectorT vec; + vec[0] = a; + vec[2] = b; + vector[0] = a; + vector[1] = b; + vector[2] = a; auto vecProj = vector.projection(vec); - ASSERT_TRUE(vecProj == vec); + ASSERT_DOUBLE_EQ(res, vecProj[0]); + ASSERT_DOUBLE_EQ(0.0, vecProj[1]); + ASSERT_DOUBLE_EQ(res, vecProj[2]); } TEST(PIMathVectorT_Test, normalize) { - PIMathVectorT vector; - vector.fill(5.0); - ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), 5.0 / sqrt(75.0), 3u)); + double a = 5.0; + PIMathVectorT vector; + vector.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), a / sqrt(SIZE * a * a), SIZE)); } TEST(PIMathVectorT_Test, normalized) { - PIMathVectorT vector; - vector.fill(5.0); - ASSERT_TRUE(cmpVectorWithValue(vector.normalized(), 5.0 / sqrt(75.0), 3u)); + double a = 5.0; + PIMathVectorT vector; + PIMathVectorT vectorNew; + vector.fill(a); + vectorNew = vector.normalized(); + ASSERT_TRUE(cmpVectorWithValue(vectorNew, a / sqrt(SIZE * a * a), SIZE)); } TEST(PIMathVectorT_Test, cross1) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(1.72); - ASSERT_TRUE(cmpVectorWithValue(vector1.cross(vector2), 0.0, 3)); + PIMathVectorT vector1; + PIMathVectorT vector2; + double a = 5.0; + double b = 1.72; + double c = 0.0; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1.cross(vector2), c, SIZE)); } TEST(PIMathVectorT_Test, cross2) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1[0] = 1.0; - vector2[1] = 1.0; - ASSERT_TRUE(((vector1 * vector2)[0] == 0.0) && ((vector1 * vector2)[1] == 0.0) && ((vector1 * vector2)[2] == 1.0)); + PIMathVectorT vector1; + PIMathVectorT vector2; + double a = 1.0; + vector1[0] = a; + vector2[1] = a; + auto crossVec = vector1 * vector2; + ASSERT_DOUBLE_EQ(crossVec[0], 0.0); + ASSERT_DOUBLE_EQ(crossVec[1], 0.0); + ASSERT_DOUBLE_EQ(crossVec[2], a); } TEST(PIMathVectorT_Test, dot) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(5.0); - ASSERT_EQ(vector1.dot(vector2), 90.0); + double a = 6.0; + double b = 5.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_DOUBLE_EQ(vector1.dot(vector2), SIZE * a * b); } TEST(PIMathVectorT_Test, isNullTrue) { - PIMathVectorT vector; + PIMathVectorT vector; ASSERT_TRUE(vector.isNull()); } TEST(PIMathVectorT_Test, isNullFalse) { - PIMathVectorT vector; - vector[0] = 6.273; + double a = 6.273; + PIMathVectorT vector; + vector[0] = a; ASSERT_FALSE(vector.isNull()); } TEST(PIMathVectorT_Test, isOrthoTrue) { - PIMathVectorT vector; - PIMathVectorT vect; - vector[0] = 2.0; - vect[1] = 1.0; + double a = 2.0; + double b = 1.0; + PIMathVectorT vector; + PIMathVectorT vect; + vector[0] = a; + vect[1] = b; ASSERT_TRUE(vector.isOrtho(vect)); } TEST(PIMathVectorT_Test, isOrthoFalse) { - PIMathVectorT vector; - PIMathVectorT vect; - vector[0] = 2.0; - vect[0] = 5.0; - vect[1] = 1.0; + double a = 2.0; + double b = 5.0; + double c = 1.0; + PIMathVectorT vector; + PIMathVectorT vect; + vector[0] = a; + vect[0] = b; + vect[1] = c; ASSERT_FALSE(vector.isOrtho(vect)); } TEST(PIMathVectorT_Test, at) { - PIMathVectorT vector; - vector.fill(5.5); - for(uint i = 0; i < 3u; i++){ - if(vector.at(i) != 5.5){ + double a = 5.5; + PIMathVectorT vector; + vector.fill(a); + for(uint i = 0; i < SIZE; i++){ + if(vector.at(i) != a){ ASSERT_TRUE(false); } } @@ -191,184 +236,226 @@ TEST(PIMathVectorT_Test, at) { } TEST(PIMathVectorT_Test, operator_AssignmentValue) { - PIMathVectorT vector; - vector = 3.0; - ASSERT_TRUE(cmpVectorWithValue(vector, 3.0, 3)); + double a = 3.0; + PIMathVectorT vector; + vector = a; + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVectorT_Test, operator_AssignmentVector) { - PIMathVectorT vector; - PIMathVectorT vec; - vec = 5.0; + double a = 5.0; + PIMathVectorT vector; + PIMathVectorT vec; + vec = a; vector = vec; - ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3)); + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVectorT_Test, operator_EqualTrue) { - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = 5.12; - vector[1] = 7.34; - vec[0] = 5.12; - vec[1] = 7.34; + double a = 5.12; + double b = 7.34; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = b; ASSERT_TRUE(vec == vector); } TEST(PIMathVectorT_Test, operator_EqualFalse) { - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = 5.12; - vector[1] = 7.34; - vec[0] = 5.12; - vec[1] = 0.34; + double a = 5.12; + double b = 7.34; + double c = 0.34; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = c; ASSERT_FALSE(vec == vector); } TEST(PIMathVectorT_Test, operator_Not_EqualTrue) { - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = 5.12; - vector[1] = 7.34; - vec[0] = 5.12; - vec[1] = 0.34; + double a = 5.12; + double b = 7.34; + double c = 0.34; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = c; ASSERT_TRUE(vec != vector); } TEST(PIMathVectorT_Test, operator_Not_EqualFalse) { - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = 5.12; - vector[1] = 7.34; - vec[0] = 5.12; - vec[1] = 7.34; + double a = 5.12; + double b = 7.34; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = b; ASSERT_FALSE(vec != vector); } TEST(PIMathVectorT_Test, operator_Addition_Aassignment) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(1.72); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); vector1 += vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, 7.72, 3)); + ASSERT_TRUE(cmpVectorWithValue(vector1, a + b, SIZE)); } TEST(PIMathVectorT_Test, operator_Subtraction_Assignment) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(1.72); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); vector1 -= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, 4.28, 3)); + ASSERT_TRUE(cmpVectorWithValue(vector1, a - b, SIZE)); } TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentValue) { - PIMathVectorT vector1; - vector1.fill(6.0); - vector1 *= 4.0; - ASSERT_TRUE(cmpVectorWithValue(vector1, 24.0, 3)); + double a = 6.0; + double b = 4.0; + PIMathVectorT vector1; + vector1.fill(a); + vector1 *= b; + ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); } TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentVector) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(1.72); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); vector1 *= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, 10.32, 3)); + ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); } TEST(PIMathVectorT_Test, operator_Division_AssignmentValue) { - PIMathVectorT vector1; - vector1.fill(6.0); - vector1 /= 4.0; - ASSERT_TRUE(cmpVectorWithValue(vector1, 1.5, 3)); + double a = 6.0; + double b = 4.0; + PIMathVectorT vector1; + vector1.fill(a); + vector1 /= b; + ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); } TEST(PIMathVectorT_Test, operator_Division_AssignmentVector) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(1.5); + double a = 6.0; + double b = 1.5; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); vector1 /= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, 4.0, 3)); + ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); } TEST(PIMathVectorT_Test, operator_Addition) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(1.72); - ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, 7.72, 3)); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, a + b, SIZE)); } TEST(PIMathVectorT_Test, operator_Subtraction) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(1.72); - ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, 4.28, 3)); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, a - b, SIZE)); } TEST(PIMathVectorT_Test, operator_MultiplicationValue) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - ASSERT_TRUE(cmpVectorWithValue(vector1 * 4.0, 24.0, 3)); + double a = 6.0; + double b = 4.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector1 * b, a * b, SIZE)); } TEST(PIMathVectorT_Test, operator_MultiplicationVector1) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(1.72); - ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, 3)); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, SIZE)); } TEST(PIMathVectorT_Test, operator_MultiplicationVector2) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1[0] = 1.0; - vector2[1] = 1.0; - ASSERT_TRUE(((vector1 * vector2)[0] == 0.0) && ((vector1 * vector2)[1] == 0.0) && ((vector1 * vector2)[2] == 1.0)); + double a = 1.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1[0] = a; + vector2[1] = a; + ASSERT_TRUE(((vector1 * vector2)[0] < double(1E-200)) && ((vector1 * vector2)[1] < double(1E-200)) && ((vector1 * vector2)[2] - a < double(1E-200))); } TEST(PIMathVectorT_Test, operator_DivisionVal) { - PIMathVectorT vector1; - vector1.fill(6.0); - ASSERT_TRUE(cmpVectorWithValue(vector1 / 4.0, 1.5, 3)); + double a = 6.0; + double b = 4.0; + PIMathVectorT vector1; + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector1 / b, a / b, SIZE)); } TEST(PIMathVectorT_Test, operator_DivisionVector) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(4.0); - ASSERT_TRUE(cmpVectorWithValue(vector1 / vector2, 1.5, 3)); + double a = 6.0; + double b = 4.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 / vector2, a / b, SIZE)); } TEST(PIMathVectorT_Test, operator_MultiplVect) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(5.0); - ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, 30.0, 3)); + double a = 6.0; + double b = 5.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, a * b, SIZE)); } TEST(PIMathVectorT_Test, operator_absDotProduct) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(5.0); - ASSERT_TRUE(90.0 == (vector1 ^ vector2)); + double a = 6.0; + double b = 5.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_DOUBLE_EQ(vector1 ^ vector2, SIZE * a * b); } TEST(PIMathVectorT_Test, transposed) { - PIMathVectorT vector; - vector.fill(6.0); + double a = 6.0; + PIMathVectorT vector; + vector.fill(a); auto matrix = vector.transposed(); - for(int i = 0; i < size; i++){ - if(matrix[0][i] != 6.0) + for(int i = 0; i < SIZE; i++){ + if(matrix[0][i] != a) { ASSERT_TRUE(false); } @@ -377,51 +464,48 @@ TEST(PIMathVectorT_Test, transposed) { } TEST(PIMathVectorT_Test, filled) { - auto vector = PIMathVectorT::filled(6.0); - ASSERT_TRUE(cmpVectorWithValue(vector, 6.0, 3)); -} - -TEST(PIMathVectorT_Test, distToLine) { - PIMathVectorT vect; - PIMathVectorT vector1; - PIMathVectorT vector2; - vect.fill(6.0); - vector1[0] = 1.0; - vector2[1] = -1.0; - ASSERT_DOUBLE_EQ(vect.distToLine(vector1, vector2), sqrt(2.0)/2.0); + double a = 6.0; + auto vector = PIMathVectorT::filled(a); + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVectorT_Test, turnTo) { - PIMathVectorT vect; - vect.fill(6.0); + double a = 6.0; + PIMathVectorT vect; + vect.fill(a); auto vector = vect.turnTo<2u, double>(); - ASSERT_TRUE((vector.size() == 2) && (vector.size() == 2)); + ASSERT_TRUE(vector.size() == 2); } TEST(PIMathVectorT_Test, LogicalOrTrue) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(6.0); - vector2.fill(1.72); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); ASSERT_TRUE(vector1 || vector2); } TEST(PIMathVectorT_Test, LogicalOrFalse) { - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1[0] = 1.0; - vector2[1] = 1.0; + double a = 1.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1[0] = a; + vector2[1] = a; ASSERT_FALSE(vector1 || vector2); } TEST(PIMathVectorT_Test, sqrt) { - PIMathVectorT vector1; - vector1.fill(36.0); - ASSERT_TRUE(cmpVectorWithValue(sqrt(vector1), 6.0, 3u)); + double a = 36.0; + PIMathVectorT vector1; + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(sqrt(vector1), sqrt(a), SIZE)); } TEST(PIMathVectorT_Test, sqr) { - PIMathVectorT vector1; - vector1.fill(6.0); - ASSERT_TRUE(cmpVectorWithValue(sqr(vector1), 36.0, 3u)); + double a = 6.0; + PIMathVectorT vector1; + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(sqr(vector1), sqr(a), SIZE)); } -- 2.43.0 From 5da9d6e43bdd2255b7eb62779bd5a1da422c369a Mon Sep 17 00:00:00 2001 From: maakshishov Date: Fri, 25 Sep 2020 13:19:10 +0300 Subject: [PATCH 09/14] tab correction --- libs/main/math/pimathvector.h | 297 +++++++++++++++++----------------- 1 file changed, 148 insertions(+), 149 deletions(-) diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index f624b2b2..b7080a9b 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -66,44 +66,44 @@ public: PIMathVectorT(const _CVector & st, const _CVector & fn) {resize(); set(st, fn);} /** - * @brief Method that returns the number of elements contained in the vector + * @brief Method that returns the number of elements contained in the vector * * @return type uint shows number of elements in this vector */ uint size() const {return Size;} /** - * @brief Method that set this elements to value "v" + * @brief Method that set this elements to value "v" * * @param v value of which the vector is filled - * @return reference to this + * @return reference to this */ _CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} /** - * @brief Method that set this with the subtraction of two vectors + * @brief Method that set this with the subtraction of two vectors * * @param st vector of type PIMathVectorT * @param fn vector of type PIMathVectorT - * @return reference to this + * @return reference to this */ _CVector & set(const _CVector & st, const _CVector & fn) {PIMV_FOR(i, 0) c[i] = fn[i] - st[i]; return *this;} /** - * @brief Method that sets this using a vector, each element of which is added to the value of "v" + * @brief Method that sets this using a vector, each element of which is added to the value of "v" * * @param v value of which the vector is filled - * @return reference to this + * @return reference to this */ _CVector & move(const Type & v) {PIMV_FOR(i, 0) c[i] += v; return *this;} /** - * @brief Method that sets this with a vector, each element of which is added to each element of the vector "v" + * @brief Method that sets this with a vector, each element of which is added to each element of the vector "v" * * @param v vector of type PIMathVectorT - * @return reference to this + * @return reference to this */ - _CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;} + _CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;} /** * @brief Method that returns sum of the squares of all elements of the vector @@ -113,7 +113,7 @@ public: Type lengthSqr() const {Type tv(0); PIMV_FOR(i, 0) tv += (c[i] * c[i]); return tv;} /** - * @brief Method that returns a scalar physical value equal to the absolute value of vector + * @brief Method that returns a scalar physical value equal to the absolute value of vector * * @return value equal to length of a vector */ @@ -128,62 +128,62 @@ public: /** * @brief Method that returns the cos of the current vector and vector "v" - * If the vectors have different dimensions, it returns false + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return cos value of the angle between two vectors */ - Type angleCos(const _CVector & v) const {if(v.size() != Size) return false; Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} + Type angleCos(const _CVector & v) const {if(v.size() != Size) return false; Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} /** - * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements. - * If the vectors have different dimensions, it returns false - * + * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements. + * If the vectors have different dimensions, it returns false + * * @param v vector of type PIMathVectorT * @return sin value of the angle between two vector */ - Type angleSin(const _CVector & v) const {if(v.size() != Size) return false; Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} + Type angleSin(const _CVector & v) const {if(v.size() != Size) return false; Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Rad. - * If the vectors have different dimensions, it returns false + * @brief Method that returns the angle between of the current vector and vector "v" in Rad. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Rad */ - Type angleRad(const _CVector & v) const {if(v.size() != Size) return false; return acos(angleCos(v));} + Type angleRad(const _CVector & v) const {if(v.size() != Size) return false; return acos(angleCos(v));} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Deg. - * If the vectors have different dimensions, it returns false + * @brief Method that returns the angle between of the current vector and vector "v" in Deg. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Deg */ - Type angleDeg(const _CVector & v) const {if(v.size() != Size) return false; return toDeg(acos(angleCos(v)));} + Type angleDeg(const _CVector & v) const {if(v.size() != Size) return false; return toDeg(acos(angleCos(v)));} /** - * @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg. - * If the vectors have different dimensions, it returns false + * @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return value of the angle elevation between two vectors in Deg */ - Type angleElevation(const _CVector & v) const {if(v.size() != Size) return false; _CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;} + Type angleElevation(const _CVector & v) const {if(v.size() != Size) return false; _CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;} /** - * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v". - * If the vectors have different dimensions, it returns this without changing anything + * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v". + * If the vectors have different dimensions, it returns this without changing anything * * @param v vector of type PIMathVectorT * @return vector of type PIMathVectorT equal to the projection of the current vector onto the vector "v" */ - _CVector projection(const _CVector & v) {if(v.size() != Size) return _CVector(*this); Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} + _CVector projection(const _CVector & v) {if(v.size() != Size) return _CVector(*this); Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} /** - * @brief Method that returns this normalized vector + * @brief Method that returns this normalized vector * - * @return reference to this + * @return reference to this */ _CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;} @@ -218,13 +218,12 @@ public: bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;} /** - * @brief Method which checks if current vector is orthogonal to vector "v". - * If the vectors have different dimensions, it returns false + * @brief Method which checks if current vector is orthogonal to vector "v". + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT - * @return true if vectors are orthogonal, else false - */ - bool isOrtho(const _CVector & v) const {if(v.size() != Size) return false; return ((*this) ^ v) == Type(0);} + * @return true if vectors are orthogonal, else fal */ + bool isOrtho(const _CVector & v) const {if(v.size() != Size) return false; return ((*this) ^ v) == Type(0);} /** * @brief Read-only access to elements reference by index of the vector element "index" @@ -249,10 +248,10 @@ public: * @param index is the index of necessary element * @return element of vector */ - const Type & operator [](uint index) const {return c[index];} + const Type & operator [](uint index) const {return c[index];} /** - * @brief Vector assignment to vector "v" of type PIMathVectorT + * @brief Vector assignment to vector "v" of type PIMathVectorT * * @param v vector for the assigment * @return vector equal to vector "v" @@ -260,12 +259,12 @@ public: _CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;} /** - * @brief Assignment operation. All vector values ​​become equal to "v" + * @brief Assignment operation. All vector values ​​become equal to "v" * * @param v value for the assigment - * @return reference to this + * @return reference to this */ - _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} + _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} /** * @brief Compare with vector "v" @@ -284,72 +283,72 @@ public: bool operator !=(const _CVector & v) const {return !(*this == v);} /** - * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the addition assigment */ - void operator +=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] += v[i];} + void operator +=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] += v[i];} /** - * @brief Subtraction assignmentthis vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Subtraction assignmentthis vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the subtraction assigment */ - void operator -=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] -= v[i];} + void operator -=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] -= v[i];} /** - * @brief Multiplication assignment this vector with value "v" + * @brief Multiplication assignment this vector with value "v" * * @param v value for the multiplication assigment */ void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} /** - * @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the multiplication assigment */ - void operator *=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] *= v[i];} + void operator *=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] *= v[i];} /** - * @brief Division assignment with this vector value "v" + * @brief Division assignment with this vector value "v" * * @param v value for the division assigment */ void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;} /** - * @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the division assigment */ - void operator /=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] /= v[i];} + void operator /=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] /= v[i];} /** - * @brief Vector substraction this vector + * @brief Vector substraction this vector * * @return the result of vector substraction */ _CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;} /** - * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything + * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything * - * @param v is vector term - * @return the result of vector addition + * @param v is vector term + * @return the result of vector addition */ - _CVector operator +(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} + _CVector operator +(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} /** - * @brief Vector substraction this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything + * @brief Vector substraction this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything * - * @param v is vector term + * @param v is vector term * @return the result of vector substraction */ - _CVector operator -(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} + _CVector operator -(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} /** - * @brief Vector multiplication this vector with value "v" + * @brief Vector multiplication this vector with value "v" * * @param v is value factor * @return the result of vector multiplication @@ -357,7 +356,7 @@ public: _CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;} /** - * @brief Vector division this vector with value "v" + * @brief Vector division this vector with value "v" * * @param v is value divider * @return the result of vector division @@ -365,12 +364,12 @@ public: _CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;} /** - * @brief Vector division this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything + * @brief Vector division this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything * * @param v is vector divider * @return the result of vector division */ - _CVector operator /(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;} + _CVector operator /(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;} /** * @brief Cross product of two vectors. Works only with vector containing three elements, otherwise returns current vector @@ -381,20 +380,20 @@ public: _CVector operator *(const _CVector & v) const {if (Size != 3) return _CVector(); _CVector tv; tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} /** - * @brief Elementwise assignment of multiplication of two vectors. If the vectors have different dimensions, it returns this without changing anything + * @brief Elementwise assignment of multiplication of two vectors. If the vectors have different dimensions, it returns this without changing anything * * @param v is vector for multiplication * @return resulting vector */ - _CVector operator &(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} + _CVector operator &(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} /** - * @brief Absolute value of the dot product. If the vectors have different dimensions, it returns false + * @brief Absolute value of the dot product. If the vectors have different dimensions, it returns false * * @param v is vector for dot product * @return resulting vector */ - Type operator ^(const _CVector & v) const {if(v.size() != Size) return false; Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} + Type operator ^(const _CVector & v) const {if(v.size() != Size) return false; Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} PIMathMatrixT<1, Size, Type> transposed() const { PIMathMatrixT<1, Size, Type> ret; @@ -411,7 +410,7 @@ public: PIMathVectorT turnTo() const {PIMathVectorT tv; uint sz = piMin(Size, Size1); for (uint i = 0; i < sz; ++i) tv[i] = c[i]; return tv;} /** - * @brief Creates a vector each element of which is equal to value "v" + * @brief Creates a vector each element of which is equal to value "v" * * @param v this value fills the cells of the vector * @return filled vector of type PIMathVectorT @@ -581,11 +580,11 @@ public: */ PIMathVector(const _CVector & st, const _CVector & fn) {c.resize(st.size()); PIMV_FOR(i, 0) c[i] = fn[i] - st[i];} - /** - * @brief Method that returns the number of elements contained in the vector - * - * @return type uint shows number of elements in this vector - */ + /** + * @brief Method that returns the number of elements contained in the vector + * + * @return type uint shows number of elements in this vector + */ uint size() const {return c.size();} /** @@ -593,7 +592,7 @@ public: * * @param size new vector dimension * @param new_value value with which the vector is filled - * @return reference to this + * @return reference to this */ _CVector & resize(uint size, const Type & new_value = Type()) {c.resize(size, new_value); return *this;} @@ -606,38 +605,38 @@ public: */ _CVector resized(uint size, const Type & new_value = Type()) {_CVector tv = _CVector(*this); tv.resize(size, new_value); return tv;} - /** - * @brief Method that set this elements to value "v" - * - * @param v value of which the vector is filled - * @return reference to this - */ + /** + * @brief Method that set this elements to value "v" + * + * @param v value of which the vector is filled + * @return reference to this + */ _CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} - /** - * @brief Method that sets this using a vector, each element of which is added to the value of "v" - * - * @param v value of which the vector is filled - * @return reference to this - */ + /** + * @brief Method that sets this using a vector, each element of which is added to the value of "v" + * + * @param v value of which the vector is filled + * @return reference to this + */ _CVector & move(const Type & v) {PIMV_FOR(i, 0) c[i] += v; return *this;} - /** - * @brief Method that sets this with a vector, each element of which is added to each element of the vector "v". - * If the vectors have different dimensions, it returns this without changing anything - * - * @param v vector of type PIMathVectorT - * @return reference to this - */ - _CVector & move(const _CVector & v) {if(v.size() != c.size()) return *this; PIMV_FOR(i, 0) c[i] += v[i]; return *this;} + /** + * @brief Method that sets this with a vector, each element of which is added to each element of the vector "v". + * If the vectors have different dimensions, it returns this without changing anything + * + * @param v vector of type PIMathVectorT + * @return reference to this + */ + _CVector & move(const _CVector & v) {if(v.size() != c.size()) return *this; PIMV_FOR(i, 0) c[i] += v[i]; return *this;} /** - * @brief Method that replaces two elements in this vector by indices. You cannot use an index larger than the number vector dimension, + * @brief Method that replaces two elements in this vector by indices. You cannot use an index larger than the number vector dimension, * otherwise there will be "undefined behavior" * * @param fe index of the first element * @param se index of the second element - * @return reference to this + * @return reference to this */ _CVector & swap(uint fe, uint se) {piSwap(c[fe], c[se]); return *this;} @@ -648,11 +647,11 @@ public: */ Type lengthSqr() const {Type tv(0); PIMV_FOR(i, 0) tv += (c[i] * c[i]); return tv;} - /** - * @brief Method that returns a scalar physical value equal to the absolute value of vector - * - * @return value equal to length of a vector - */ + /** + * @brief Method that returns a scalar physical value equal to the absolute value of vector + * + * @return value equal to length of a vector + */ Type length() const {return sqrt(lengthSqr());} /** @@ -663,48 +662,48 @@ public: Type manhattanLength() const {Type tv(0); PIMV_FOR(i, 0) tv += fabs(c[i]); return tv;} /** - * @brief Method that returns the cos of the current vector and vector "v". If the vectors have different dimensions, it returns false + * @brief Method that returns the cos of the current vector and vector "v". If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVector * @return cos value of the angle between two vectors */ - Type angleCos(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} + Type angleCos(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} /** - * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements. - * If the vectors have different dimensions, it returns false + * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVector * @return sin value of the angle between two vector */ - Type angleSin(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} + Type angleSin(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Rad. - * If the vectors have different dimensions, it returns false + * @brief Method that returns the angle between of the current vector and vector "v" in Rad. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVector * @return value of the angle between two vectors in Rad */ - Type angleRad(const _CVector & v) const {if(v.size() != c.size()) return false; return acos(angleCos(v));} + Type angleRad(const _CVector & v) const {if(v.size() != c.size()) return false; return acos(angleCos(v));} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Deg. - * If the vectors have different dimensions, it returns false + * @brief Method that returns the angle between of the current vector and vector "v" in Deg. + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Deg */ - Type angleDeg(const _CVector & v) const {if(v.size() != c.size()) return false; return toDeg(acos(angleCos(v)));} + Type angleDeg(const _CVector & v) const {if(v.size() != c.size()) return false; return toDeg(acos(angleCos(v)));} /** - * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v". - * If the vectors have different dimensions, it returns this without changing anything + * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v". + * If the vectors have different dimensions, it returns this without changing anything * * @param v vector of type PIMathVector * @return vector of type PIMathVector equal to the projection of the current vector onto the vector "v" */ - _CVector projection(const _CVector & v) {if(v.size() != c.size()) return *this; Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} + _CVector projection(const _CVector & v) {if(v.size() != c.size()) return *this; Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} /** * @brief Method that returns a normalized vector @@ -735,13 +734,13 @@ public: bool isValid() const {return !c.isEmpty();} /** - * @brief Method which checks if current vector is orthogonal to vector "v". - * If the vectors have different dimensions, it returns false + * @brief Method which checks if current vector is orthogonal to vector "v". + * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVector * @return true if vectors are orthogonal, else false */ - bool isOrtho(const _CVector & v) const {if(v.size() != c.size()) return false; return ((*this) ^ v) == Type(0);} + bool isOrtho(const _CVector & v) const {if(v.size() != c.size()) return false; return ((*this) ^ v) == Type(0);} /** * @brief Read-only access to elements reference by index of the vector element "index" @@ -766,22 +765,22 @@ public: * @param index is the index of necessary element * @return element of vector */ - const Type & operator [](uint index) const {return c[index];} + const Type & operator [](uint index) const {return c[index];} /** * @brief Vector assignment to vector "v" of type PIMathVector - * If the vectors have different dimensions, it returns this without changing anything + * If the vectors have different dimensions, it returns this without changing anything * * @param v vector for the assigment - * @return reference to this + * @return reference to this */ - _CVector & operator =(const _CVector & v) {if(v.size() != c.size()) return *this; c = v.c; return *this;} + _CVector & operator =(const _CVector & v) {if(v.size() != c.size()) return *this; c = v.c; return *this;} /** * @brief Vector assignment to value "v" * * @param v value for the assigment - * @return reference to this + * @return reference to this */ _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} @@ -791,7 +790,7 @@ public: * @param v vector for the compare * @return if vectors are equal true, else false */ - bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if ((c[i] != v[i]) || (v.size() != c.size())) return false; return true;} + bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if ((c[i] != v[i]) || (v.size() != c.size())) return false; return true;} /** * @brief Compare with vector "v" @@ -802,72 +801,72 @@ public: bool operator !=(const _CVector & v) const {return !(*this == v);} /** - * @brief Addition assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Addition assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the addition assigment */ - void operator +=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] += v[i];} + void operator +=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] += v[i];} /** - * @brief Subtraction assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Subtraction assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the subtraction assigment */ - void operator -=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] -= v[i];} + void operator -=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] -= v[i];} /** - * @brief Multiplication assignment this vector with value "v" + * @brief Multiplication assignment this vector with value "v" * * @param v value for the multiplication assigment */ void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} /** - * @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the multiplication assigment */ - void operator *=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] *= v[i];} + void operator *=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] *= v[i];} /** - * @brief Division assignment this vector with value "v" + * @brief Division assignment this vector with value "v" * * @param v value for the division assigment */ void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;} /** - * @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the division assigment */ - void operator /=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] /= v[i];} + void operator /=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] /= v[i];} /** - * @brief Vector substraction this vector + * @brief Vector substraction this vector * * @return the result of vector substraction */ _CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;} /** - * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything + * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything * - * @param v is vector term + * @param v is vector term * @return the result of matrix addition */ - _CVector operator +(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} + _CVector operator +(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} /** - * @brief Vector substraction this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything + * @brief Vector substraction this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything * - * @param v is vector term + * @param v is vector term * @return the result of vector substraction */ - _CVector operator -(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} + _CVector operator -(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} /** - * @brief Vector multiplicationthis vector with value "v" + * @brief Vector multiplicationthis vector with value "v" * * @param v is value factor * @return the result of vector multiplication @@ -875,7 +874,7 @@ public: _CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;} /** - * @brief Vector division this vector with value "v" + * @brief Vector division this vector with value "v" * * @param v is value divider * @return the result of vector division @@ -888,23 +887,23 @@ public: * @param v is vector for cross product * @return the result vector equal of cross product */ - _CVector operator *(const _CVector & v) const {if ((c.size() != 3) || (v.size() != 3)) return _CVector(); _CVector tv(3); tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} + _CVector operator *(const _CVector & v) const {if ((c.size() != 3) || (v.size() != 3)) return _CVector(); _CVector tv(3); tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} /** - * @brief Elementwise assignment of multiplication of two vectors. If the vectors have different dimensions, it returns this without changing anything + * @brief Elementwise assignment of multiplication of two vectors. If the vectors have different dimensions, it returns this without changing anything * * @param v is vector for multiplication * @return resulting vector */ - _CVector operator &(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} + _CVector operator &(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} /** - * @brief Value of the dot product. If the vectors have different dimensions, it returns false + * @brief Value of the dot product. If the vectors have different dimensions, it returns false * * @param v is vector for dot product - * @return resulting value + * @return resulting value */ - Type operator ^(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} + Type operator ^(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} /** * @brief Converts PIMathVector to PIVector type -- 2.43.0 From 8bc421dc3061cb2a62c978538ca41172c4ddea98 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Fri, 25 Sep 2020 13:42:09 +0300 Subject: [PATCH 10/14] PIMathMatrix.h documentation correction --- libs/main/math/pimathmatrix.h | 55 +++++++++++++++++------------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 7d42fbc3..cc0eacb8 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -235,12 +235,12 @@ public: } /** - * @brief Set the selected column in matrix. + * @brief Set the selected column in this matrix. * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected column * @param v is a vector of the type _CMCol that needs to fill the column - * @return matrix type _CMatrix + * @return reference to this */ _CMatrix &setCol(uint index, const _CMCol &v) { PIMM_FOR_R(i) m[i][index] = v[i]; @@ -248,12 +248,12 @@ public: } /** - * @brief Set the selected row in matrix + * @brief Set the selected row in this matrix * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected row * @param v is a vector of the type _CMCol that needs to fill the row - * @return matrix type _CMatrix + * @return reference to this */ _CMatrix &setRow(uint index, const _CMRow &v) { PIMM_FOR_C(i) m[index][i] = v[i]; @@ -261,12 +261,12 @@ public: } /** - * @brief Method which changes selected rows in a matrix. + * @brief Method which changes selected rows in this matrix. * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param r0 is the number of the first selected row * @param r1 is the number of the second selected row - * @return matrix type _CMatrix + * @return reference to this */ _CMatrix &swapRows(uint r0, uint r1) { Type t; @@ -279,12 +279,12 @@ public: } /** - * @brief Method which changes selected columns in a matrix. + * @brief Method which changes selected columns in this matrix. * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param c0 is the number of the first selected column * @param c1 is the number of the second selected column - * @return matrix type _CMatrix + * @return reference to this */ _CMatrix &swapCols(uint c0, uint c1) { Type t; @@ -297,10 +297,10 @@ public: } /** - * @brief Method which fills the matrix with selected value + * @brief Method which set this matrix elements with selected value * * @param v is a parameter the type and value of which is selected and later filled into the matrix - * @return filled matrix type _CMatrix + * @return reference to this */ _CMatrix &fill(const Type &v) { PIMM_FOR_WB(r, c) m[r][c] = v; @@ -374,7 +374,7 @@ public: * @brief Matrix assignment to matrix "sm" * * @param sm matrix for the assigment - * @return matrix equal with sm + * @return this matrix equal with sm */ _CMatrix &operator=(const _CMatrix &sm) { memcpy(m, sm.m, sizeof(Type) * Cols * Rows); @@ -512,7 +512,7 @@ public: * @brief Transforming matrix to upper triangular. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly - * @return copy of transformed upper triangular matrix + * @return reference to this of transformed upper triangular matrix */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (Cols != Rows) { @@ -554,8 +554,7 @@ public: /** * @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix * - * @param ok is a parameter with which we can find out if the method worked correctly - * @return copy of inverted matrix + * @param ok is a parameter with which we can find out if the method worked correct * @return reference to this inverted matrix */ _CMatrix &invert(bool *ok = 0) { static_assert(Cols == Rows, "Only square matrix invertable"); @@ -941,12 +940,12 @@ public: static _CMatrix matrixCol(const PIMathVector &val) { return _CMatrix(1, val.size(), val.toVector()); } /** - * @brief Set the selected column in matrix. If there are more elements of the vector than elements in the column of the matrix - * or index larger than the number of columns otherwise there will be "undefined behavior" + * @brief Set the selected column in this matrix. If there are more elements of the vector than elements in the column of the matrix + * or index larger than the number of columns otherwise there will be "undefined behavior" * * @param index is the number of the selected column * @param v is a vector of the type _CMCol that needs to fill the column - * @return matrix type _CMatrix + * @return reference to this */ _CMatrix &setCol(uint index, const _CMCol &v) { PIMM_FOR_R(i) _V2D::element(i, index) = v[i]; @@ -954,11 +953,11 @@ public: } /** - * @brief Set the selected row in matrix. If there are more elements of the vector than elements in the row of the matrix, + * @brief Set the selected row in this matrix. If there are more elements of the vector than elements in the row of the matrix, * or index larger than the number of rows otherwise there will be "undefined behavior" * @param index is the number of the selected row * @param v is a vector of the type _CMCol that needs to fill the row - * @return matrix type _CMatrix + * @return reference to this */ _CMatrix &setRow(uint index, const _CMCol &v) { PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; @@ -966,12 +965,12 @@ public: } /** - * @brief Method which replace selected columns in a matrix. You cannot use an index larger than the number of columns, + * @brief Method which replace selected columns in this matrix. You cannot use an index larger than the number of columns, * otherwise there will be "undefined behavior" * * @param r0 is the number of the first selected row * @param r1 is the number of the second selected row - * @return matrix type _CMatrix + * @return reference to this */ _CMatrix &swapCols(uint r0, uint r1) { PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); } @@ -979,12 +978,12 @@ public: } /** - * @brief Method which replace selected rows in a matrix. You cannot use an index larger than the number of rows, + * @brief Method which replace selected rows in this matrix. You cannot use an index larger than the number of rows, * otherwise there will be "undefined behavior" * * @param c0 is the number of the first selected row * @param c1 is the number of the second selected row - * @return matrix type _CMatrix + * @return reference to this */ _CMatrix &swapRows(uint c0, uint c1) { PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); } @@ -992,10 +991,10 @@ public: } /** - * @brief Method which fills the matrix with selected value + * @brief Method which set this matrix elements with selected value * * @param v is a parameter the type and value of which is selected and later filled into the matrix - * @return filled matrix type _CMatrix + * @return reference to this */ _CMatrix &fill(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] = v; @@ -1040,7 +1039,7 @@ public: * @brief Matrix assignment to matrix "v" * * @param v matrix for the assigment - * @return matrix equal with v + * @return reference to this matrix equal with v */ _CMatrix &operator=(const PIVector > &v) { *this = _CMatrix(v); @@ -1197,7 +1196,7 @@ public: * @brief Transforming matrix to upper triangular. Works only with square matrix, nonzero matrices and invertible matrix * * @param ok is a parameter with which we can find out if the method worked correctly - * @return copy of transformed upper triangular matrix + * @return this transformed upper triangular matrix */ _CMatrix &toUpperTriangular(bool *ok = 0) { if (!isSquare()) { @@ -1241,7 +1240,7 @@ public: * * @param ok is a parameter with which we can find out if the method worked correctly * @param sv is a vector multiplier - * @return copy of inverted matrix + * @return this inverted matrix */ _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { if (!isSquare()) { -- 2.43.0 From e16243d64b7290f7f252c81a0c1fcc69a00ec0cd Mon Sep 17 00:00:00 2001 From: maakshishov Date: Thu, 1 Oct 2020 15:34:24 +0300 Subject: [PATCH 11/14] PIMathMatrix.h documentation correction --- libs/main/math/pimathmatrix.h | 138 ++++++++++++++++------------------ libs/main/math/pimathvector.h | 67 ++++++++--------- 2 files changed, 94 insertions(+), 111 deletions(-) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index cc0eacb8..be972620 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -29,10 +29,10 @@ #include "pimathcomplex.h" /** -* @brief Inline funtion of compare with zero different types +* @brief Floating point number specific comparison between value of matrix passed as parameter and zero * -* @param v is input parameter of type T -* @return true if zero, false if not zero +* @param v floating point parameter for comparison +* @return true if v in locality of zero, otherwise false */ template inline bool _PIMathMatrixNullCompare(const T v) { @@ -41,10 +41,10 @@ inline bool _PIMathMatrixNullCompare(const T v) { } /** -* @brief Inline funtion of compare with zero colmplexf type +* @brief Floating point number specific comparison between parameter value of matrix of complexf type and zero * * @param v is input parameter of type colmplexf -* @return true if zero, false if not zero +* @return true if absolute value of v in locality of zero, otherwise false */ template<> inline bool _PIMathMatrixNullCompare(const complexf v) { @@ -52,10 +52,10 @@ inline bool _PIMathMatrixNullCompare(const complexf v) { } /** -* @brief Inline funtion of compare with zero complexd type +* @brief Floating point number specific comparison between parameter value of matrix of complexd type and zero * * @param v is input parameter of type colmplexd -* @return true if zero, false if not zero +* @return true if absolute value of v in locality of zero, otherwise false */ template<> inline bool _PIMathMatrixNullCompare(const complexd v) { @@ -120,10 +120,10 @@ public: } /** - * @brief Creates a matrix that is filled with elements + * @brief Creates a matrix and sets it with elements equal to value "v" * * @param v is a parameter the type and value of which is selected and later filled into the matrix - * @return filled matrix of type PIMathMatrixT + * @return filled matrix of type PIMathMatrixT equal to "v" */ static _CMatrix filled(const Type &v) { _CMatrix tm; @@ -145,7 +145,7 @@ public: * else return default construction of PIMathMatrixT * * @param angle is the angle of rotation of the matrix along the X axis - * @return rotated matrix + * @return rotated matrix along the X axis */ static _CMatrix rotationX(double angle) { return _CMatrix(); } @@ -154,7 +154,7 @@ public: * else return default construction of PIMathMatrixT * * @param angle is the angle of rotation of the matrix along the Y axis - * @return rotated matrix + * @return rotated matrix along the Y axis */ static _CMatrix rotationY(double angle) { return _CMatrix(); } @@ -163,7 +163,7 @@ public: * else return default construction of PIMathMatrixT * * @param angle is the angle of rotation of the matrix along the Z axis - * @return rotated matrix + * @return rotated matrix along the Z axis */ static _CMatrix rotationZ(double angle) { return _CMatrix(); } @@ -172,7 +172,7 @@ public: * else return default construction of PIMathMatrixT * * @param factor is the value of scaling by X axis - * @return rotated matrix + * @return rotated matrix along the axis X */ static _CMatrix scaleX(double factor) { return _CMatrix(); } @@ -181,7 +181,7 @@ public: * else return default construction of PIMathMatrixT * * @param factor is the value of scaling by Y axis - * @return rotated matrix + * @return rotated matrix along the axis Y */ static _CMatrix scaleY(double factor) { return _CMatrix(); } @@ -190,26 +190,26 @@ public: * else return default construction of PIMathMatrixT * * @param factor is the value of scaling by Z axis - * @return rotated matrix + * @return rotated matrix along the axis Z */ static _CMatrix scaleZ(double factor) { return _CMatrix(); } /** - * @brief Method which returns number of columns in matrix + * @brief Method which returns number of columns in this matrix * - * @return type uint shows number of columns + * @return number of columns */ uint cols() const { return Cols; } /** - * @brief Method which returns number of rows in matrix + * @brief Method which returns number of rows in this matrix * - * @return type uint shows number of rows + * @return number of rows */ uint rows() const { return Rows; } /** - * @brief Method which returns the selected column in PIMathVectorT format. + * @brief Method which returns the selected column of this matrix in PIMathVectorT format. * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected column @@ -222,7 +222,7 @@ public: } /** - * @brief Method which returns the selected row in PIMathVectorT format + * @brief Method which returns the selected row of this matrix in PIMathVectorT format. * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param index is the number of the selected row @@ -261,7 +261,7 @@ public: } /** - * @brief Method which changes selected rows in this matrix. + * @brief Method which permutes the values ​​of two selected rows among themselves in this matrix. * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param r0 is the number of the first selected row @@ -279,7 +279,7 @@ public: } /** - * @brief Method which changes selected columns in this matrix. + * @brief Method which permutes the values ​​of two selected columns among themselves in this matrix. * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param c0 is the number of the first selected column @@ -308,7 +308,7 @@ public: } /** - * @brief Method which checks if matrix is square + * @brief Method which checks if this matrix is square * * @return true if matrix is square, else false */ @@ -335,24 +335,14 @@ public: } /** - * @brief Full access to elements reference by row "row" and col "col". + * @brief Read-only access to elements reference by row "row" and column "col". * If you enter an index out of the border of the matrix there will be "undefined behavior" * * @param row is a parameter that shows the row number of the matrix of the selected element * @param col is a parameter that shows the column number of the matrix of the selected element - * @return reference to element of matrix by row "row" and col "col" + * @return reference to element of this matrix */ - Type &at(uint row, uint col) { return m[row][col]; } - - /** - * @brief Full access to element by row "row" and col "col". - * If you enter an index out of the border of the matrix there will be "undefined behavior" - * - * @param row is a parameter that shows the row number of the matrix of the selected element - * @param col is a parameter that shows the column number of the matrix of the selected element - * @return element of matrix by row "row" and col "col" - */ - Type at(uint row, uint col) const { return m[row][col]; } + const Type &at(uint row, uint col) { return m[row][col]; } /** * @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix there will be "undefined behavior" @@ -371,10 +361,10 @@ public: const Type *operator[](uint row) const { return m[row]; } /** - * @brief Matrix assignment to matrix "sm" + * @brief Assignment all elements of this matrix with all elements of matrix "sm" * - * @param sm matrix for the assigment - * @return this matrix equal with sm + * @param sm matrix used for the assignment + * @return matrix whose each element is equal to each element of the matrix "sm" */ _CMatrix &operator=(const _CMatrix &sm) { memcpy(m, sm.m, sizeof(Type) * Cols * Rows); @@ -382,9 +372,9 @@ public: } /** - * @brief Compare with matrix "sm" + * @brief Compare all elements of this matrix with all elements of matrix "sm" * - * @param sm matrix for the compare + * @param sm matrix used for the compare * @return if matrices are equal true, else false */ bool operator==(const _CMatrix &sm) const { @@ -393,36 +383,36 @@ public: } /** - * @brief Compare with matrix "sm" + * @brief Compare all elements of this matrix with all elements of matrix "sm" * - * @param sm matrix for the compare + * @param sm matrix used for the compare * @return if matrices are not equal true, else false */ bool operator!=(const _CMatrix &sm) const { return !(*this == sm); } /** - * @brief Addition assignment with matrix "sm" + * @brief Addition all elements of this matrix with all elements matrix "sm" * * @param sm matrix for the addition assigment */ void operator+=(const _CMatrix &sm) { PIMM_FOR_WB(r, c) m[r][c] += sm.m[r][c]; } /** - * @brief Subtraction assignment with matrix "sm" + * @brief Subtraction all elements of this matrix with all elements matrix "sm" * * @param sm matrix for the subtraction assigment */ void operator-=(const _CMatrix &sm) { PIMM_FOR_WB(r, c) m[r][c] -= sm.m[r][c]; } /** - * @brief Multiplication assignment with value "v" + * @brief Multiplication all elements of this matrix with value "v" * * @param v value for the multiplication assigment */ void operator*=(const Type &v) { PIMM_FOR_WB(r, c) m[r][c] *= v; } /** - * @brief Division assignment with value "v" + * @brief Division all elements of this matrix with value "v" * * @param v value for the division assigment */ @@ -440,7 +430,7 @@ public: } /** - * @brief Matrix addition + * @brief Addition all elements of this matrix with all elements of matrix "sm" * * @param sm is matrix term * @return the result of matrix addition @@ -452,7 +442,7 @@ public: } /** - * @brief Matrix substraction + * @brief Substraction all elements of this matrix with all elements of matrix "sm" * * @param sm is matrix subtractor * @return the result of matrix substraction @@ -464,7 +454,7 @@ public: } /** - * @brief Matrix multiplication + * @brief Multiplication all elements of this matrix with value "v" * * @param v is value factor * @return the result of matrix multiplication @@ -476,7 +466,7 @@ public: } /** - * @brief Matrix division + * @brief Division all elements of this matrix with value "v" * * @param v is value divider * @return the result of matrix division @@ -731,11 +721,11 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT inline PICout operator<<(PICout s, const PIMathMatrixT &m) { @@ -965,7 +955,7 @@ public: } /** - * @brief Method which replace selected columns in this matrix. You cannot use an index larger than the number of columns, + * @brief Method which permutes the values ​​of two selected columns among themselves in this matrix. You cannot use an index larger than the number of columns, * otherwise there will be "undefined behavior" * * @param r0 is the number of the first selected row @@ -978,7 +968,7 @@ public: } /** - * @brief Method which replace selected rows in this matrix. You cannot use an index larger than the number of rows, + * @briefMethod which permutes the values ​​of two selected rows among themselves in this matrix. You cannot use an index larger than the number of rows, * otherwise there will be "undefined behavior" * * @param c0 is the number of the first selected row @@ -1036,9 +1026,9 @@ public: bool isValid() const { return !PIVector2D::isEmpty(); } /** - * @brief Matrix assignment to matrix "v" + * @brief Assignment all elements of this matrix with all elements of matrix "sm" * - * @param v matrix for the assigment + * @param v matrix used for the assigment * @return reference to this matrix equal with v */ _CMatrix &operator=(const PIVector > &v) { @@ -1047,9 +1037,9 @@ public: } /** - * @brief Compare with matrix "sm" + * @brief Compare all elements of this matrix with all elements of matrix "sm" * - * @param sm matrix for the compare + * @param sm matrix used for the compare * @return if matrices are equal true, else false */ bool operator==(const _CMatrix &sm) const { @@ -1058,36 +1048,36 @@ public: } /** - * @brief Compare with matrix "sm" + * @brief Compare all elements of this matrix with all elements of matrix "sm" * - * @param sm matrix for the compare + * @param sm matrix used for the compare * @return if matrices are not equal true, else false */ bool operator!=(const _CMatrix &sm) const { return !(*this == sm); } /** - * @brief Addition assignment with matrix "sm" + * @brief Addition all elements of this matrix with all elements matrix "sm" * * @param sm matrix for the addition assigment */ void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; } /** - * @brief Subtraction assignment with matrix "sm" + * @brief Subtraction all elements of this matrix with all elements matrix "sm" * * @param sm matrix for the subtraction assigment */ void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; } /** - * @brief Multiplication assignment with value "v" + * @brief Multiplication all elements of this matrix with value "v" * * @param v value for the multiplication assigment */ void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; } /** - * @brief Division assignment with value "v" + * @brief Division all elements of this matrix with value "v" * * @param v value for the division assigment */ @@ -1105,7 +1095,7 @@ public: } /** - * @brief Matrix addition + * @brief Addition all elements of this matrix with all elements of matrix "sm" * * @param sm is matrix term * @return the result of matrix addition @@ -1117,7 +1107,7 @@ public: } /** - * @brief Matrix subtraction + * @brief Substraction all elements of this matrix with all elements of matrix "sm" * * @param sm is matrix subtractor * @return the result of matrix subtraction @@ -1129,7 +1119,7 @@ public: } /** - * @brief Matrix multiplication + * @brief Multiplication all elements of this matrix with value "v" * * @param v is value factor * @return the result of matrix multiplication @@ -1141,7 +1131,7 @@ public: } /** - * @brief Matrix division + * @brief Division all elements of this matrix with value "v" * * @param v is value divider * @return the result of matrix division @@ -1328,7 +1318,7 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix & m #endif /** -* @brief Inline operator for outputting the matrix to the console +* @brief Outputting the matrix to the console * * @param s PICout type * @param the matrix type PIMathMatrix that we print to the console @@ -1349,7 +1339,7 @@ inline PICout operator<<(PICout s, const PIMathMatrix &m) { } /** -* @brief Inline operator for serializing a matrix into a PIByteArray +* @brief Serializing a matrix into a PIByteArray * * @param s PIByteArray type * @param v PIMathMatrix type @@ -1362,7 +1352,7 @@ inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &v) { } /** -* @brief Inline operator to deserialize matrix from PIByteArray +* @brief Deserializing matrix from PIByteArray * * @param s PIByteArray type * @param v PIMathMatrix type diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index b7080a9b..d9b84b5e 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -128,57 +128,51 @@ public: /** * @brief Method that returns the cos of the current vector and vector "v" - * If the vectors have different dimensions, it returns false * * @param v vector of type PIMathVectorT * @return cos value of the angle between two vectors */ - Type angleCos(const _CVector & v) const {if(v.size() != Size) return false; Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} + Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} /** - * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements. - * If the vectors have different dimensions, it returns false + * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements * * @param v vector of type PIMathVectorT * @return sin value of the angle between two vector */ - Type angleSin(const _CVector & v) const {if(v.size() != Size) return false; Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} + Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Rad. - * If the vectors have different dimensions, it returns false + * @brief Method that returns the angle between of the current vector and vector "v" in Rad * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Rad */ - Type angleRad(const _CVector & v) const {if(v.size() != Size) return false; return acos(angleCos(v));} + Type angleRad(const _CVector & v) const {return acos(angleCos(v));} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Deg. - * If the vectors have different dimensions, it returns false + * @brief Method that returns the angle between of the current vector and vector "v" in Deg * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Deg */ - Type angleDeg(const _CVector & v) const {if(v.size() != Size) return false; return toDeg(acos(angleCos(v)));} + Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));} /** - * @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg. - * If the vectors have different dimensions, it returns false + * @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg * * @param v vector of type PIMathVectorT * @return value of the angle elevation between two vectors in Deg */ - Type angleElevation(const _CVector & v) const {if(v.size() != Size) return false; _CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;} + Type angleElevation(const _CVector & v) const {_CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;} /** * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v". - * If the vectors have different dimensions, it returns this without changing anything * * @param v vector of type PIMathVectorT * @return vector of type PIMathVectorT equal to the projection of the current vector onto the vector "v" */ - _CVector projection(const _CVector & v) {if(v.size() != Size) return _CVector(*this); Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} + _CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} /** * @brief Method that returns this normalized vector @@ -218,12 +212,11 @@ public: bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;} /** - * @brief Method which checks if current vector is orthogonal to vector "v". - * If the vectors have different dimensions, it returns false + * @brief Method which checks if current vector is orthogonal to vector "v" * * @param v vector of type PIMathVectorT * @return true if vectors are orthogonal, else fal */ - bool isOrtho(const _CVector & v) const {if(v.size() != Size) return false; return ((*this) ^ v) == Type(0);} + bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);} /** * @brief Read-only access to elements reference by index of the vector element "index" @@ -283,18 +276,18 @@ public: bool operator !=(const _CVector & v) const {return !(*this == v);} /** - * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Vector addition this vector with vector "v" * * @param v vector for the addition assigment */ - void operator +=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] += v[i];} + void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} /** - * @brief Subtraction assignmentthis vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Subtraction assignmentthis vector with vector "v" * * @param v vector for the subtraction assigment */ - void operator -=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] -= v[i];} + void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} /** * @brief Multiplication assignment this vector with value "v" @@ -304,11 +297,11 @@ public: void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} /** - * @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Multiplication assignment this vector with vector "v" * * @param v vector for the multiplication assigment */ - void operator *=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] *= v[i];} + void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];} /** * @brief Division assignment with this vector value "v" @@ -318,11 +311,11 @@ public: void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;} /** - * @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Division assignment this vector with vector "v" * * @param v vector for the division assigment */ - void operator /=(const _CVector & v) {if(v.size() != Size) return void(); PIMV_FOR(i, 0) c[i] /= v[i];} + void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];} /** * @brief Vector substraction this vector @@ -332,20 +325,20 @@ public: _CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;} /** - * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything + * @brief Vector addition this vector with vector "v" * * @param v is vector term * @return the result of vector addition */ - _CVector operator +(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} + _CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} /** - * @brief Vector substraction this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything + * @brief Vector substraction this vector with vector "v" * * @param v is vector term * @return the result of vector substraction */ - _CVector operator -(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} + _CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} /** * @brief Vector multiplication this vector with value "v" @@ -364,12 +357,12 @@ public: _CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;} /** - * @brief Vector division this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything + * @brief Vector division this vector with vector "v" * * @param v is vector divider * @return the result of vector division */ - _CVector operator /(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;} + _CVector operator /(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;} /** * @brief Cross product of two vectors. Works only with vector containing three elements, otherwise returns current vector @@ -380,20 +373,20 @@ public: _CVector operator *(const _CVector & v) const {if (Size != 3) return _CVector(); _CVector tv; tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} /** - * @brief Elementwise assignment of multiplication of two vectors. If the vectors have different dimensions, it returns this without changing anything + * @brief Elementwise assignment of multiplication of two vectors * * @param v is vector for multiplication * @return resulting vector */ - _CVector operator &(const _CVector & v) const {if(v.size() != Size) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} + _CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} /** - * @brief Absolute value of the dot product. If the vectors have different dimensions, it returns false + * @brief Absolute value of the dot product * * @param v is vector for dot product * @return resulting vector */ - Type operator ^(const _CVector & v) const {if(v.size() != Size) return false; Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} + Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} PIMathMatrixT<1, Size, Type> transposed() const { PIMathMatrixT<1, Size, Type> ret; -- 2.43.0 From 49905a3de02aaa9665c85fe309fb7315e142ffc8 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Thu, 1 Oct 2020 17:07:01 +0300 Subject: [PATCH 12/14] documentation correction and tests in PIMathVector.h --- libs/main/math/pimathvector.h | 145 +++++++++--------- tests/math/testpimathmatrixt.cpp | 248 +++++++++++++++---------------- tests/math/testpimathvector.cpp | 6 +- tests/math/testpimathvectort.cpp | 2 +- 4 files changed, 202 insertions(+), 199 deletions(-) diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index d9b84b5e..77b017ee 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -132,39 +132,39 @@ public: * @param v vector of type PIMathVectorT * @return cos value of the angle between two vectors */ - Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} + Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);} /** - * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements + * @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements * * @param v vector of type PIMathVectorT * @return sin value of the angle between two vector */ - Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} + Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Rad + * @brief Method that returns the angle between of the current vector and vector "v" in Rad * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Rad */ - Type angleRad(const _CVector & v) const {return acos(angleCos(v));} + Type angleRad(const _CVector & v) const {return acos(angleCos(v));} /** - * @brief Method that returns the angle between of the current vector and vector "v" in Deg + * @brief Method that returns the angle between of the current vector and vector "v" in Deg * * @param v vector of type PIMathVectorT * @return value of the angle between two vectors in Deg */ - Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));} + Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));} /** - * @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg + * @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg * * @param v vector of type PIMathVectorT * @return value of the angle elevation between two vectors in Deg */ - Type angleElevation(const _CVector & v) const {_CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;} + Type angleElevation(const _CVector & v) const {_CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;} /** * @brief Method that returns a vector equal to the projection of the current vector onto the vector "v". @@ -172,17 +172,17 @@ public: * @param v vector of type PIMathVectorT * @return vector of type PIMathVectorT equal to the projection of the current vector onto the vector "v" */ - _CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} + _CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} /** - * @brief Method that returns this normalized vector + * @brief Method that returns this normalized vector (each element of a vector is divided by the absolute value of this vector) * * @return reference to this */ _CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;} /** - * @brief Method that returns a normalized vector + * @brief Method that returns a normalized vector (each element of a vector is divided by the absolute value of this vector) * * @return normalized vector of type PIMathVectorT */ @@ -212,11 +212,11 @@ public: bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;} /** - * @brief Method which checks if current vector is orthogonal to vector "v" + * @brief Method which checks if current vector is orthogonal to vector "v" * * @param v vector of type PIMathVectorT * @return true if vectors are orthogonal, else fal */ - bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);} + bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);} /** * @brief Read-only access to elements reference by index of the vector element "index" @@ -244,15 +244,16 @@ public: const Type & operator [](uint index) const {return c[index];} /** - * @brief Vector assignment to vector "v" of type PIMathVectorT + * @brief Assignment all elements of this vector with all elements of vector "v" + * If the vectors have different dimensions, it returns this without changing anything * * @param v vector for the assigment - * @return vector equal to vector "v" + * @return reference to this */ _CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;} /** - * @brief Assignment operation. All vector values ​​become equal to "v" + * @brief Assignment all elements of this vector with all elements of value "v" * * @param v value for the assigment * @return reference to this @@ -260,7 +261,7 @@ public: _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} /** - * @brief Compare with vector "v" + * @brief Compare all elements of this vector with all elements of vector "v" * * @param v vector for the compare * @return if vectors are equal true, else false @@ -268,7 +269,7 @@ public: bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;} /** - * @brief Compare with vector "v" + * @brief Compare all elements of this vector with all elements of vector "v" * * @param v vector for the compare * @return if vectors are not equal true, else false @@ -276,46 +277,46 @@ public: bool operator !=(const _CVector & v) const {return !(*this == v);} /** - * @brief Vector addition this vector with vector "v" + * @brief Addition all elements of this vector with all elements vector "v" * * @param v vector for the addition assigment */ - void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} + void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];} /** - * @brief Subtraction assignmentthis vector with vector "v" + * @brief Subtraction all elements of this vector with all elements vector "v" * * @param v vector for the subtraction assigment */ - void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} + void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];} /** - * @brief Multiplication assignment this vector with value "v" + * @brief Multiplication all elements of this vector with value "v" * * @param v value for the multiplication assigment */ void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} /** - * @brief Multiplication assignment this vector with vector "v" + * @brief Multiplication all elements of this vector with all elements vector "v" * * @param v vector for the multiplication assigment */ - void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];} + void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];} /** - * @brief Division assignment with this vector value "v" + * @brief Division all elements of this vector with value "v" * * @param v value for the division assigment */ void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;} /** - * @brief Division assignment this vector with vector "v" + * @brief Division all elements of this vector with all elements vector "v" * * @param v vector for the division assigment */ - void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];} + void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];} /** * @brief Vector substraction this vector @@ -325,23 +326,23 @@ public: _CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;} /** - * @brief Vector addition this vector with vector "v" + * @brief Addition all elements of this vector with all elements of vector "v" * * @param v is vector term * @return the result of vector addition */ - _CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} + _CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} /** - * @brief Vector substraction this vector with vector "v" + * @brief Substraction all elements of this vector with all elements of vector "v" * * @param v is vector term * @return the result of vector substraction */ - _CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} + _CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} /** - * @brief Vector multiplication this vector with value "v" + * @brief Multiplication all elements of this vector with value "v" * * @param v is value factor * @return the result of vector multiplication @@ -349,7 +350,7 @@ public: _CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;} /** - * @brief Vector division this vector with value "v" + * @brief Division all elements of this vector with value "v" * * @param v is value divider * @return the result of vector division @@ -357,12 +358,12 @@ public: _CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;} /** - * @brief Vector division this vector with vector "v" + * @brief Division all elements of this vector with all elements of vector "v" * * @param v is vector divider * @return the result of vector division */ - _CVector operator /(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;} + _CVector operator /(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;} /** * @brief Cross product of two vectors. Works only with vector containing three elements, otherwise returns current vector @@ -373,20 +374,20 @@ public: _CVector operator *(const _CVector & v) const {if (Size != 3) return _CVector(); _CVector tv; tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;} /** - * @brief Elementwise assignment of multiplication of two vectors + * @brief Elementwise assignment of multiplication of two vectors * * @param v is vector for multiplication * @return resulting vector */ - _CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} + _CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;} /** - * @brief Absolute value of the dot product + * @brief Absolute value of the dot product * * @param v is vector for dot product * @return resulting vector */ - Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} + Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;} PIMathMatrixT<1, Size, Type> transposed() const { PIMathMatrixT<1, Size, Type> ret; @@ -418,7 +419,7 @@ private: }; /** -* @brief Inline operator which returns vector multiplication with value "x" +* @brief Multiplication all vector elements with value "x" * * @param x value for the multiplication * @param v vector for the multiplication @@ -430,7 +431,7 @@ inline PIMathVectorT operator *(const Type & x, const PIMathVectorT< } /** -* @brief Inline operator for outputting the vector to the console +* @brief Outputting the vector to the console * * @param s PICout type * @param the vector type PIMathVectorT that we print to the console @@ -440,7 +441,7 @@ template inline PICout operator <<(PICout s, const PIMathVectorT & v) {s << "{"; PIMV_FOR(i, 0) {s << v[i]; if (i < Size - 1) s << ", ";} s << "}"; return s;} /** -* @brief Inline operator checking if the cross product is zero. Works only with vector containing three elements, otherwise returns current vector +* @brief Checking if the cross product of two vectors is zero. Works only with vector containing three elements, otherwise returns current vector * * @param f vector of the first operand * @param s vector of the second operand @@ -450,7 +451,7 @@ template inline bool operator ||(const PIMathVectorT & f, const PIMathVectorT & s) {return (f * s).isNull();} /** -* @brief Inline function which takes the square root of each element in the vector +* @brief The square root of every element in the vector * * @param v vector of whose elements the square root is taken * @return resulting vector @@ -459,7 +460,7 @@ template inline PIMathVectorT sqrt(const PIMathVectorT & v) {PIMathVectorT ret; PIMV_FOR(i, 0) {ret[i] = sqrt(v[i]);} return ret;} /** -* @brief Inline function which squares each element of the vector +* @brief Squares every element of the vector * * @param v vector whose elements are squared * @return resulting vector @@ -468,7 +469,7 @@ template inline PIMathVectorT sqr(const PIMathVectorT & v) {PIMathVectorT ret; PIMV_FOR(i, 0) {ret[i] = sqr(v[i]);} return ret;} /** -* @brief Inline operator for serializing a vector into a PIByteArray +* @brief Serializing a vector into a PIByteArray * * @param s PIByteArray type * @param v PIMathVectorT type @@ -478,7 +479,7 @@ template inline PIByteArray & operator <<(PIByteArray & s, const PIMathVectorT & v) {for (uint i = 0; i < Size; ++i) s << v[i]; return s;} /** -* @brief Inline operator to deserialize vector from PIByteArray +* @brief Deserializing vector from PIByteArray * * @param s PIByteArray type * @param v PIMathVector type @@ -488,7 +489,7 @@ template inline PIByteArray & operator >>(PIByteArray & s, PIMathVectorT & v) {for (uint i = 0; i < Size; ++i) s >> v[i]; return s;} /** -* @brief Inline function which returns vector size 2 and type of T +* @brief Function which returns vector size 2 and type of T * * @param x first element of vector * @param y second element of vector @@ -498,7 +499,7 @@ template inline PIMathVectorT<2u, T> createVectorT2(T x, T y) {return PIMathVectorT<2u, T>(PIVector() << x << y);} /** -* @brief Inline function which returns vector size 3 and type of T +* @brief Function which returns vector size 3 and type of T * * @param x first element of vector * @param y second element of vector @@ -509,7 +510,7 @@ template inline PIMathVectorT<3u, T> createVectorT3(T x, T y, T z) {return PIMathVectorT<3u, T>(PIVector() << x << y << z);} /** -* @brief Inline function which returns vector size 4 and type of T +* @brief Function which returns vector size 4 and type of T * * @param x first element of vector * @param y second element of vector @@ -699,14 +700,14 @@ public: _CVector projection(const _CVector & v) {if(v.size() != c.size()) return *this; Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));} /** - * @brief Method that returns a normalized vector + * @brief Method that returns a normalized vector (each element of a vector is divided by the absolute value of this vector) * * @return copy of normalized vector of type PIMathVector */ _CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;} /** - * @brief Method that returns a normalized vector + * @brief Method that returns a normalized vector (each element of a vector is divided by the absolute value of this vector) * * @return normalized vector of type PIMathVector */ @@ -720,7 +721,7 @@ public: bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;} /** - * @brief Method which checks if vector is valid + * @brief Method which checks if vector is empty * * @return true if vector is valid, else false */ @@ -761,7 +762,7 @@ public: const Type & operator [](uint index) const {return c[index];} /** - * @brief Vector assignment to vector "v" of type PIMathVector + * @brief Assignment all elements of this vector with all elements of vector "v" * If the vectors have different dimensions, it returns this without changing anything * * @param v vector for the assigment @@ -770,7 +771,7 @@ public: _CVector & operator =(const _CVector & v) {if(v.size() != c.size()) return *this; c = v.c; return *this;} /** - * @brief Vector assignment to value "v" + * @brief Assignment all elements of this vector with all elements of value "v" * * @param v value for the assigment * @return reference to this @@ -778,7 +779,7 @@ public: _CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;} /** - * @brief Compare with vector "v" + * @brief Compare all elements of this vector with all elements of vector "v" * * @param v vector for the compare * @return if vectors are equal true, else false @@ -786,7 +787,7 @@ public: bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if ((c[i] != v[i]) || (v.size() != c.size())) return false; return true;} /** - * @brief Compare with vector "v" + * @brief Compare all elements of this vector with all elements of vector "v" * * @param v vector for the compare * @return if vectors are not equal true, else false @@ -794,42 +795,42 @@ public: bool operator !=(const _CVector & v) const {return !(*this == v);} /** - * @brief Addition assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Addition all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the addition assigment */ void operator +=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] += v[i];} /** - * @brief Subtraction assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Subtraction all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the subtraction assigment */ void operator -=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] -= v[i];} /** - * @brief Multiplication assignment this vector with value "v" + * @brief Multiplication all elements of this vector with value "v" * * @param v value for the multiplication assigment */ void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;} /** - * @brief Multiplication assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Multiplication all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the multiplication assigment */ void operator *=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] *= v[i];} /** - * @brief Division assignment this vector with value "v" + * @brief Division all elements of this vector with value "v" * * @param v value for the division assigment */ void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;} /** - * @brief Division assignment this vector with vector "v". If the vectors have different dimensions, it returns void() + * @brief Division all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void() * * @param v vector for the division assigment */ @@ -843,15 +844,15 @@ public: _CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;} /** - * @brief Vector addition this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything + * @brief Addition all elements of this vector with all elements of vector "v". If the vectors have different dimensions, it returns this without changing anything * * @param v is vector term - * @return the result of matrix addition + * @return the result of vector addition */ _CVector operator +(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;} /** - * @brief Vector substraction this vector with vector "v". If the vectors have different dimensions, it returns this without changing anything + * @brief Substraction all elements of this vector with all elements of vector "v". If the vectors have different dimensions, it returns this without changing anything * * @param v is vector term * @return the result of vector substraction @@ -859,7 +860,7 @@ public: _CVector operator -(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;} /** - * @brief Vector multiplicationthis vector with value "v" + * @brief Multiplication all elements of this vector with value "v" * * @param v is value factor * @return the result of vector multiplication @@ -867,7 +868,7 @@ public: _CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;} /** - * @brief Vector division this vector with value "v" + * @brief Division all elements of this vector with value "v" * * @param v is value divider * @return the result of vector division @@ -932,7 +933,7 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathVector & v #endif /** -* @brief Inline operator for outputting the vector to the console +* @brief Outputting the vector to the console * * @param s PICout type * @param the vector type PIMathVector that we print to the console @@ -942,7 +943,7 @@ template inline PICout operator <<(PICout s, const PIMathVector & v) {s << "Vector{"; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;} /** -* @brief Inline operator for serializing a vector into a PIByteArray +* @brief Serializing a vector into a PIByteArray * * @param s PIByteArray type * @param v PIMathVector type @@ -952,7 +953,7 @@ template inline PIByteArray & operator <<(PIByteArray & s, const PIMathVector & v) {s << v.c; return s;} /** -* @brief Inline operator to deserialize vector from PIByteArray +* @brief Deserializing vector from PIByteArray * * @param s PIByteArray type * @param v PIMathVector type diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index c9ba0ff7..013672ba 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -8,7 +8,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, double v bool b = true; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { - if(matrix.at(i, j) - val >= double(1E-200)) { + if(matrix[i][j] - val >= double(1E-200)) { b = false; } } @@ -63,15 +63,15 @@ TEST(PIMathMatrixT_Test, col) { PIMathMatrixT matr; PIMathVectorT vect; uint g = 2; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; vect = matr.col(g); for(uint i = 0; i < matr.cols(); i++) { if(matr.at(i, g) != vect.at(i)) { @@ -85,15 +85,15 @@ TEST(PIMathMatrixT_Test, row) { PIMathMatrixT matr; PIMathVectorT vect; uint g = 2; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; vect = matr.row(g); for(uint i = 0; i < matr.rows(); i++) { if(matr.at(g, i) != vect.at(i)) { @@ -138,15 +138,15 @@ TEST(PIMathMatrixT_Test, setRow) { TEST(PIMathMatrixT_Test, swapCols) { PIMathMatrixT matr; int g1 = 1, g2 = 2; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; const PIMathVectorT before_Vect1 = matr.col(g1); const PIMathVectorT before_Vect2 = matr.col(g2); matr.swapCols(g1, g2); @@ -163,15 +163,15 @@ TEST(PIMathMatrixT_Test, swapCols) { TEST(PIMathMatrixT_Test, swapRows) { PIMathMatrixT matr; int g1 = 1, g2 = 2; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; const PIMathVectorT before_Vect1 = matr.row(g1); const PIMathVectorT before_Vect2 = matr.row(g2); matr.swapRows(g1, g2); @@ -192,7 +192,7 @@ TEST(PIMathMatrixT_Test, fill) { matr.fill(g); for(uint i = 0; i < cols; i++) { for(uint j = 0; j < rows; j++) { - matrix1.at(j,i) = g; + matrix1[j][i] = g; } } ASSERT_TRUE(matr == matrix1); @@ -239,56 +239,56 @@ TEST(PIMathMatrixT_Test, operator_Assignment) { TEST(PIMathMatrixT_Test, operator_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - matrix1.at(0, 0) = 5.1; - matrix1.at(0, 1) = 1.21; - matrix1.at(1, 1) = 0.671; - matrix1.at(1, 0) = 2.623; - matrix2.at(0, 0) = 5.1; - matrix2.at(0, 1) = 1.21; - matrix2.at(1, 1) = 0.671; - matrix2.at(1, 0) = 2.623; + matrix1[0][0] = 5.1; + matrix1[0][1] = 1.21; + matrix1[1][1] = 0.671; + matrix1[1][0] = 2.623; + matrix2[0][0] = 5.1; + matrix2[0][1] = 1.21; + matrix2[1][1] = 0.671; + matrix2[1][0] = 2.623; ASSERT_TRUE(matrix1 == matrix2); } TEST(PIMathMatrixT_Test, operator_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - matrix1.at(0, 0) = 5.1; - matrix1.at(0, 1) = 1.21; - matrix1.at(1, 1) = 0.671; - matrix1.at(1, 0) = 2.623; - matrix2.at(0, 0) = 5.1; - matrix2.at(0, 1) = 1.21; - matrix2.at(1, 1) = 665.671; - matrix2.at(1, 0) = 2.623; + matrix1[0][0] = 5.1; + matrix1[0][1] = 1.21; + matrix1[1][1] = 0.671; + matrix1[1][0] = 2.623; + matrix2[0][0] = 5.1; + matrix2[0][1] = 1.21; + matrix2[1][1] = 665.671; + matrix2[1][0] = 2.623; ASSERT_FALSE(matrix1 == matrix2); } TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - matrix1.at(0, 0) = 5.1; - matrix1.at(0, 1) = 1.21; - matrix1.at(1, 1) = 0.671; - matrix1.at(1, 0) = 2.623; - matrix2.at(0, 0) = 5.1; - matrix2.at(0, 1) = 1.21; - matrix2.at(1, 1) = 665.671; - matrix2.at(1, 0) = 2.623; + matrix1[0][0] = 5.1; + matrix1[0][1] = 1.21; + matrix1[1][1] = 0.671; + matrix1[1][0] = 2.623; + matrix2[0][0] = 5.1; + matrix2[0][1] = 1.21; + matrix2[1][1] = 665.671; + matrix2[1][0] = 2.623; ASSERT_TRUE(matrix1 != matrix2); } TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - matrix1.at(0, 0) = 5.1; - matrix1.at(0, 1) = 1.21; - matrix1.at(1, 1) = 0.671; - matrix1.at(1, 0) = 2.623; - matrix2.at(0, 0) = 5.1; - matrix2.at(0, 1) = 1.21; - matrix2.at(1, 1) = 0.671; - matrix2.at(1, 0) = 2.623; + matrix1[0][0] = 5.1; + matrix1[0][1] = 1.21; + matrix1[1][1] = 0.671; + matrix1[1][0] = 2.623; + matrix2[0][0] = 5.1; + matrix2[0][1] = 1.21; + matrix2[1][1] = 0.671; + matrix2[1][0] = 2.623; ASSERT_FALSE(matrix1 != matrix2); } @@ -343,30 +343,30 @@ TEST(PIMathMatrixT_Test, determinantIfSquare) { double d; double i = 59.0; PIMathMatrixT matr; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; d = matr.determinant(); ASSERT_DOUBLE_EQ(i, d); } TEST(PIMathMatrixT_Test, determinantIfNotSquare) { PIMathMatrixT matr; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; ASSERT_FALSE(matr.determinant()); } @@ -376,15 +376,15 @@ TEST(PIMathMatrixT_Test, invert) { PIMathMatrixT matrix3; PIMathMatrixT matr; double d1, d2; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; matrix2 = matr; matr.invert(); d1 = matr.determinant(); @@ -401,15 +401,15 @@ TEST(PIMathMatrixT_Test, inverted) { PIMathMatrixT matr; double d1, d2; matrix1 = matr.identity(); - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; matrix2 = matr.inverted(); d1 = matr.determinant(); d2 = matrix2.determinant(); @@ -421,15 +421,15 @@ TEST(PIMathMatrixT_Test, toUpperTriangular) { PIMathMatrixT matrix; double d1, d2 = 1; PIMathMatrixT matr; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; matrix = matr.toUpperTriangular(); d1 = matrix.determinant(); for(uint i = 0; i < cols; i++) @@ -444,15 +444,15 @@ TEST(PIMathMatrixT_Test, transposed) { PIMathMatrixT matrix2; PIMathMatrixT matr; double d1, d2; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; d1 = matr.determinant(); matrix1 = matr.transposed(); d2 = matrix1.determinant(); diff --git a/tests/math/testpimathvector.cpp b/tests/math/testpimathvector.cpp index 4d0bf405..3556ac55 100644 --- a/tests/math/testpimathvector.cpp +++ b/tests/math/testpimathvector.cpp @@ -24,14 +24,16 @@ TEST(PIMathVector_Test, resize) { PIMathVector vector; vector.resize(newSize, a); ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size())); + ASSERT_TRUE(vector.size() == newSize); } TEST(PIMathVector_Test, resized) { uint newSize = 4u; double a = 5.0; PIMathVector vector; - vector.resized(newSize, a); - ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size())); + auto vect = vector.resized(newSize, a); + ASSERT_TRUE(cmpVectorWithValue(vect, a, vect.size()) && vect.size() == newSize); + ASSERT_TRUE(vect.size() == newSize); } TEST(PIMathVector_Test, fill) { diff --git a/tests/math/testpimathvectort.cpp b/tests/math/testpimathvectort.cpp index 89905e97..738c663d 100644 --- a/tests/math/testpimathvectort.cpp +++ b/tests/math/testpimathvectort.cpp @@ -14,7 +14,7 @@ bool cmpVectorWithValue(PIMathVectorT vector, double val, int num) return b; } -TEST(PIMathVectorT_Test, SIZE) { +TEST(PIMathVectorT_Test, size) { PIMathVectorT vector; ASSERT_TRUE(vector.size() == SIZE); } -- 2.43.0 From d6637047b2d90b40d44eba31a9870913756742f4 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Tue, 6 Oct 2020 17:07:34 +0300 Subject: [PATCH 13/14] new tests fo PIMathVector.h and tab correction --- tests/math/testpimathmatrix.cpp | 842 +++++++++++++++---------------- tests/math/testpimathmatrixt.cpp | 804 ++++++++++++++--------------- tests/math/testpimathvector.cpp | 794 +++++++++++++++++------------ tests/math/testpimathvectort.cpp | 694 +++++++++++++------------ 4 files changed, 1654 insertions(+), 1480 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index c6a52ec7..cb8dbea5 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -2,553 +2,553 @@ #include "pimathmatrix.h" bool cmpSquareMatrixWithValue(PIMathMatrix matrix, double val, int num) { - bool b = true; - for(int i = 0; i < num; i++) { - for(int j = 0; j < num; j++) { - if(matrix.element(i, j) - val >= double(1E-200)) { - b = false; - } - } - } - return b; + bool b = true; + for(int i = 0; i < num; i++) { + for(int j = 0; j < num; j++) { + if(matrix.element(i, j) - val >= double(1E-200)) { + b = false; + } + } + } + return b; } TEST(PIMathMatrix_Test, identity) { - auto matrix = PIMathMatrix::identity(3, 3); - for(int i = 0; i < 3; i++) { - for(int j = 0; j < 3; j++) { - if(i != j) { - if(matrix[i][j] != 0.0){ - ASSERT_TRUE(false); - } - } - else { - if(matrix[i][i] != 1.0){ - ASSERT_TRUE(false); - } - } - } - } - ASSERT_TRUE(true); + auto matrix = PIMathMatrix::identity(3, 3); + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) { + if(i != j) { + if(matrix[i][j] != 0.0){ + ASSERT_TRUE(false); + } + } + else { + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); + } + } + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, element) { - auto matrix = PIMathMatrix::identity(3, 3); - for(int i = 0; i < 3; i++){ - for(int j = 0; j < 3; j++){ - if(i != j){ - if(matrix[i][j] != 0.0){ - ASSERT_TRUE(false); - } - } - else { - if(matrix.element(i,i) != 1.0) { - ASSERT_TRUE(false); - } - } - } - } - ASSERT_TRUE(true); + auto matrix = PIMathMatrix::identity(3, 3); + for(int i = 0; i < 3; i++){ + for(int j = 0; j < 3; j++){ + if(i != j){ + if(matrix[i][j] != 0.0){ + ASSERT_TRUE(false); + } + } + else { + if(matrix.element(i,i) != 1.0) { + ASSERT_TRUE(false); + } + } + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, matrixRow) { - PIMathVector vector; - vector.resize(3, 3.0); - auto matrix = PIMathMatrix::matrixRow(vector); - for(uint i = 0; i < vector.size(); i++) { - if(matrix[0][i] != 3.0) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + PIMathVector vector; + vector.resize(3, 3.0); + auto matrix = PIMathMatrix::matrixRow(vector); + for(uint i = 0; i < vector.size(); i++) { + if(matrix[0][i] != 3.0) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, matrixCol) { - PIMathVector vector; - vector.resize(3, 3.0); - auto matrix = PIMathMatrix::matrixCol(vector); - for(uint i = 0; i < vector.size(); i++) { - if(matrix[i][0] != 3.0) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + PIMathVector vector; + vector.resize(3, 3.0); + auto matrix = PIMathMatrix::matrixCol(vector); + for(uint i = 0; i < vector.size(); i++) { + if(matrix[i][0] != 3.0) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, setCol) { - PIMathVector vector; - vector.resize(3, 3.0); - auto matrix = PIMathMatrix::matrixCol(vector); - vector.fill(10.0); - matrix.setCol(0, vector); - for(uint i = 0; i < vector.size(); i++) { - if(matrix[i][0] != 10.0) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + PIMathVector vector; + vector.resize(3, 3.0); + auto matrix = PIMathMatrix::matrixCol(vector); + vector.fill(10.0); + matrix.setCol(0, vector); + for(uint i = 0; i < vector.size(); i++) { + if(matrix[i][0] != 10.0) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, setRow) { - PIMathVector vector; - vector.resize(3, 3.0); - auto matrix = PIMathMatrix::matrixRow(vector); - vector.fill(10.0); - matrix.setRow(0, vector); - for(uint i = 0; i < vector.size(); i++) { - if(matrix[0][i] != 10.0) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + PIMathVector vector; + vector.resize(3, 3.0); + auto matrix = PIMathMatrix::matrixRow(vector); + vector.fill(10.0); + matrix.setRow(0, vector); + for(uint i = 0; i < vector.size(); i++) { + if(matrix[0][i] != 10.0) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, swapCols) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathVector vector; - uint i1 = 0; uint i2 = 1; - double a1[3], a2[3], a3[3]; - double b1[3], b2[3], b3[3]; - vector.resize(3, 3.0); - vector[0] = 3.0; - vector[1] = 6.0; - vector[2] = 8.0; - matrix1 = origMatr.identity(3, 3); - matrix1.setCol(0, vector); - vector[0] = 2.0; - vector[1] = 1.0; - vector[2] = 4.0; - matrix1.setCol(1, vector); - vector[0] = 6.0; - vector[1] = 2.0; - vector[2] = 5.0; - matrix1.setCol(2, vector); - for(int i = 0; i < 3; i++) { - a1[i] = matrix1.element(i, 0); - a2[i] = matrix1.element(i, 1); - a3[i] = matrix1.element(i, 2); - } - matrix1.swapCols(i1, i2); - for(int i = 0; i < 3; i++) { - b1[i] = matrix1.element(i, 0); - b2[i] = matrix1.element(i, 1); - b3[i] = matrix1.element(i, 2); - } - ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)); + PIMathMatrix origMatr; + PIMathMatrix matrix1; + PIMathVector vector; + uint i1 = 0; uint i2 = 1; + double a1[3], a2[3], a3[3]; + double b1[3], b2[3], b3[3]; + vector.resize(3, 3.0); + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; + matrix1 = origMatr.identity(3, 3); + matrix1.setCol(0, vector); + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; + matrix1.setCol(1, vector); + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; + matrix1.setCol(2, vector); + for(int i = 0; i < 3; i++) { + a1[i] = matrix1.element(i, 0); + a2[i] = matrix1.element(i, 1); + a3[i] = matrix1.element(i, 2); + } + matrix1.swapCols(i1, i2); + for(int i = 0; i < 3; i++) { + b1[i] = matrix1.element(i, 0); + b2[i] = matrix1.element(i, 1); + b3[i] = matrix1.element(i, 2); + } + ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)); } TEST(PIMathMatrix_Test, swapRows) { - PIMathMatrix origMatr; - PIMathMatrix matrix1; - PIMathVector vector; - uint i1 = 0; uint i2 = 1; - double a1[3], a2[3], a3[3]; - double b1[3], b2[3], b3[3]; - vector.resize(3, 3.0); - vector[0] = 3.0; - vector[1] = 6.0; - vector[2] = 8.0; - matrix1 = origMatr.identity(3, 3); - matrix1.setCol(0, vector); - vector[0] = 2.0; - vector[1] = 1.0; - vector[2] = 4.0; - matrix1.setCol(1, vector); - vector[0] = 6.0; - vector[1] = 2.0; - vector[2] = 5.0; - matrix1.setCol(2, vector); - for(int i = 0; i < 3; i++) { - a1[i] = matrix1.element(0, i); - a2[i] = matrix1.element(1, i); - a3[i] = matrix1.element(2, i); - } - matrix1.swapRows(i1, i2); - for(int i = 0; i < 3; i++) { - b1[i] = matrix1.element(0, i); - b2[i] = matrix1.element(1, i); - b3[i] = matrix1.element(2, i); - } - ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)); + PIMathMatrix origMatr; + PIMathMatrix matrix1; + PIMathVector vector; + uint i1 = 0; uint i2 = 1; + double a1[3], a2[3], a3[3]; + double b1[3], b2[3], b3[3]; + vector.resize(3, 3.0); + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; + matrix1 = origMatr.identity(3, 3); + matrix1.setCol(0, vector); + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; + matrix1.setCol(1, vector); + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; + matrix1.setCol(2, vector); + for(int i = 0; i < 3; i++) { + a1[i] = matrix1.element(0, i); + a2[i] = matrix1.element(1, i); + a3[i] = matrix1.element(2, i); + } + matrix1.swapRows(i1, i2); + for(int i = 0; i < 3; i++) { + b1[i] = matrix1.element(0, i); + b2[i] = matrix1.element(1, i); + b3[i] = matrix1.element(2, i); + } + ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)); } TEST(PIMathMatrix_Test, fill) { - PIMathMatrix matrix(3, 3, 5.0); - matrix.fill(7.0); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3)); + PIMathMatrix matrix(3, 3, 5.0); + matrix.fill(7.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3)); } TEST(PIMathMatrix_Test, isSquareTrue) { - PIMathMatrix matrix(3, 3, 1.0); - ASSERT_TRUE(matrix.isSquare()); + PIMathMatrix matrix(3, 3, 1.0); + ASSERT_TRUE(matrix.isSquare()); } TEST(PIMathMatrix_Test, isSquareFalse) { - PIMathMatrix matrix(2, 4, 1.0); - ASSERT_FALSE(matrix.isSquare()); + PIMathMatrix matrix(2, 4, 1.0); + ASSERT_FALSE(matrix.isSquare()); } TEST(PIMathMatrix_Test, isIdentityTrue) { - auto matrix = PIMathMatrix::identity(3, 3); - ASSERT_TRUE(matrix.isIdentity()); + auto matrix = PIMathMatrix::identity(3, 3); + ASSERT_TRUE(matrix.isIdentity()); } TEST(PIMathMatrix_Test, isIdentityFalse) { - PIMathMatrix matrix(3, 3, 5.0); - ASSERT_FALSE(matrix.isIdentity()); + PIMathMatrix matrix(3, 3, 5.0); + ASSERT_FALSE(matrix.isIdentity()); } TEST(PIMathMatrix_Test, isNullTrue) { - PIMathMatrix matrix(3, 3, 0.0); - ASSERT_TRUE(matrix.isNull()); + PIMathMatrix matrix(3, 3, 0.0); + ASSERT_TRUE(matrix.isNull()); } TEST(PIMathMatrix_Test, isNullFalse) { - PIMathMatrix matrix(3, 3, 5.0); - ASSERT_FALSE(matrix.isNull()); + PIMathMatrix matrix(3, 3, 5.0); + ASSERT_FALSE(matrix.isNull()); } TEST(PIMathMatrix_Test, isValidTrue) { - PIMathMatrix matrix(3, 3, 1.62); - ASSERT_TRUE(matrix.isValid()); + PIMathMatrix matrix(3, 3, 1.62); + ASSERT_TRUE(matrix.isValid()); } TEST(PIMathMatrix_Test, isValidFalse) { - PIMathMatrix matrix; - ASSERT_FALSE(matrix.isValid()); + PIMathMatrix matrix; + ASSERT_FALSE(matrix.isValid()); } TEST(PIMathMatrix_Test, operator_Assignment) { - PIMathMatrix matrix1(3, 3, 5.72); - PIMathMatrix matrix2(3, 3, 7.12); - matrix1 = matrix2; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3)); + PIMathMatrix matrix1(3, 3, 5.72); + PIMathMatrix matrix2(3, 3, 7.12); + matrix1 = matrix2; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3)); } TEST(PIMathMatrix_Test, operator_EqualTrue) { - PIMathMatrix matrix1(2, 2, 2.0); - PIMathMatrix matrix2(2, 2, 2.0); - matrix1.element(0, 0) = 5.1; - matrix1.element(0, 1) = 1.21; - matrix1.element(1, 1) = 0.671; - matrix1.element(1, 0) = 2.623; - matrix2.element(0, 0) = 5.1; - matrix2.element(0, 1) = 1.21; - matrix2.element(1, 1) = 0.671; - matrix2.element(1, 0) = 2.623; - ASSERT_TRUE(matrix1 == matrix2); + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 0.671; + matrix2.element(1, 0) = 2.623; + ASSERT_TRUE(matrix1 == matrix2); } TEST(PIMathMatrix_Test, operator_EqualFalse) { - PIMathMatrix matrix1(2, 2, 2.0); - PIMathMatrix matrix2(2, 2, 2.0); - matrix1.element(0, 0) = 5.1; - matrix1.element(0, 1) = 1.21; - matrix1.element(1, 1) = 0.671; - matrix1.element(1, 0) = 2.623; - matrix2.element(0, 0) = 5.1; - matrix2.element(0, 1) = 1.21; - matrix2.element(1, 1) = 665.671; - matrix2.element(1, 0) = 2.623; - ASSERT_FALSE(matrix1 == matrix2); + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 665.671; + matrix2.element(1, 0) = 2.623; + ASSERT_FALSE(matrix1 == matrix2); } TEST(PIMathMatrix_Test, operator_Not_EqualTrue) { - PIMathMatrix matrix1(2, 2, 2.0); - PIMathMatrix matrix2(2, 2, 2.0); - matrix1.element(0, 0) = 5.1; - matrix1.element(0, 1) = 1.21; - matrix1.element(1, 1) = 0.671; - matrix1.element(1, 0) = 2.623; - matrix2.element(0, 0) = 5.1; - matrix2.element(0, 1) = 1.21; - matrix2.element(1, 1) = 665.671; - matrix2.element(1, 0) = 2.623; - ASSERT_TRUE(matrix1 != matrix2); + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 665.671; + matrix2.element(1, 0) = 2.623; + ASSERT_TRUE(matrix1 != matrix2); } TEST(PIMathMatrix_Test, operator_Not_EqualFalse) { - PIMathMatrix matrix1(2, 2, 2.0); - PIMathMatrix matrix2(2, 2, 2.0); - matrix1.element(0, 0) = 5.1; - matrix1.element(0, 1) = 1.21; - matrix1.element(1, 1) = 0.671; - matrix1.element(1, 0) = 2.623; - matrix2.element(0, 0) = 5.1; - matrix2.element(0, 1) = 1.21; - matrix2.element(1, 1) = 0.671; - matrix2.element(1, 0) = 2.623; - ASSERT_FALSE(matrix1 != matrix2); + PIMathMatrix matrix1(2, 2, 2.0); + PIMathMatrix matrix2(2, 2, 2.0); + matrix1.element(0, 0) = 5.1; + matrix1.element(0, 1) = 1.21; + matrix1.element(1, 1) = 0.671; + matrix1.element(1, 0) = 2.623; + matrix2.element(0, 0) = 5.1; + matrix2.element(0, 1) = 1.21; + matrix2.element(1, 1) = 0.671; + matrix2.element(1, 0) = 2.623; + ASSERT_FALSE(matrix1 != matrix2); } TEST(PIMathMatrix_Test, operator_Addition_Aassignment) { - PIMathMatrix matrix1(3, 3, 6.72); - PIMathMatrix matrix2(3, 3, 1.0); - matrix1 += matrix2; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3)); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 1.0); + matrix1 += matrix2; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3)); } TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) { - PIMathMatrix matrix1(3, 3, 1.0); - PIMathMatrix matrix2(3, 3, 6.72); - matrix1 -= matrix2; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3)); + PIMathMatrix matrix1(3, 3, 1.0); + PIMathMatrix matrix2(3, 3, 6.72); + matrix1 -= matrix2; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3)); } TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) { - PIMathMatrix matrix1(3, 3, 6.72); - matrix1 *= 2.0; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3)); + PIMathMatrix matrix1(3, 3, 6.72); + matrix1 *= 2.0; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3)); } TEST(PIMathMatrix_Test, operator_Division_Assignment) { - PIMathMatrix matrix1(3, 3, 6.72); - matrix1 /= 2.0; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3)); + PIMathMatrix matrix1(3, 3, 6.72); + matrix1 /= 2.0; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3)); } TEST(PIMathMatrix_Test, operator_Addition) { - PIMathMatrix matrix1(3, 3, 6.72); - PIMathMatrix matrix2(3, 3, 8.28); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3)); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 8.28); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3)); } TEST(PIMathMatrix_Test, operator_Subtraction) { - PIMathMatrix matrix1(3, 3, 6.0); - PIMathMatrix matrix2(3, 3, 5.0); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3)); + PIMathMatrix matrix1(3, 3, 6.0); + PIMathMatrix matrix2(3, 3, 5.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3)); } TEST(PIMathMatrix_Test, operator_Multiplication) { - PIMathMatrix matrix1(3, 3, 6.72); - PIMathMatrix matrix2(3, 3, 5.0); - matrix2 = matrix1*4.0; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3)); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 5.0); + matrix2 = matrix1*4.0; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3)); } TEST(PIMathMatrix_Test, operator_Division) { - PIMathMatrix matrix1(3, 3, 6.72); - PIMathMatrix matrix2(3, 3, 5.0); - matrix2 = matrix1/4.0; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3)); + PIMathMatrix matrix1(3, 3, 6.72); + PIMathMatrix matrix2(3, 3, 5.0); + matrix2 = matrix1/4.0; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3)); } TEST(PIMathMatrix_Test, determinantIfSquare) { - double d; - double i = 59.0; - PIMathMatrix matrix(3, 3, 0.0); - PIMathVector vector; - vector.resize(3, 3.0); - vector[0] = 3.0; - vector[1] = 6.0; - vector[2] = 8.0; - matrix.setCol(0, vector); - vector[0] = 2.0; - vector[1] = 1.0; - vector[2] = 4.0; - matrix.setCol(1, vector); - vector[0] = 6.0; - vector[1] = 2.0; - vector[2] = 5.0; - matrix.setCol(2, vector); - d = matrix.determinant(); - ASSERT_DOUBLE_EQ(d, i); + double d; + double i = 59.0; + PIMathMatrix matrix(3, 3, 0.0); + PIMathVector vector; + vector.resize(3, 3.0); + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; + matrix.setCol(0, vector); + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; + matrix.setCol(1, vector); + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; + matrix.setCol(2, vector); + d = matrix.determinant(); + ASSERT_DOUBLE_EQ(d, i); } TEST(PIMathMatrix_Test, determinantIfNotSquare) { - PIMathMatrix matrix(3, 5, 1.0); - matrix.element(1,1) = 5.0; - ASSERT_FALSE(matrix.determinant()); + PIMathMatrix matrix(3, 5, 1.0); + matrix.element(1,1) = 5.0; + ASSERT_FALSE(matrix.determinant()); } TEST(PIMathMatrix_Test, trace) { - PIMathMatrix matrix(3, 3, 0.0); - double t; - double i = 9.0; - PIMathVector vector; - vector.resize(3, 3.0); - vector[0] = 3.0; - vector[1] = 6.0; - vector[2] = 8.0; - matrix.setCol(0, vector); - vector[0] = 2.0; - vector[1] = 1.0; - vector[2] = 4.0; - matrix.setCol(1, vector); - vector[0] = 6.0; - vector[1] = 2.0; - vector[2] = 5.0; - matrix.setCol(2, vector); - t = matrix.trace(); - ASSERT_DOUBLE_EQ(t, i); + PIMathMatrix matrix(3, 3, 0.0); + double t; + double i = 9.0; + PIMathVector vector; + vector.resize(3, 3.0); + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; + matrix.setCol(0, vector); + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; + matrix.setCol(1, vector); + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; + matrix.setCol(2, vector); + t = matrix.trace(); + ASSERT_DOUBLE_EQ(t, i); } TEST(PIMathMatrix_Test, traceIfNotSquare) { - PIMathMatrix matrix(3, 5, 1.0); - matrix.element(1,1) = 5.0; - ASSERT_FALSE(matrix.trace()); + PIMathMatrix matrix(3, 5, 1.0); + matrix.element(1,1) = 5.0; + ASSERT_FALSE(matrix.trace()); } TEST(PIMathMatrix_Test, toUpperTriangular) { - PIMathMatrix matrix(3, 3, 0.0); - double d1, d2 = 1; - int i; - PIMathVector vector; - vector.resize(3, 3.0); - vector[0] = 3.0; - vector[1] = 6.0; - vector[2] = 8.0; - matrix.setCol(0, vector); - vector[0] = 2.0; - vector[1] = 1.0; - vector[2] = 4.0; - matrix.setCol(1, vector); - vector[0] = 6.0; - vector[1] = 2.0; - vector[2] = 5.0; - matrix.setCol(2, vector); - d1 = matrix.determinant(); - matrix.toUpperTriangular(); - for(i = 0; i < 3; i++) - { - d2 = d2 * matrix.element(i, i); - } - ASSERT_DOUBLE_EQ(d1, d2); + PIMathMatrix matrix(3, 3, 0.0); + double d1, d2 = 1; + int i; + PIMathVector vector; + vector.resize(3, 3.0); + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; + matrix.setCol(0, vector); + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; + matrix.setCol(1, vector); + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; + matrix.setCol(2, vector); + d1 = matrix.determinant(); + matrix.toUpperTriangular(); + for(i = 0; i < 3; i++) + { + d2 = d2 * matrix.element(i, i); + } + ASSERT_DOUBLE_EQ(d1, d2); } TEST(PIMathMatrix_Test, invert) { - double d1, d2; - PIMathMatrix matrix1(3, 3, 0.0); - PIMathMatrix matrix2(3, 3, 0.0); - PIMathMatrix matrix3(3, 3, 0.0); - PIMathMatrix matrix4(3, 3, 0.0); - PIMathVector vector; - vector.resize(3, 3.0); - vector[0] = 3.0; - vector[1] = 6.0; - vector[2] = 8.0; - matrix1.setCol(0, vector); - vector[0] = 2.0; - vector[1] = 1.0; - vector[2] = 4.0; - matrix1.setCol(1, vector); - vector[0] = 6.0; - vector[1] = 2.0; - vector[2] = 5.0; - matrix1.setCol(2, vector); - d1 = matrix1.determinant(); - matrix2 = matrix1; - matrix2.invert(); - d2 = matrix2.determinant(); - matrix4.invert(); - ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); + double d1, d2; + PIMathMatrix matrix1(3, 3, 0.0); + PIMathMatrix matrix2(3, 3, 0.0); + PIMathMatrix matrix3(3, 3, 0.0); + PIMathMatrix matrix4(3, 3, 0.0); + PIMathVector vector; + vector.resize(3, 3.0); + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; + matrix1.setCol(0, vector); + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; + matrix1.setCol(1, vector); + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; + matrix1.setCol(2, vector); + d1 = matrix1.determinant(); + matrix2 = matrix1; + matrix2.invert(); + d2 = matrix2.determinant(); + matrix4.invert(); + ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrix_Test, inverted) { - double d1, d2; - PIMathMatrix matrix1(3, 3, 0.0); - PIMathMatrix matrix2(3, 3, 0.0); - PIMathMatrix matrix3(3, 3, 0.0); - PIMathMatrix matrix4(3, 3, 0.0); - PIMathVector vector; - vector.resize(3, 3.0); - vector[0] = 3.0; - vector[1] = 6.0; - vector[2] = 8.0; - matrix1.setCol(0, vector); - vector[0] = 2.0; - vector[1] = 1.0; - vector[2] = 4.0; - matrix1.setCol(1, vector); - vector[0] = 6.0; - vector[1] = 2.0; - vector[2] = 5.0; - matrix1.setCol(2, vector); - d1 = matrix1.determinant(); - matrix2 = matrix1; - matrix1 = matrix2.invert(); - d2 = matrix1.determinant(); - matrix3 = matrix4.invert(); - ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); + double d1, d2; + PIMathMatrix matrix1(3, 3, 0.0); + PIMathMatrix matrix2(3, 3, 0.0); + PIMathMatrix matrix3(3, 3, 0.0); + PIMathMatrix matrix4(3, 3, 0.0); + PIMathVector vector; + vector.resize(3, 3.0); + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; + matrix1.setCol(0, vector); + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; + matrix1.setCol(1, vector); + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; + matrix1.setCol(2, vector); + d1 = matrix1.determinant(); + matrix2 = matrix1; + matrix1 = matrix2.invert(); + d2 = matrix1.determinant(); + matrix3 = matrix4.invert(); + ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrix_Test, transposed) { - PIMathMatrix origMatr; - double d1, d2; - PIMathMatrix matrix1; - PIMathMatrix matrix2; - PIMathMatrix matrix3; - PIMathVector vector; - vector.resize(3, 3.0); - vector[0] = 3.0; - vector[1] = 6.0; - vector[2] = 8.0; - matrix1.setCol(0, vector); - vector[0] = 2.0; - vector[1] = 1.0; - vector[2] = 4.0; - matrix1.setCol(1, vector); - vector[0] = 6.0; - vector[1] = 2.0; - vector[2] = 5.0; - matrix1.setCol(2, vector); - d1 = matrix1.determinant(); - matrix2 = matrix1.transposed(); - d2 = matrix2.determinant(); - matrix3 = matrix2.transposed(); - ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3)); + PIMathMatrix origMatr; + double d1, d2; + PIMathMatrix matrix1; + PIMathMatrix matrix2; + PIMathMatrix matrix3; + PIMathVector vector; + vector.resize(3, 3.0); + vector[0] = 3.0; + vector[1] = 6.0; + vector[2] = 8.0; + matrix1.setCol(0, vector); + vector[0] = 2.0; + vector[1] = 1.0; + vector[2] = 4.0; + matrix1.setCol(1, vector); + vector[0] = 6.0; + vector[1] = 2.0; + vector[2] = 5.0; + matrix1.setCol(2, vector); + d1 = matrix1.determinant(); + matrix2 = matrix1.transposed(); + d2 = matrix2.determinant(); + matrix3 = matrix2.transposed(); + ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3)); } TEST(PIMathMatrix_Test, matrixMultiplication) { - PIMathMatrix matrix1(2, 2, 1.5); - PIMathMatrix matrix2(2, 2, 2.5); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); + PIMathMatrix matrix1(2, 2, 1.5); + PIMathMatrix matrix2(2, 2, 2.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); } TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { - PIMathMatrix matrix1(2, 2, 1.5); - PIMathVector vector; - vector.resize(2, 2.5); - for(uint i = 0; i < 2; i++) { - if((matrix1 * vector)[i] != 7.5) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + PIMathMatrix matrix1(2, 2, 1.5); + PIMathVector vector; + vector.resize(2, 2.5); + for(uint i = 0; i < 2; i++) { + if((matrix1 * vector)[i] != 7.5) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { - PIMathMatrix matrix1(2, 2, 1.5); - PIMathVector vector; - vector.resize(2, 2.5); - for(uint i = 0; i < 2; i++) { - if((vector * matrix1)[i] != 7.5) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + PIMathMatrix matrix1(2, 2, 1.5); + PIMathVector vector; + vector.resize(2, 2.5); + for(uint i = 0; i < 2; i++) { + if((vector * matrix1)[i] != 7.5) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { - PIMathMatrix matrix1(3, 3, 1.5); - ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); + PIMathMatrix matrix1(3, 3, 1.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } TEST(PIMathMatrix_Test, hermitian) { - complex val; - complex res; - val.imag(1.0); - val.real(1.0); - PIMathMatrix> matrix(3, 3, val); - res.imag(-1.0); - res.real(1.0); - auto matr = hermitian(matrix); - for(uint i = 0; i < 3; i++) { - for(uint j = 0; j < 3; j++) { - if(matr.element(i, j) != res) { - ASSERT_TRUE(false); - } - } - } - ASSERT_TRUE(true); + complex val; + complex res; + val.imag(1.0); + val.real(1.0); + PIMathMatrix> matrix(3, 3, val); + res.imag(-1.0); + res.real(1.0); + auto matr = hermitian(matrix); + for(uint i = 0; i < 3; i++) { + for(uint j = 0; j < 3; j++) { + if(matr.element(i, j) != res) { + ASSERT_TRUE(false); + } + } + } + ASSERT_TRUE(true); } diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 013672ba..59cd14c9 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -5,558 +5,558 @@ const uint rows = 3; const uint cols = 3; bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, double val, int num) { - bool b = true; - for(int i = 0; i < num; i++) { - for(int j = 0; j < num; j++) { - if(matrix[i][j] - val >= double(1E-200)) { - b = false; - } - } - } - return b; + bool b = true; + for(int i = 0; i < num; i++) { + for(int j = 0; j < num; j++) { + if(matrix[i][j] - val >= double(1E-200)) { + b = false; + } + } + } + return b; } TEST(PIMathMatrixT_Test, identity) { - auto matrix = PIMathMatrixT::identity(); - for(int i = 0; i < 3; i++){ - for(int j = 0; j < 3; j++){ - if(i != j){ - if(matrix[i][j] != 0.0){ - ASSERT_TRUE(false); - } - } - else { - if(matrix[i][i] != 1.0){ - ASSERT_TRUE(false); - } - } - } - } - ASSERT_TRUE(true); + auto matrix = PIMathMatrixT::identity(); + for(int i = 0; i < 3; i++){ + for(int j = 0; j < 3; j++){ + if(i != j){ + if(matrix[i][j] != 0.0){ + ASSERT_TRUE(false); + } + } + else { + if(matrix[i][i] != 1.0){ + ASSERT_TRUE(false); + } + } + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, at) { - auto matrix1 = PIMathMatrixT::identity(); - for(uint i = 0; i < rows; i++) { - if(matrix1.at(i,i) != 1.0) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + auto matrix1 = PIMathMatrixT::identity(); + for(uint i = 0; i < rows; i++) { + if(matrix1.at(i,i) != 1.0) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, filled) { - auto matr = PIMathMatrixT::filled(1.0); - ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows)); + auto matr = PIMathMatrixT::filled(1.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows)); } TEST(PIMathMatrixT_Test, cols) { - PIMathMatrixT matr; - ASSERT_EQ(cols,matr.cols()); + PIMathMatrixT matr; + ASSERT_EQ(cols,matr.cols()); } TEST(PIMathMatrixT_Test, rows) { - PIMathMatrixT matr; - ASSERT_EQ(rows,matr.rows()); + PIMathMatrixT matr; + ASSERT_EQ(rows,matr.rows()); } TEST(PIMathMatrixT_Test, col) { - PIMathMatrixT matr; - PIMathVectorT vect; - uint g = 2; - matr[0][0] = 3; - matr[0][1] = 6; - matr[0][2] = 8; - matr[1][0] = 2; - matr[1][1] = 1; - matr[1][2] = 4; - matr[2][0] = 6; - matr[2][1] = 2; - matr[2][2] = 5; - vect = matr.col(g); - for(uint i = 0; i < matr.cols(); i++) { - if(matr.at(i, g) != vect.at(i)) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + PIMathMatrixT matr; + PIMathVectorT vect; + uint g = 2; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; + vect = matr.col(g); + for(uint i = 0; i < matr.cols(); i++) { + if(matr.at(i, g) != vect.at(i)) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, row) { - PIMathMatrixT matr; - PIMathVectorT vect; - uint g = 2; - matr[0][0] = 3; - matr[0][1] = 6; - matr[0][2] = 8; - matr[1][0] = 2; - matr[1][1] = 1; - matr[1][2] = 4; - matr[2][0] = 6; - matr[2][1] = 2; - matr[2][2] = 5; - vect = matr.row(g); - for(uint i = 0; i < matr.rows(); i++) { - if(matr.at(g, i) != vect.at(i)) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + PIMathMatrixT matr; + PIMathVectorT vect; + uint g = 2; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; + vect = matr.row(g); + for(uint i = 0; i < matr.rows(); i++) { + if(matr.at(g, i) != vect.at(i)) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, setCol) { - PIMathMatrixT matr; - PIMathVectorT vect; - vect[0] = 1.0; - vect[1] = 3.0; - vect[2] = 5.0; - uint g = 1; - matr.setCol(g, vect); - for(uint i = 0; i < vect.size(); i++) { - if(matr.at(i, g) != vect.at(i)) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + PIMathMatrixT matr; + PIMathVectorT vect; + vect[0] = 1.0; + vect[1] = 3.0; + vect[2] = 5.0; + uint g = 1; + matr.setCol(g, vect); + for(uint i = 0; i < vect.size(); i++) { + if(matr.at(i, g) != vect.at(i)) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, setRow) { - PIMathMatrixT matr; - PIMathVectorT vect; - vect[0] = 1.0; - vect[1] = 3.0; - vect[2] = 5.0; - uint g = 1; - matr.setRow(g, vect); - for(uint i = 0; i < vect.size(); i++) { - if(matr.at(g,i) != vect.at(i)) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + PIMathMatrixT matr; + PIMathVectorT vect; + vect[0] = 1.0; + vect[1] = 3.0; + vect[2] = 5.0; + uint g = 1; + matr.setRow(g, vect); + for(uint i = 0; i < vect.size(); i++) { + if(matr.at(g,i) != vect.at(i)) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, swapCols) { - PIMathMatrixT matr; - int g1 = 1, g2 = 2; - matr[0][0] = 3; - matr[0][1] = 6; - matr[0][2] = 8; - matr[1][0] = 2; - matr[1][1] = 1; - matr[1][2] = 4; - matr[2][0] = 6; - matr[2][1] = 2; - matr[2][2] = 5; - const PIMathVectorT before_Vect1 = matr.col(g1); - const PIMathVectorT before_Vect2 = matr.col(g2); - matr.swapCols(g1, g2); - const PIMathVectorT after_Vect1 = matr.col(g1); - const PIMathVectorT after_Vect2 = matr.col(g2); - if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { - ASSERT_TRUE(true); - } - else { - ASSERT_TRUE(false); - } + PIMathMatrixT matr; + int g1 = 1, g2 = 2; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; + const PIMathVectorT before_Vect1 = matr.col(g1); + const PIMathVectorT before_Vect2 = matr.col(g2); + matr.swapCols(g1, g2); + const PIMathVectorT after_Vect1 = matr.col(g1); + const PIMathVectorT after_Vect2 = matr.col(g2); + if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { + ASSERT_TRUE(true); + } + else { + ASSERT_TRUE(false); + } } TEST(PIMathMatrixT_Test, swapRows) { - PIMathMatrixT matr; - int g1 = 1, g2 = 2; - matr[0][0] = 3; - matr[0][1] = 6; - matr[0][2] = 8; - matr[1][0] = 2; - matr[1][1] = 1; - matr[1][2] = 4; - matr[2][0] = 6; - matr[2][1] = 2; - matr[2][2] = 5; - const PIMathVectorT before_Vect1 = matr.row(g1); - const PIMathVectorT before_Vect2 = matr.row(g2); - matr.swapRows(g1, g2); - const PIMathVectorT after_Vect1 = matr.row(g1); - const PIMathVectorT after_Vect2 = matr.row(g2); - if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { - ASSERT_TRUE(true); - } - else { - ASSERT_TRUE(false); - } + PIMathMatrixT matr; + int g1 = 1, g2 = 2; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; + const PIMathVectorT before_Vect1 = matr.row(g1); + const PIMathVectorT before_Vect2 = matr.row(g2); + matr.swapRows(g1, g2); + const PIMathVectorT after_Vect1 = matr.row(g1); + const PIMathVectorT after_Vect2 = matr.row(g2); + if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { + ASSERT_TRUE(true); + } + else { + ASSERT_TRUE(false); + } } TEST(PIMathMatrixT_Test, fill) { - PIMathMatrixT matr; - PIMathMatrixT matrix1; - double g = 1.0; - matr.fill(g); - for(uint i = 0; i < cols; i++) { - for(uint j = 0; j < rows; j++) { - matrix1[j][i] = g; - } - } - ASSERT_TRUE(matr == matrix1); + PIMathMatrixT matr; + PIMathMatrixT matrix1; + double g = 1.0; + matr.fill(g); + for(uint i = 0; i < cols; i++) { + for(uint j = 0; j < rows; j++) { + matrix1[j][i] = g; + } + } + ASSERT_TRUE(matr == matrix1); } TEST(PIMathMatrixT_Test, isSquareTrue) { - PIMathMatrixT matrix1; - ASSERT_TRUE(matrix1.isSquare()); + PIMathMatrixT matrix1; + ASSERT_TRUE(matrix1.isSquare()); } TEST(PIMathMatrixT_Test, isSquareFalse) { - const uint new_Cols = 4; - PIMathMatrixT matrix2; - ASSERT_FALSE(matrix2.isSquare()); + const uint new_Cols = 4; + PIMathMatrixT matrix2; + ASSERT_FALSE(matrix2.isSquare()); } TEST(PIMathMatrixT_Test, isIdentityTrue) { - auto matrix1 = PIMathMatrixT::identity(); - ASSERT_TRUE(matrix1.isIdentity()); + auto matrix1 = PIMathMatrixT::identity(); + ASSERT_TRUE(matrix1.isIdentity()); } TEST(PIMathMatrixT_Test, isIdentityFalse) { - auto matrix1 = PIMathMatrixT::filled(2.5); - ASSERT_FALSE(matrix1.isIdentity()); + auto matrix1 = PIMathMatrixT::filled(2.5); + ASSERT_FALSE(matrix1.isIdentity()); } TEST(PIMathMatrixT_Test, isNullTrue) { - PIMathMatrixT matrix1; - ASSERT_TRUE(matrix1.isNull()); + PIMathMatrixT matrix1; + ASSERT_TRUE(matrix1.isNull()); } TEST(PIMathMatrixT_Test, isNullFalse) { - auto matrix1 = PIMathMatrixT::identity(); - ASSERT_FALSE(matrix1.isNull()); + auto matrix1 = PIMathMatrixT::identity(); + ASSERT_FALSE(matrix1.isNull()); } TEST(PIMathMatrixT_Test, operator_Assignment) { - PIMathMatrixT matrix1; - auto matrix2 = PIMathMatrixT::filled(6.72); - matrix1 = matrix2; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); + PIMathMatrixT matrix1; + auto matrix2 = PIMathMatrixT::filled(6.72); + matrix1 = matrix2; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); } TEST(PIMathMatrixT_Test, operator_EqualTrue) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - matrix1[0][0] = 5.1; - matrix1[0][1] = 1.21; - matrix1[1][1] = 0.671; - matrix1[1][0] = 2.623; - matrix2[0][0] = 5.1; - matrix2[0][1] = 1.21; - matrix2[1][1] = 0.671; - matrix2[1][0] = 2.623; - ASSERT_TRUE(matrix1 == matrix2); + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1[0][0] = 5.1; + matrix1[0][1] = 1.21; + matrix1[1][1] = 0.671; + matrix1[1][0] = 2.623; + matrix2[0][0] = 5.1; + matrix2[0][1] = 1.21; + matrix2[1][1] = 0.671; + matrix2[1][0] = 2.623; + ASSERT_TRUE(matrix1 == matrix2); } TEST(PIMathMatrixT_Test, operator_EqualFalse) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - matrix1[0][0] = 5.1; - matrix1[0][1] = 1.21; - matrix1[1][1] = 0.671; - matrix1[1][0] = 2.623; - matrix2[0][0] = 5.1; - matrix2[0][1] = 1.21; - matrix2[1][1] = 665.671; - matrix2[1][0] = 2.623; - ASSERT_FALSE(matrix1 == matrix2); + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1[0][0] = 5.1; + matrix1[0][1] = 1.21; + matrix1[1][1] = 0.671; + matrix1[1][0] = 2.623; + matrix2[0][0] = 5.1; + matrix2[0][1] = 1.21; + matrix2[1][1] = 665.671; + matrix2[1][0] = 2.623; + ASSERT_FALSE(matrix1 == matrix2); } TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - matrix1[0][0] = 5.1; - matrix1[0][1] = 1.21; - matrix1[1][1] = 0.671; - matrix1[1][0] = 2.623; - matrix2[0][0] = 5.1; - matrix2[0][1] = 1.21; - matrix2[1][1] = 665.671; - matrix2[1][0] = 2.623; - ASSERT_TRUE(matrix1 != matrix2); + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1[0][0] = 5.1; + matrix1[0][1] = 1.21; + matrix1[1][1] = 0.671; + matrix1[1][0] = 2.623; + matrix2[0][0] = 5.1; + matrix2[0][1] = 1.21; + matrix2[1][1] = 665.671; + matrix2[1][0] = 2.623; + ASSERT_TRUE(matrix1 != matrix2); } TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - matrix1[0][0] = 5.1; - matrix1[0][1] = 1.21; - matrix1[1][1] = 0.671; - matrix1[1][0] = 2.623; - matrix2[0][0] = 5.1; - matrix2[0][1] = 1.21; - matrix2[1][1] = 0.671; - matrix2[1][0] = 2.623; - ASSERT_FALSE(matrix1 != matrix2); + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1[0][0] = 5.1; + matrix1[0][1] = 1.21; + matrix1[1][1] = 0.671; + matrix1[1][0] = 2.623; + matrix2[0][0] = 5.1; + matrix2[0][1] = 1.21; + matrix2[1][1] = 0.671; + matrix2[1][0] = 2.623; + ASSERT_FALSE(matrix1 != matrix2); } TEST(PIMathMatrixT_Test, operator_Addition_Assignment) { - auto matrix1 = PIMathMatrixT::filled(6.72) ; - auto matrix2 = PIMathMatrixT::filled(1.0) ; - matrix1 += matrix2; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); + auto matrix1 = PIMathMatrixT::filled(6.72) ; + auto matrix2 = PIMathMatrixT::filled(1.0) ; + matrix1 += matrix2; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { - auto matrix1 = PIMathMatrixT::filled(1.0); - auto matrix2 = PIMathMatrixT::filled(6.72); - matrix1 -= matrix2; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); + auto matrix1 = PIMathMatrixT::filled(1.0); + auto matrix2 = PIMathMatrixT::filled(6.72); + matrix1 -= matrix2; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) { - auto matrix1 = PIMathMatrixT::filled(6.72); - matrix1 *= 2.0; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); + auto matrix1 = PIMathMatrixT::filled(6.72); + matrix1 *= 2.0; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); } TEST(PIMathMatrixT_Test, operator_Division_Assignment) { - auto matrix1 = PIMathMatrixT::filled(6.72); - matrix1 /= 2.0; - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); + auto matrix1 = PIMathMatrixT::filled(6.72); + matrix1 /= 2.0; + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); } TEST(PIMathMatrixT_Test, operator_Addition) { - auto matrix1 = PIMathMatrixT::filled(6.72); - auto matrix2 = PIMathMatrixT::filled(8.28); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); + auto matrix1 = PIMathMatrixT::filled(6.72); + auto matrix2 = PIMathMatrixT::filled(8.28); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction) { - auto matrix1 = PIMathMatrixT::filled(6.0); - auto matrix2 = PIMathMatrixT::filled(5.0); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); + auto matrix1 = PIMathMatrixT::filled(6.0); + auto matrix2 = PIMathMatrixT::filled(5.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication) { - auto matrix1 = PIMathMatrixT::filled(6.72); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); } TEST(PIMathMatrixT_Test, operator_Division) { - auto matrix1 = PIMathMatrixT::filled(6.72); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); } TEST(PIMathMatrixT_Test, determinantIfSquare) { - double d; - double i = 59.0; - PIMathMatrixT matr; - matr[0][0] = 3; - matr[0][1] = 6; - matr[0][2] = 8; - matr[1][0] = 2; - matr[1][1] = 1; - matr[1][2] = 4; - matr[2][0] = 6; - matr[2][1] = 2; - matr[2][2] = 5; - d = matr.determinant(); - ASSERT_DOUBLE_EQ(i, d); + double d; + double i = 59.0; + PIMathMatrixT matr; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; + d = matr.determinant(); + ASSERT_DOUBLE_EQ(i, d); } TEST(PIMathMatrixT_Test, determinantIfNotSquare) { - PIMathMatrixT matr; - matr[0][0] = 3; - matr[0][1] = 6; - matr[0][2] = 8; - matr[1][0] = 2; - matr[1][1] = 1; - matr[1][2] = 4; - matr[2][0] = 6; - matr[2][1] = 2; - matr[2][2] = 5; - ASSERT_FALSE(matr.determinant()); + PIMathMatrixT matr; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; + ASSERT_FALSE(matr.determinant()); } TEST(PIMathMatrixT_Test, invert) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matrix3; - PIMathMatrixT matr; - double d1, d2; - matr[0][0] = 3; - matr[0][1] = 6; - matr[0][2] = 8; - matr[1][0] = 2; - matr[1][1] = 1; - matr[1][2] = 4; - matr[2][0] = 6; - matr[2][1] = 2; - matr[2][2] = 5; - matrix2 = matr; - matr.invert(); - d1 = matr.determinant(); - d2 = matrix2.determinant(); - matrix3 = matrix1; - matrix1.invert(); - ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2)); + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + PIMathMatrixT matrix3; + PIMathMatrixT matr; + double d1, d2; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; + matrix2 = matr; + matr.invert(); + d1 = matr.determinant(); + d2 = matrix2.determinant(); + matrix3 = matrix1; + matrix1.invert(); + ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2)); } TEST(PIMathMatrixT_Test, inverted) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matrix3; - PIMathMatrixT matr; - double d1, d2; - matrix1 = matr.identity(); - matr[0][0] = 3; - matr[0][1] = 6; - matr[0][2] = 8; - matr[1][0] = 2; - matr[1][1] = 1; - matr[1][2] = 4; - matr[2][0] = 6; - matr[2][1] = 2; - matr[2][2] = 5; - matrix2 = matr.inverted(); - d1 = matr.determinant(); - d2 = matrix2.determinant(); - matrix3 = matrix1.inverted(); - ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + PIMathMatrixT matrix3; + PIMathMatrixT matr; + double d1, d2; + matrix1 = matr.identity(); + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; + matrix2 = matr.inverted(); + d1 = matr.determinant(); + d2 = matrix2.determinant(); + matrix3 = matrix1.inverted(); + ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrixT_Test, toUpperTriangular) { - PIMathMatrixT matrix; - double d1, d2 = 1; - PIMathMatrixT matr; - matr[0][0] = 3; - matr[0][1] = 6; - matr[0][2] = 8; - matr[1][0] = 2; - matr[1][1] = 1; - matr[1][2] = 4; - matr[2][0] = 6; - matr[2][1] = 2; - matr[2][2] = 5; - matrix = matr.toUpperTriangular(); - d1 = matrix.determinant(); - for(uint i = 0; i < cols; i++) - { - d2 = d2*matrix.at(i,i); - } - ASSERT_DOUBLE_EQ(d1, d2); + PIMathMatrixT matrix; + double d1, d2 = 1; + PIMathMatrixT matr; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; + matrix = matr.toUpperTriangular(); + d1 = matrix.determinant(); + for(uint i = 0; i < cols; i++) + { + d2 = d2*matrix.at(i,i); + } + ASSERT_DOUBLE_EQ(d1, d2); } TEST(PIMathMatrixT_Test, transposed) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - double d1, d2; - matr[0][0] = 3; - matr[0][1] = 6; - matr[0][2] = 8; - matr[1][0] = 2; - matr[1][1] = 1; - matr[1][2] = 4; - matr[2][0] = 6; - matr[2][1] = 2; - matr[2][2] = 5; - d1 = matr.determinant(); - matrix1 = matr.transposed(); - d2 = matrix1.determinant(); - matrix2 = matrix1.transposed(); - ASSERT_TRUE((d1 == d2) && (matr == matrix2)); + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + PIMathMatrixT matr; + double d1, d2; + matr[0][0] = 3; + matr[0][1] = 6; + matr[0][2] = 8; + matr[1][0] = 2; + matr[1][1] = 1; + matr[1][2] = 4; + matr[2][0] = 6; + matr[2][1] = 2; + matr[2][2] = 5; + d1 = matr.determinant(); + matrix1 = matr.transposed(); + d2 = matrix1.determinant(); + matrix2 = matrix1.transposed(); + ASSERT_TRUE((d1 == d2) && (matr == matrix2)); } TEST(PIMathMatrixT_Test, scaleX_two) { - double factor = 5.64; - PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); - ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))); + double factor = 5.64; + PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); + ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))); } TEST(PIMathMatrixT_Test, scaleY_two) { - double factor = 5.64; - PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor); - ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))); + double factor = 5.64; + PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor); + ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))); } TEST(PIMathMatrixT_Test, rotation_2x2) { - double angle = 1.0; - PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); - double c = cos(angle); - double s = sin(angle); - ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))); + double angle = 1.0; + PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); + double c = cos(angle); + double s = sin(angle); + ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))); } TEST(PIMathMatrixT_Test, rotation_3x3) { - double angle = 1.0; - PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows)); + double angle = 1.0; + PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows)); } TEST(PIMathMatrixT_Test, rotationX) { - double angle = 1.0; - double c = cos(angle); - double s = sin(angle); - PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(angle); - ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))); + double angle = 1.0; + double c = cos(angle); + double s = sin(angle); + PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(angle); + ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))); } TEST(PIMathMatrixT_Test, rotationY) { - double angle = 1.0; - double c = cos(angle); - double s = sin(angle); - PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(angle); - ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))); + double angle = 1.0; + double c = cos(angle); + double s = sin(angle); + PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(angle); + ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))); } TEST(PIMathMatrixT_Test, rotationZ) { - double angle = 1.0; - double c = cos(angle); - double s = sin(angle); - PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(angle); - ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))); + double angle = 1.0; + double c = cos(angle); + double s = sin(angle); + PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(angle); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))); } TEST(PIMathMatrixT_Test, scaleX_three) { - double factor = 23.65; - PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); - ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); + double factor = 23.65; + PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, scaleY_three) { - double factor = 23.65; - PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); - ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))); + double factor = 23.65; + PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, scaleZ_three) { - double factor = 23.65; - PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); - ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); + double factor = 23.65; + PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); + ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, matrixMultiplication) { - auto matrix1 = PIMathMatrixT::filled(1.5); - auto matrix2 = PIMathMatrixT::filled(2.5); - ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3)); + auto matrix1 = PIMathMatrixT::filled(1.5); + auto matrix2 = PIMathMatrixT::filled(2.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3)); } TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) { - auto matrix1 = PIMathMatrixT::filled(1.5); - auto vector = PIMathVectorT::filled(2.5); - for(uint i = 0; i < 2; i++) { - if((matrix1 * vector)[i] != 11.25) { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + auto matrix1 = PIMathMatrixT::filled(1.5); + auto vector = PIMathVectorT::filled(2.5); + for(uint i = 0; i < 2; i++) { + if((matrix1 * vector)[i] != 11.25) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) { - auto matrix1 = PIMathMatrixT::filled(1.5); - auto vector = PIMathVectorT::filled(2.5); - for(uint i = 0; i < 2; i++) { - if((vector * matrix1)[i] != 11.25) { - ASSERT_TRUE(false); - } - } + auto matrix1 = PIMathMatrixT::filled(1.5); + auto vector = PIMathVectorT::filled(2.5); + for(uint i = 0; i < 2; i++) { + if((vector * matrix1)[i] != 11.25) { + ASSERT_TRUE(false); + } + } } TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) { - auto matrix1 = PIMathMatrixT::filled(1.5); - ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); + auto matrix1 = PIMathMatrixT::filled(1.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } diff --git a/tests/math/testpimathvector.cpp b/tests/math/testpimathvector.cpp index 3556ac55..9ac59f1a 100644 --- a/tests/math/testpimathvector.cpp +++ b/tests/math/testpimathvector.cpp @@ -2,446 +2,622 @@ #include "pimathvector.h" const uint SIZE = 3u; +const double angle45DegInRad = 0.78539816339744830961566084581988; bool cmpVectorWithValue(PIMathVector vector, double val, int num) { - bool b = true; - for(int i = 0; i < num; i++) { - if(vector[i] - val >= double(1E-200)) { - b = false; - } - } - return b; + bool b = true; + for(int i = 0; i < num; i++) { + if(vector[i] - val >= double(1E-200)) { + b = false; + } + } + return b; } TEST(PIMathVector_Test, size) { - auto vector = PIMathVector(SIZE); - ASSERT_TRUE(vector.size() == SIZE); + auto vector = PIMathVector(SIZE); + ASSERT_TRUE(vector.size() == SIZE); } TEST(PIMathVector_Test, resize) { - uint newSize = 4u; - double a = 5.0; - PIMathVector vector; - vector.resize(newSize, a); - ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size())); - ASSERT_TRUE(vector.size() == newSize); + uint newSize = 4u; + double a = 5.0; + PIMathVector vector; + vector.resize(newSize, a); + ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size())); + ASSERT_TRUE(vector.size() == newSize); } TEST(PIMathVector_Test, resized) { - uint newSize = 4u; - double a = 5.0; - PIMathVector vector; - auto vect = vector.resized(newSize, a); - ASSERT_TRUE(cmpVectorWithValue(vect, a, vect.size()) && vect.size() == newSize); - ASSERT_TRUE(vect.size() == newSize); + uint newSize = 4u; + double a = 5.0; + PIMathVector vector; + auto vect = vector.resized(newSize, a); + ASSERT_TRUE(cmpVectorWithValue(vect, a, vect.size())); + ASSERT_TRUE(vect.size() == newSize); } TEST(PIMathVector_Test, fill) { - double a = 5.0; - PIMathVector vector(SIZE); - vector.fill(a); - ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); + double a = 5.0; + PIMathVector vector(SIZE); + vector.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVector_Test, moveVal) { - double a = 5.0; - PIMathVector vector(SIZE); - vector.fill(a); - vector.move(a); - ASSERT_TRUE(cmpVectorWithValue(vector, 2 * a, SIZE)); + double a = 5.0; + PIMathVector vector(SIZE); + vector.fill(a); + vector.move(a); + ASSERT_TRUE(cmpVectorWithValue(vector, 2 * a, SIZE)); } TEST(PIMathVector_Test, moveVec) { - double a = 5.0; - double b = 7.0; - PIMathVector vector(SIZE); - PIMathVector vec(SIZE); - vector.fill(a); - vec.fill(b); - vector.move(vec); - ASSERT_TRUE(cmpVectorWithValue(vector, a + b, SIZE)); + double a = 5.0; + double b = 7.0; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vector.fill(a); + vec.fill(b); + vector.move(vec); + ASSERT_TRUE(cmpVectorWithValue(vector, a + b, SIZE)); +} + +TEST(PIMathVector_Test, moveVecSizeNotEq) { + double a = 5.0; + double b = 7.0; + uint bias = 2u; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE + bias); + vector.fill(a); + vec.fill(b); + vector.move(vec); + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); + ASSERT_TRUE(vector.size() == SIZE); } TEST(PIMathVector_Test, swap) { - double b = 5.12; - double c = 3.32; - double d = 7.12; - PIMathVector vector(SIZE); - double a[3]; - vector[0] = b; - vector[1] = c; - vector[2] = d; - a[0] = vector[0]; - a[1] = vector[1]; - a[2] = vector[2]; - vector.swap(0u, 1u); - ASSERT_DOUBLE_EQ(a[0], vector[1]); - ASSERT_DOUBLE_EQ(a[1], vector[0]); - ASSERT_DOUBLE_EQ(a[2], vector[2]); + double b = 5.12; + double c = 3.32; + double d = 7.12; + PIMathVector vector(SIZE); + double a[3]; + vector[0] = b; + vector[1] = c; + vector[2] = d; + a[0] = vector[0]; + a[1] = vector[1]; + a[2] = vector[2]; + vector.swap(0u, 1u); + ASSERT_DOUBLE_EQ(a[0], vector[1]); + ASSERT_DOUBLE_EQ(a[1], vector[0]); + ASSERT_DOUBLE_EQ(a[2], vector[2]); } TEST(PIMathVector_Test, lengthSqr) { - double a = 3.0; - PIMathVector vector(SIZE); - vector.fill(a); - ASSERT_DOUBLE_EQ(SIZE * a * a, vector.lengthSqr()); + double a = 3.0; + PIMathVector vector(SIZE); + vector.fill(a); + ASSERT_DOUBLE_EQ(SIZE * a * a, vector.lengthSqr()); } TEST(PIMathVector_Test, length) { - double a = 3.32; - PIMathVector vector(SIZE); - vector.fill(a); - ASSERT_DOUBLE_EQ(sqrt(SIZE * a * a), vector.length()); + double a = 3.32; + PIMathVector vector(SIZE); + vector.fill(a); + ASSERT_DOUBLE_EQ(sqrt(SIZE * a * a), vector.length()); } TEST(PIMathVector_Test, manhattanLength) { - double a = 3.32; - PIMathVector vector(SIZE); - vector.fill(a); - ASSERT_DOUBLE_EQ(SIZE * a, vector.manhattanLength()); + double a = 3.32; + PIMathVector vector(SIZE); + vector.fill(a); + ASSERT_DOUBLE_EQ(SIZE * a, vector.manhattanLength()); } TEST(PIMathVector_Test, angleCos) { - double a = 3.32; - double angle = 0.78539816339744830961566084581988; - PIMathVector vector(SIZE); - PIMathVector vec(SIZE); - vector[0] = a; - vector[1] = a; - vec[1] = a; - ASSERT_DOUBLE_EQ(cos(angle), vector.angleCos(vec)); + double a = 3.32; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(cos(angle45DegInRad), vector.angleCos(vec)); +} + +TEST(PIMathVector_Test, angleCosSizeNotEq) { + double a = 3.32; + uint bias = 2u; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE + bias); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_FALSE(vector.angleCos(vec)); } TEST(PIMathVector_Test, angleSin) { - double a = 3.32; - double angle = 0.78539816339744830961566084581988; - PIMathVector vector(SIZE); - PIMathVector vec(SIZE); - vector[0] = a; - vector[1] = a; - vec[1] = a; - ASSERT_DOUBLE_EQ(sin(angle), vector.angleSin(vec)); + double a = 3.32; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(sin(angle45DegInRad), vector.angleSin(vec)); +} + +TEST(PIMathVector_Test, angleSinSizeNotEq) { + double a = 3.32; + uint bias = 2u; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE + bias); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_FALSE(vector.angleSin(vec)); } TEST(PIMathVector_Test, angleRad) { - double a = 3.32; - double angle = 0.78539816339744830961566084581988; - PIMathVector vector(SIZE); - PIMathVector vec(SIZE); - vector[0] = a; - vector[1] = a; - vec[1] = a; - ASSERT_DOUBLE_EQ(angle, vector.angleRad(vec)); + double a = 3.32; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(angle45DegInRad, vector.angleRad(vec)); +} + +TEST(PIMathVector_Test, angleRadSizeNotEq) { + double a = 3.32; + uint bias = 2u; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE + bias); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_FALSE(vector.angleRad(vec)); } TEST(PIMathVector_Test, angleDeg) { - double a = 3.32; - double angle = 45.0; - PIMathVector vector(SIZE); - PIMathVector vec(SIZE); - vector[0] = a; - vector[1] = a; - vec[1] = a; - ASSERT_DOUBLE_EQ(angle, vector.angleDeg(vec)); + double a = 3.32; + double angle45Deg = 45.0; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(angle45Deg, vector.angleDeg(vec)); +} + +TEST(PIMathVector_Test, angleDegSizeNotEq) { + double a = 3.32; + uint bias = 2u; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE + bias); + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_FALSE(vector.angleDeg(vec)); } TEST(PIMathVector_Test, projection) { - double a = 2.0; - double b = 2.0; - double res = sqrt(32.0); - PIMathVector vector(SIZE); - PIMathVector vec(SIZE); - vec[0] = a; - vec[2] = b; - vector[0] = a; - vector[1] = b; - vector[2] = a; - auto vecProj = vector.projection(vec); - ASSERT_DOUBLE_EQ(res, vecProj[0]); - ASSERT_DOUBLE_EQ(0.0, vecProj[1]); - ASSERT_DOUBLE_EQ(res, vecProj[2]); + double a = 2.0; + double b = 2.0; + double res = sqrt(32.0); + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vec[0] = a; + vec[2] = b; + vector[0] = a; + vector[1] = b; + vector[2] = a; + auto vecProj = vector.projection(vec); + ASSERT_DOUBLE_EQ(res, vecProj[0]); + ASSERT_DOUBLE_EQ(0.0, vecProj[1]); + ASSERT_DOUBLE_EQ(res, vecProj[2]); +} + +TEST(PIMathVector_Test, projectionSizeNotEq) { + double a = 2.0; + double b = 2.0; + uint bias = 2u; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE + bias); + vec[0] = a; + vec[2] = b; + vector[0] = a; + vector[1] = b; + vector[2] = a; + auto vecProj = vector.projection(vec); + ASSERT_DOUBLE_EQ(a, vecProj[0]); + ASSERT_DOUBLE_EQ(b, vecProj[1]); + ASSERT_DOUBLE_EQ(a, vecProj[2]); } TEST(PIMathVector_Test, normalize) { - double a = 5.0; - PIMathVector vector(SIZE); - vector.fill(a); - ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), a / sqrt(SIZE * a * a), SIZE)); + double a = 5.0; + PIMathVector vector(SIZE); + vector.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), a / sqrt(SIZE * a * a), SIZE)); } TEST(PIMathVector_Test, normalized) { - double a = 5.0; - PIMathVector vector(SIZE); - PIMathVector vectorNew(SIZE); - vector.fill(a); - vectorNew = vector.normalized(); - ASSERT_TRUE(cmpVectorWithValue(vectorNew, a / sqrt(SIZE * a * a), SIZE)); + double a = 5.0; + PIMathVector vector(SIZE); + PIMathVector vectorNew(SIZE); + vector.fill(a); + vectorNew = vector.normalized(); + ASSERT_TRUE(cmpVectorWithValue(vectorNew, a / sqrt(SIZE * a * a), SIZE)); } TEST(PIMathVector_Test, isNullTrue) { - PIMathVector vector(SIZE); - ASSERT_TRUE(vector.isNull()); + PIMathVector vector(SIZE); + ASSERT_TRUE(vector.isNull()); } TEST(PIMathVector_Test, isNullFalse) { - PIMathVector vector(SIZE); - vector[0] = 6.273; - ASSERT_FALSE(vector.isNull()); + PIMathVector vector(SIZE); + vector[0] = 6.273; + ASSERT_FALSE(vector.isNull()); } TEST(PIMathVector_Test, isValidTrue) { - PIMathVector vector(SIZE); - ASSERT_TRUE(vector.isValid()); + PIMathVector vector(SIZE); + ASSERT_TRUE(vector.isValid()); } TEST(PIMathVector_Test, isValidFalse) { - PIMathVector vector; - ASSERT_FALSE(vector.isValid()); + PIMathVector vector; + ASSERT_FALSE(vector.isValid()); } TEST(PIMathVector_Test, isOrthoTrue) { - uint sizeNew = 2u; - double a = 2.0; - double b = 1.0; - PIMathVector vector(sizeNew); - PIMathVector vect(sizeNew); - vector[0] = a; - vect[1] = b; - ASSERT_TRUE(vector.isOrtho(vect)); + uint sizeNew = 2u; + double a = 2.0; + double b = 1.0; + PIMathVector vector(sizeNew); + PIMathVector vect(sizeNew); + vector[0] = a; + vect[1] = b; + ASSERT_TRUE(vector.isOrtho(vect)); } TEST(PIMathVector_Test, isOrthoFalse) { - uint sizeNew = 2u; - double a = 2.0; - double b = 1.0; - double c = 5.0; - PIMathVector vector(sizeNew); - PIMathVector vect(sizeNew); - vector[0] = a; - vect[0] = c; - vect[1] = b; - ASSERT_FALSE(vector.isOrtho(vect)); + uint sizeNew = 2u; + double a = 2.0; + double b = 1.0; + double c = 5.0; + PIMathVector vector(sizeNew); + PIMathVector vect(sizeNew); + vector[0] = a; + vect[0] = c; + vect[1] = b; + ASSERT_FALSE(vector.isOrtho(vect)); } TEST(PIMathVector_Test, at) { - double a = 5.5; - PIMathVector vector(SIZE); - vector.fill(a); - for(uint i = 0; i < SIZE; i++){ - if(vector.at(i) - a >= double(1E-200)){ - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + double a = 5.5; + PIMathVector vector(SIZE); + vector.fill(a); + for(uint i = 0; i < SIZE; i++){ + if(vector.at(i) - a >= double(1E-200)){ + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathVector_Test, operator_AssignmentValue) { - double a = 5.5; - PIMathVector vector(SIZE); - vector = a; - ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); + double a = 5.5; + PIMathVector vector(SIZE); + vector = a; + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVector_Test, operator_AssignmentVector) { - double a = 5.5; - PIMathVector vector(SIZE); - PIMathVector vec(SIZE); - vec = a; - vector = vec; - ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); + double a = 5.5; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE); + vec = a; + vector = vec; + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); +} + +TEST(PIMathVector_Test, operator_AssignmentVectorSizeNotEq) { + double a = 5.5; + double b = 1.43; + uint bias = 2u; + PIMathVector vector(SIZE); + PIMathVector vec(SIZE + bias); + vector = b; + vec = a; + vector = vec; + ASSERT_TRUE(cmpVectorWithValue(vector, b, SIZE)); } TEST(PIMathVector_Test, operator_EqualTrue) { - double a = 5.12; - double b = 7.34; - uint newSize = 2u; - PIMathVector vector(newSize); - PIMathVector vec(newSize); - vector[0] = a; - vector[1] = b; - vec[0] = a; - vec[1] = b; - ASSERT_TRUE(vec == vector); + double a = 5.12; + double b = 7.34; + uint newSize = 2u; + PIMathVector vector(newSize); + PIMathVector vec(newSize); + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = b; + ASSERT_TRUE(vec == vector); } TEST(PIMathVector_Test, operator_EqualFalse) { - double a = 5.12; - double b = 7.34; - double c = 7.332; - uint newSize = 2u; - PIMathVector vector(newSize); - PIMathVector vec(newSize); - vector[0] = a; - vector[1] = b; - vec[0] = a; - vec[1] = c; - ASSERT_FALSE(vec == vector); + double a = 5.12; + double b = 7.34; + double c = 7.332; + uint newSize = 2u; + PIMathVector vector(newSize); + PIMathVector vec(newSize); + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = c; + ASSERT_FALSE(vec == vector); } TEST(PIMathVector_Test, operator_Not_EqualTrue) { - double a = 5.12; - double b = 7.34; - double c = 7.332; - uint newSize = 2u; - PIMathVector vector(newSize); - PIMathVector vec(newSize); - vector[0] = a; - vector[1] = b; - vec[0] = a; - vec[1] = c; - ASSERT_TRUE(vec != vector); + double a = 5.12; + double b = 7.34; + double c = 7.332; + uint newSize = 2u; + PIMathVector vector(newSize); + PIMathVector vec(newSize); + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = c; + ASSERT_TRUE(vec != vector); } TEST(PIMathVector_Test, operator_Not_EqualFalse) { - double a = 5.12; - double b = 7.34; - uint newSize = 2u; - PIMathVector vector(newSize); - PIMathVector vec(newSize); - vector[0] = a; - vector[1] = b; - vec[0] = a; - vec[1] = b; - ASSERT_FALSE(vec != vector); + double a = 5.12; + double b = 7.34; + uint newSize = 2u; + PIMathVector vector(newSize); + PIMathVector vec(newSize); + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = b; + ASSERT_FALSE(vec != vector); } -TEST(PIMathVector_Test, operator_Addition_Aassignment) { - double a = 6.0; - double b = 1.72; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1.fill(a); - vector2.fill(b); - vector1 += vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, a + b, SIZE)); +TEST(PIMathVector_Test, operator_Addition_Assignment) { + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + vector1 += vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a + b, SIZE)); +} + +TEST(PIMathVector_Test, operator_Addition_Assignment_sizeNotEq) { + double a = 6.0; + double b = 1.72; + uint bias = 2u; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE + bias); + vector1.fill(a); + vector2.fill(b); + vector1 += vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a, SIZE)); } TEST(PIMathVector_Test, operator_Subtraction_Assignment) { - double a = 6.0; - double b = 1.72; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1.fill(a); - vector2.fill(b); - vector1 -= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, a - b, SIZE)); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + vector1 -= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a - b, SIZE)); +} + +TEST(PIMathVector_Test, operator_Subtraction_Assignment_sizeNotEq) { + double a = 6.0; + double b = 1.72; + uint bias = 2u; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE + bias); + vector1.fill(a); + vector2.fill(b); + vector1 -= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a, SIZE)); } TEST(PIMathVector_Test, operator_Multiplication_AssignmentValue) { - double a = 6.0; - double b = 4.0; - PIMathVector vector1(SIZE); - vector1.fill(a); - vector1 *= b; - ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); + double a = 6.0; + double b = 4.0; + PIMathVector vector1(SIZE); + vector1.fill(a); + vector1 *= b; + ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); } TEST(PIMathVector_Test, operator_Multiplication_AssignmentVector) { - double a = 6.0; - double b = 1.72; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1.fill(a); - vector2.fill(b); - vector1 *= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + vector1 *= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); +} + +TEST(PIMathVector_Test, operator_Multiplication_AssignmentVector_sizeNotEq) { + double a = 6.0; + double b = 1.72; + uint bias = 2u; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE + bias); + vector1.fill(a); + vector2.fill(b); + vector1 *= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a, SIZE)); } TEST(PIMathVector_Test, operator_Division_AssignmentValue) { - double a = 6.0; - double b = 4.0; - PIMathVector vector1(SIZE); - vector1.fill(a); - vector1 /= b; - ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); + double a = 6.0; + double b = 4.0; + PIMathVector vector1(SIZE); + vector1.fill(a); + vector1 /= b; + ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); } TEST(PIMathVector_Test, operator_Division_AssignmentVector) { - double a = 6.0; - double b = 1.5; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1.fill(a); - vector2.fill(b); - vector1 /= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); + double a = 6.0; + double b = 1.5; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + vector1 /= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); +} + +TEST(PIMathVector_Test, operator_Division_AssignmentVector_sizeNotEq) { + double a = 6.0; + double b = 1.72; + uint bias = 2u; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE + bias); + vector1.fill(a); + vector2.fill(b); + vector1 /= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a, SIZE)); } TEST(PIMathVector_Test, operator_Addition) { - double a = 6.0; - double b = 1.72; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, a + b, SIZE)); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, a + b, SIZE)); +} + +TEST(PIMathVector_Test, operator_AdditionSizeNotEq) { + double a = 6.0; + double b = 1.72; + uint bias = 2u; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE + bias); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, a, SIZE)); } TEST(PIMathVector_Test, operator_Subtraction) { - double a = 6.0; - double b = 1.72; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, a - b, SIZE)); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, a - b, SIZE)); +} + +TEST(PIMathVector_Test, operator_SubtractionSizeNotEq) { + double a = 6.0; + double b = 1.72; + uint bias = 2u; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE + bias); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, a, SIZE)); } TEST(PIMathVector_Test, operator_MultiplicationValue) { - double a = 6.0; - double b = 4.0; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1.fill(a); - ASSERT_TRUE(cmpVectorWithValue(vector1 * b, a * b, SIZE)); + double a = 6.0; + double b = 4.0; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector1 * b, a * b, SIZE)); } TEST(PIMathVector_Test, operator_MultiplicationVector1) { - double a = 6.0; - double b = 1.72; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, SIZE)); + double a = 6.0; + double b = 1.72; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, SIZE)); } TEST(PIMathVector_Test, operator_MultiplicationVector2) { - double a = 1.0; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1[0] = a; - vector2[1] = a; - auto crossVec = vector1 * vector2; - ASSERT_DOUBLE_EQ(crossVec[0], 0.0); - ASSERT_DOUBLE_EQ(crossVec[1], 0.0); - ASSERT_DOUBLE_EQ(crossVec[2], a); + double a = 1.0; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1[0] = a; + vector2[1] = a; + auto crossVec = vector1 * vector2; + ASSERT_DOUBLE_EQ(crossVec[0], 0.0); + ASSERT_DOUBLE_EQ(crossVec[1], 0.0); + ASSERT_DOUBLE_EQ(crossVec[2], a); } TEST(PIMathVector_Test, operator_DivisionValue) { - double a = 6.0; - double b = 4.0; - PIMathVector vector1(SIZE); - vector1.fill(a); - ASSERT_TRUE(cmpVectorWithValue(vector1 / b, a / b, SIZE)); + double a = 6.0; + double b = 4.0; + PIMathVector vector1(SIZE); + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector1 / b, a / b, SIZE)); } TEST(PIMathVector_Test, operator_MultiplVect) { - double a = 6.0; - double b = 5.0; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, a * b, SIZE)); + double a = 6.0; + double b = 5.0; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, a * b, SIZE)); +} + +TEST(PIMathVector_Test, operator_MultiplVectSizeNotEq) { + double a = 6.0; + double b = 5.0; + uint bias = 2u; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE + bias); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, a , SIZE)); } TEST(PIMathVector_Test, operator_DotProduct) { - double a = 6.0; - double b = 5.0; - PIMathVector vector1(SIZE); - PIMathVector vector2(SIZE); - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(SIZE * a * b == (vector1 ^ vector2)); + double a = 6.0; + double b = 5.0; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE); + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(SIZE * a * b == (vector1 ^ vector2)); +} + +TEST(PIMathVector_Test, operator_DotProductSizeNotEq) { + double a = 6.0; + double b = 5.0; + uint bias = 2u; + PIMathVector vector1(SIZE); + PIMathVector vector2(SIZE + bias); + vector1.fill(a); + vector2.fill(b); + ASSERT_FALSE(vector1 ^ vector2); } diff --git a/tests/math/testpimathvectort.cpp b/tests/math/testpimathvectort.cpp index 738c663d..f29a7527 100644 --- a/tests/math/testpimathvectort.cpp +++ b/tests/math/testpimathvectort.cpp @@ -3,509 +3,507 @@ #include "pimathmatrix.h" const uint SIZE = 3u; +const double angle45DegInRad = 0.78539816339744830961566084581988; bool cmpVectorWithValue(PIMathVectorT vector, double val, int num) { - bool b = true; - for(int i = 0; i < num; i++) { - if(vector[i] - val >= double(1E-200)) { - b = false; - } - } - return b; + bool b = true; + for(int i = 0; i < num; i++) { + if(vector[i] - val >= double(1E-200)) { + b = false; + } + } + return b; } TEST(PIMathVectorT_Test, size) { - PIMathVectorT vector; - ASSERT_TRUE(vector.size() == SIZE); + PIMathVectorT vector; + ASSERT_TRUE(vector.size() == SIZE); } TEST(PIMathVectorT_Test, fill) { - double a = 5.0; - PIMathVectorT vector; - ASSERT_TRUE(cmpVectorWithValue(vector.fill(a), a, SIZE)); + double a = 5.0; + PIMathVectorT vector; + ASSERT_TRUE(cmpVectorWithValue(vector.fill(a), a, SIZE)); } TEST(PIMathVectorT_Test, set) { - double a = 5.0; - double b = 3.0; - PIMathVectorT vector; - PIMathVectorT vector1; - PIMathVectorT vector2; - ASSERT_TRUE(cmpVectorWithValue(vector.set(vector1.fill(a), vector2.fill(b)), b - a, SIZE)); + double a = 5.0; + double b = 3.0; + PIMathVectorT vector; + PIMathVectorT vector1; + PIMathVectorT vector2; + ASSERT_TRUE(cmpVectorWithValue(vector.set(vector1.fill(a), vector2.fill(b)), b - a, SIZE)); } TEST(PIMathVectorT_Test, MoveVal) { - double a = 4.0; - PIMathVectorT vector; - ASSERT_TRUE(cmpVectorWithValue(vector.move(a), a, SIZE)); + double a = 4.0; + PIMathVectorT vector; + ASSERT_TRUE(cmpVectorWithValue(vector.move(a), a, SIZE)); } TEST(PIMathVectorT_Test, MoveVector) { - double a = 5.0; - PIMathVectorT vector; - PIMathVectorT vector1; - ASSERT_TRUE(cmpVectorWithValue(vector.move(vector1.fill(a)), a, SIZE)); + double a = 5.0; + PIMathVectorT vector; + PIMathVectorT vector1; + ASSERT_TRUE(cmpVectorWithValue(vector.move(vector1.fill(a)), a, SIZE)); } TEST(PIMathVectorT_Test, lengthSqr) { - double a = 1.0; - PIMathVectorT vector; - vector.fill(a); - ASSERT_DOUBLE_EQ(SIZE * a, vector.lengthSqr()); + double a = 1.0; + PIMathVectorT vector; + vector.fill(a); + ASSERT_DOUBLE_EQ(SIZE * a, vector.lengthSqr()); } TEST(PIMathVectorT_Test, length) { - double a = 1.0; - PIMathVectorT vector; - vector.fill(a); - ASSERT_DOUBLE_EQ(sqrt(SIZE * a), vector.length()); + double a = 1.0; + PIMathVectorT vector; + vector.fill(a); + ASSERT_DOUBLE_EQ(sqrt(SIZE * a), vector.length()); } TEST(PIMathVectorT_Test, manhattanLength) { - double a = 5.0; - PIMathVectorT vector; - vector.fill(a); - ASSERT_DOUBLE_EQ(SIZE * a, vector.manhattanLength()); + double a = 5.0; + PIMathVectorT vector; + vector.fill(a); + ASSERT_DOUBLE_EQ(SIZE * a, vector.manhattanLength()); } TEST(PIMathVectorT_Test, angleCos) { - double a = 1.0; - double angle = 0.78539816339744830961566084581988; - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = a; - vector[1] = a; - vec[1] = a; - ASSERT_DOUBLE_EQ(cos(angle), vector.angleCos(vec)); + double a = 1.0; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(cos(angle45DegInRad), vector.angleCos(vec)); } TEST(PIMathVectorT_Test, angleSin) { - double a = 1.0; - double angle = 0.78539816339744830961566084581988; - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = a; - vector[1] = a; - vec[1] = a; - ASSERT_DOUBLE_EQ(sin(angle), vector.angleSin(vec)); + double a = 1.0; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(sin(angle45DegInRad), vector.angleSin(vec)); } TEST(PIMathVectorT_Test, angleRad) { - double a = 1.0; - double angle = 0.78539816339744830961566084581988; - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = a; - vector[1] = a; - vec[1] = a; - ASSERT_DOUBLE_EQ(angle, vector.angleRad(vec)); + double a = 1.0; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(angle45DegInRad, vector.angleRad(vec)); } TEST(PIMathVectorT_Test, angleDeg) { - double a = 1.0; - double angle = 45.0; - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = a; - vector[1] = a; - vec[1] = a; - ASSERT_DOUBLE_EQ(angle, vector.angleDeg(vec)); + double a = 1.0; + double angle45inDeg = 45.0; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(angle45inDeg, vector.angleDeg(vec)); } TEST(PIMathVectorT_Test, angleElevation) { - double a = 1.0; - double angle = 45.0; - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = a; - vector[1] = a; - vec[1] = a; - ASSERT_DOUBLE_EQ(-angle, vector.angleElevation(vec)); + double a = 1.0; + double angle45inDeg = 45.0; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = a; + vec[1] = a; + ASSERT_DOUBLE_EQ(-angle45inDeg, vector.angleElevation(vec)); } TEST(PIMathVectorT_Test, projection) { - double a = 2.0; - double b = 2.0; - double res = sqrt(32.0); - PIMathVectorT vector; - PIMathVectorT vec; - vec[0] = a; - vec[2] = b; - vector[0] = a; - vector[1] = b; - vector[2] = a; - auto vecProj = vector.projection(vec); - ASSERT_DOUBLE_EQ(res, vecProj[0]); - ASSERT_DOUBLE_EQ(0.0, vecProj[1]); - ASSERT_DOUBLE_EQ(res, vecProj[2]); + double a = 2.0; + double b = 2.0; + double res = sqrt(32.0); + PIMathVectorT vector; + PIMathVectorT vec; + vec[0] = a; + vec[2] = b; + vector[0] = a; + vector[1] = b; + vector[2] = a; + auto vecProj = vector.projection(vec); + ASSERT_DOUBLE_EQ(res, vecProj[0]); + ASSERT_DOUBLE_EQ(0.0, vecProj[1]); + ASSERT_DOUBLE_EQ(res, vecProj[2]); } TEST(PIMathVectorT_Test, normalize) { - double a = 5.0; - PIMathVectorT vector; - vector.fill(a); - ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), a / sqrt(SIZE * a * a), SIZE)); + double a = 5.0; + PIMathVectorT vector; + vector.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), a / sqrt(SIZE * a * a), SIZE)); } TEST(PIMathVectorT_Test, normalized) { - double a = 5.0; - PIMathVectorT vector; - PIMathVectorT vectorNew; - vector.fill(a); - vectorNew = vector.normalized(); - ASSERT_TRUE(cmpVectorWithValue(vectorNew, a / sqrt(SIZE * a * a), SIZE)); + double a = 5.0; + PIMathVectorT vector; + PIMathVectorT vectorNew; + vector.fill(a); + vectorNew = vector.normalized(); + ASSERT_TRUE(cmpVectorWithValue(vectorNew, a / sqrt(SIZE * a * a), SIZE)); } TEST(PIMathVectorT_Test, cross1) { - PIMathVectorT vector1; - PIMathVectorT vector2; - double a = 5.0; - double b = 1.72; - double c = 0.0; - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(cmpVectorWithValue(vector1.cross(vector2), c, SIZE)); + PIMathVectorT vector1; + PIMathVectorT vector2; + double a = 5.0; + double b = 1.72; + double c = 0.0; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1.cross(vector2), c, SIZE)); } TEST(PIMathVectorT_Test, cross2) { - PIMathVectorT vector1; - PIMathVectorT vector2; - double a = 1.0; - vector1[0] = a; - vector2[1] = a; - auto crossVec = vector1 * vector2; - ASSERT_DOUBLE_EQ(crossVec[0], 0.0); - ASSERT_DOUBLE_EQ(crossVec[1], 0.0); - ASSERT_DOUBLE_EQ(crossVec[2], a); + PIMathVectorT vector1; + PIMathVectorT vector2; + double a = 1.0; + vector1[0] = a; + vector2[1] = a; + auto crossVec = vector1 * vector2; + ASSERT_DOUBLE_EQ(crossVec[0], 0.0); + ASSERT_DOUBLE_EQ(crossVec[1], 0.0); + ASSERT_DOUBLE_EQ(crossVec[2], a); } TEST(PIMathVectorT_Test, dot) { - double a = 6.0; - double b = 5.0; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - ASSERT_DOUBLE_EQ(vector1.dot(vector2), SIZE * a * b); + double a = 6.0; + double b = 5.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_DOUBLE_EQ(vector1.dot(vector2), SIZE * a * b); } TEST(PIMathVectorT_Test, isNullTrue) { - PIMathVectorT vector; - ASSERT_TRUE(vector.isNull()); + PIMathVectorT vector; + ASSERT_TRUE(vector.isNull()); } TEST(PIMathVectorT_Test, isNullFalse) { - double a = 6.273; - PIMathVectorT vector; - vector[0] = a; - ASSERT_FALSE(vector.isNull()); + double a = 6.273; + PIMathVectorT vector; + vector[0] = a; + ASSERT_FALSE(vector.isNull()); } TEST(PIMathVectorT_Test, isOrthoTrue) { - double a = 2.0; - double b = 1.0; - PIMathVectorT vector; - PIMathVectorT vect; - vector[0] = a; - vect[1] = b; - ASSERT_TRUE(vector.isOrtho(vect)); + double a = 2.0; + double b = 1.0; + PIMathVectorT vector; + PIMathVectorT vect; + vector[0] = a; + vect[1] = b; + ASSERT_TRUE(vector.isOrtho(vect)); } TEST(PIMathVectorT_Test, isOrthoFalse) { - double a = 2.0; - double b = 5.0; - double c = 1.0; - PIMathVectorT vector; - PIMathVectorT vect; - vector[0] = a; - vect[0] = b; - vect[1] = c; - ASSERT_FALSE(vector.isOrtho(vect)); + double a = 2.0; + double b = 5.0; + double c = 1.0; + PIMathVectorT vector; + PIMathVectorT vect; + vector[0] = a; + vect[0] = b; + vect[1] = c; + ASSERT_FALSE(vector.isOrtho(vect)); } TEST(PIMathVectorT_Test, at) { - double a = 5.5; - PIMathVectorT vector; - vector.fill(a); - for(uint i = 0; i < SIZE; i++){ - if(vector.at(i) != a){ - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + double a = 5.5; + PIMathVectorT vector; + vector.fill(a); + for(uint i = 0; i < SIZE; i++){ + if(vector.at(i) != a){ + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathVectorT_Test, operator_AssignmentValue) { - double a = 3.0; - PIMathVectorT vector; - vector = a; - ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); + double a = 3.0; + PIMathVectorT vector; + vector = a; + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVectorT_Test, operator_AssignmentVector) { - double a = 5.0; - PIMathVectorT vector; - PIMathVectorT vec; - vec = a; - vector = vec; - ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); + double a = 5.0; + PIMathVectorT vector; + PIMathVectorT vec; + vec = a; + vector = vec; + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVectorT_Test, operator_EqualTrue) { - double a = 5.12; - double b = 7.34; - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = a; - vector[1] = b; - vec[0] = a; - vec[1] = b; - ASSERT_TRUE(vec == vector); + double a = 5.12; + double b = 7.34; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = b; + ASSERT_TRUE(vec == vector); } TEST(PIMathVectorT_Test, operator_EqualFalse) { - double a = 5.12; - double b = 7.34; - double c = 0.34; - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = a; - vector[1] = b; - vec[0] = a; - vec[1] = c; - ASSERT_FALSE(vec == vector); + double a = 5.12; + double b = 7.34; + double c = 0.34; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = c; + ASSERT_FALSE(vec == vector); } TEST(PIMathVectorT_Test, operator_Not_EqualTrue) { - double a = 5.12; - double b = 7.34; - double c = 0.34; - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = a; - vector[1] = b; - vec[0] = a; - vec[1] = c; - ASSERT_TRUE(vec != vector); + double a = 5.12; + double b = 7.34; + double c = 0.34; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = c; + ASSERT_TRUE(vec != vector); } TEST(PIMathVectorT_Test, operator_Not_EqualFalse) { - double a = 5.12; - double b = 7.34; - PIMathVectorT vector; - PIMathVectorT vec; - vector[0] = a; - vector[1] = b; - vec[0] = a; - vec[1] = b; - ASSERT_FALSE(vec != vector); + double a = 5.12; + double b = 7.34; + PIMathVectorT vector; + PIMathVectorT vec; + vector[0] = a; + vector[1] = b; + vec[0] = a; + vec[1] = b; + ASSERT_FALSE(vec != vector); } -TEST(PIMathVectorT_Test, operator_Addition_Aassignment) { - double a = 6.0; - double b = 1.72; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - vector1 += vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, a + b, SIZE)); +TEST(PIMathVectorT_Test, operator_Addition_Assignment) { + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + vector1 += vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a + b, SIZE)); } TEST(PIMathVectorT_Test, operator_Subtraction_Assignment) { - double a = 6.0; - double b = 1.72; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - vector1 -= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, a - b, SIZE)); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + vector1 -= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a - b, SIZE)); } TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentValue) { - double a = 6.0; - double b = 4.0; - PIMathVectorT vector1; - vector1.fill(a); - vector1 *= b; - ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); + double a = 6.0; + double b = 4.0; + PIMathVectorT vector1; + vector1.fill(a); + vector1 *= b; + ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); } TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentVector) { - double a = 6.0; - double b = 1.72; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - vector1 *= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + vector1 *= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE)); } TEST(PIMathVectorT_Test, operator_Division_AssignmentValue) { - double a = 6.0; - double b = 4.0; - PIMathVectorT vector1; - vector1.fill(a); - vector1 /= b; - ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); + double a = 6.0; + double b = 4.0; + PIMathVectorT vector1; + vector1.fill(a); + vector1 /= b; + ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); } TEST(PIMathVectorT_Test, operator_Division_AssignmentVector) { - double a = 6.0; - double b = 1.5; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - vector1 /= vector2; - ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); + double a = 6.0; + double b = 1.5; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + vector1 /= vector2; + ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE)); } TEST(PIMathVectorT_Test, operator_Addition) { - double a = 6.0; - double b = 1.72; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, a + b, SIZE)); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, a + b, SIZE)); } TEST(PIMathVectorT_Test, operator_Subtraction) { - double a = 6.0; - double b = 1.72; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, a - b, SIZE)); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, a - b, SIZE)); } TEST(PIMathVectorT_Test, operator_MultiplicationValue) { - double a = 6.0; - double b = 4.0; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - ASSERT_TRUE(cmpVectorWithValue(vector1 * b, a * b, SIZE)); + double a = 6.0; + double b = 4.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector1 * b, a * b, SIZE)); } TEST(PIMathVectorT_Test, operator_MultiplicationVector1) { - double a = 6.0; - double b = 1.72; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, SIZE)); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, SIZE)); } TEST(PIMathVectorT_Test, operator_MultiplicationVector2) { - double a = 1.0; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1[0] = a; - vector2[1] = a; - ASSERT_TRUE(((vector1 * vector2)[0] < double(1E-200)) && ((vector1 * vector2)[1] < double(1E-200)) && ((vector1 * vector2)[2] - a < double(1E-200))); + double a = 1.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1[0] = a; + vector2[1] = a; + ASSERT_TRUE(((vector1 * vector2)[0] < double(1E-200)) && ((vector1 * vector2)[1] < double(1E-200)) && ((vector1 * vector2)[2] - a < double(1E-200))); } TEST(PIMathVectorT_Test, operator_DivisionVal) { - double a = 6.0; - double b = 4.0; - PIMathVectorT vector1; - vector1.fill(a); - ASSERT_TRUE(cmpVectorWithValue(vector1 / b, a / b, SIZE)); + double a = 6.0; + double b = 4.0; + PIMathVectorT vector1; + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(vector1 / b, a / b, SIZE)); } TEST(PIMathVectorT_Test, operator_DivisionVector) { - double a = 6.0; - double b = 4.0; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(cmpVectorWithValue(vector1 / vector2, a / b, SIZE)); + double a = 6.0; + double b = 4.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 / vector2, a / b, SIZE)); } TEST(PIMathVectorT_Test, operator_MultiplVect) { - double a = 6.0; - double b = 5.0; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, a * b, SIZE)); + double a = 6.0; + double b = 5.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, a * b, SIZE)); } TEST(PIMathVectorT_Test, operator_absDotProduct) { - double a = 6.0; - double b = 5.0; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - ASSERT_DOUBLE_EQ(vector1 ^ vector2, SIZE * a * b); + double a = 6.0; + double b = 5.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_DOUBLE_EQ(vector1 ^ vector2, SIZE * a * b); } TEST(PIMathVectorT_Test, transposed) { - double a = 6.0; - PIMathVectorT vector; - vector.fill(a); - auto matrix = vector.transposed(); - for(int i = 0; i < SIZE; i++){ - if(matrix[0][i] != a) - { - ASSERT_TRUE(false); - } - } - ASSERT_TRUE(true); + double a = 6.0; + PIMathVectorT vector; + vector.fill(a); + auto matrix = vector.transposed(); + for(int i = 0; i < SIZE; i++){ + if(matrix[0][i] != a) + { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); } TEST(PIMathVectorT_Test, filled) { - double a = 6.0; - auto vector = PIMathVectorT::filled(a); - ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); + double a = 6.0; + auto vector = PIMathVectorT::filled(a); + ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); } TEST(PIMathVectorT_Test, turnTo) { - double a = 6.0; - PIMathVectorT vect; - vect.fill(a); - auto vector = vect.turnTo<2u, double>(); - ASSERT_TRUE(vector.size() == 2); + double a = 6.0; + PIMathVectorT vect; + vect.fill(a); + auto vector = vect.turnTo<2u, double>(); + ASSERT_TRUE(vector.size() == 2); } TEST(PIMathVectorT_Test, LogicalOrTrue) { - double a = 6.0; - double b = 1.72; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1.fill(a); - vector2.fill(b); - ASSERT_TRUE(vector1 || vector2); + double a = 6.0; + double b = 1.72; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1.fill(a); + vector2.fill(b); + ASSERT_TRUE(vector1 || vector2); } TEST(PIMathVectorT_Test, LogicalOrFalse) { - double a = 1.0; - PIMathVectorT vector1; - PIMathVectorT vector2; - vector1[0] = a; - vector2[1] = a; - ASSERT_FALSE(vector1 || vector2); + double a = 1.0; + PIMathVectorT vector1; + PIMathVectorT vector2; + vector1[0] = a; + vector2[1] = a; + ASSERT_FALSE(vector1 || vector2); } TEST(PIMathVectorT_Test, sqrt) { - double a = 36.0; - PIMathVectorT vector1; - vector1.fill(a); - ASSERT_TRUE(cmpVectorWithValue(sqrt(vector1), sqrt(a), SIZE)); + double a = 36.0; + PIMathVectorT vector1; + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(sqrt(vector1), sqrt(a), SIZE)); } TEST(PIMathVectorT_Test, sqr) { - double a = 6.0; - PIMathVectorT vector1; - vector1.fill(a); - ASSERT_TRUE(cmpVectorWithValue(sqr(vector1), sqr(a), SIZE)); + double a = 6.0; + PIMathVectorT vector1; + vector1.fill(a); + ASSERT_TRUE(cmpVectorWithValue(sqr(vector1), sqr(a), SIZE)); } -- 2.43.0 From 9b02325ba1bee410c91dfa27c475f52d0c4751b1 Mon Sep 17 00:00:00 2001 From: maakshishov Date: Thu, 8 Oct 2020 11:16:05 +0300 Subject: [PATCH 14/14] PIMathVector Tests bug fix --- tests/math/testpimathmatrixt.cpp | 4 ++-- tests/math/testpimathvector.cpp | 9 ++++----- tests/math/testpimathvectort.cpp | 7 ++++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 59cd14c9..97b37737 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -18,8 +18,8 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT matrix, double v TEST(PIMathMatrixT_Test, identity) { auto matrix = PIMathMatrixT::identity(); - for(int i = 0; i < 3; i++){ - for(int j = 0; j < 3; j++){ + for(int i = 0; i < rows; i++){ + for(int j = 0; j < cols; j++){ if(i != j){ if(matrix[i][j] != 0.0){ ASSERT_TRUE(false); diff --git a/tests/math/testpimathvector.cpp b/tests/math/testpimathvector.cpp index 9ac59f1a..2320aa19 100644 --- a/tests/math/testpimathvector.cpp +++ b/tests/math/testpimathvector.cpp @@ -16,7 +16,7 @@ bool cmpVectorWithValue(PIMathVector vector, double val, int num) { TEST(PIMathVector_Test, size) { auto vector = PIMathVector(SIZE); - ASSERT_TRUE(vector.size() == SIZE); + ASSERT_EQ(vector.size(), SIZE); } TEST(PIMathVector_Test, resize) { @@ -24,8 +24,8 @@ TEST(PIMathVector_Test, resize) { double a = 5.0; PIMathVector vector; vector.resize(newSize, a); + ASSERT_EQ(vector.size(), newSize); ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size())); - ASSERT_TRUE(vector.size() == newSize); } TEST(PIMathVector_Test, resized) { @@ -33,8 +33,8 @@ TEST(PIMathVector_Test, resized) { double a = 5.0; PIMathVector vector; auto vect = vector.resized(newSize, a); + ASSERT_EQ(vect.size(), newSize); ASSERT_TRUE(cmpVectorWithValue(vect, a, vect.size())); - ASSERT_TRUE(vect.size() == newSize); } TEST(PIMathVector_Test, fill) { @@ -73,7 +73,7 @@ TEST(PIMathVector_Test, moveVecSizeNotEq) { vec.fill(b); vector.move(vec); ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE)); - ASSERT_TRUE(vector.size() == SIZE); + ASSERT_EQ(vector.size(), SIZE); } TEST(PIMathVector_Test, swap) { @@ -304,7 +304,6 @@ TEST(PIMathVector_Test, at) { ASSERT_TRUE(false); } } - ASSERT_TRUE(true); } TEST(PIMathVector_Test, operator_AssignmentValue) { diff --git a/tests/math/testpimathvectort.cpp b/tests/math/testpimathvectort.cpp index f29a7527..37d78c9e 100644 --- a/tests/math/testpimathvectort.cpp +++ b/tests/math/testpimathvectort.cpp @@ -230,7 +230,6 @@ TEST(PIMathVectorT_Test, at) { ASSERT_TRUE(false); } } - ASSERT_TRUE(true); } TEST(PIMathVectorT_Test, operator_AssignmentValue) { @@ -406,7 +405,10 @@ TEST(PIMathVectorT_Test, operator_MultiplicationVector2) { PIMathVectorT vector2; vector1[0] = a; vector2[1] = a; - ASSERT_TRUE(((vector1 * vector2)[0] < double(1E-200)) && ((vector1 * vector2)[1] < double(1E-200)) && ((vector1 * vector2)[2] - a < double(1E-200))); + auto vect = vector1 * vector2; + ASSERT_TRUE(vect[0] < double(1E-200)); + ASSERT_TRUE(vect[1] < double(1E-200)); + ASSERT_TRUE(vect[2] - a < double(1E-200)); } TEST(PIMathVectorT_Test, operator_DivisionVal) { @@ -458,7 +460,6 @@ TEST(PIMathVectorT_Test, transposed) { ASSERT_TRUE(false); } } - ASSERT_TRUE(true); } TEST(PIMathVectorT_Test, filled) { -- 2.43.0