From 26dff328a3da1b6ec88c3a215120c6118ac22cdd Mon Sep 17 00:00:00 2001 From: Oleg Date: Tue, 2 Nov 2021 23:32:40 +0300 Subject: [PATCH 1/5] stack + gtest_stack --- include/stack.h | 75 +++++++++++++++++++++++++- sln/vc12/arithmetic/arithmetic.vcxproj | 4 +- sln/vc12/gtest/gtest.vcxproj | 4 +- sln/vc12/sample/sample.vcxproj | 4 +- sln/vc12/tests/tests.vcxproj | 4 +- test/test_stack.cpp | 43 ++++++++++++++- 6 files changed, 124 insertions(+), 10 deletions(-) diff --git a/include/stack.h b/include/stack.h index 0af9f3f..8f4b7ba 100644 --- a/include/stack.h +++ b/include/stack.h @@ -6,4 +6,77 @@ // - проверка на пустоту, // - получение количества элементов в стеке // - очистка стека -// при вставке в полный стек должна перевыделяться память \ No newline at end of file +// при вставке в полный стек должна перевыделяться память + +constexpr int memsize = 25; + +template +class Stack +{ +private: + T* pMem; + int MemSize; + int Hi; + //virtual int GetNextIndex(int index); +public: + Stack(int size = memsize) + { + if (size <= 0) + throw std::exception("Size must be greater than null!"); + pMem = new T[size]; + MemSize = size; + Hi = -1; + } + + ~Stack() + { + delete[] pMem; + } + + void Put(const T& val) + { + if (IsFull()) + { + T* tmp = new T[++MemSize]; + for (size_t i = 0; i < MemSize; i++) + tmp[i] = pMem[i]; + delete[] pMem; + pMem = tmp; + } + pMem[++Hi] = val; + } + + T Get() + { + if (IsEmpty()) + throw std::exception("Stack is empty!"); + return pMem[Hi--]; + } + + T View() const + { + if (IsEmpty()) + throw std::exception("Stack is empty!"); + return pMem[Hi]; + } + + int IsEmpty() const + { + return Hi == -1; + } + + int IsFull() const + { + return (Hi == (MemSize - 1)); + } + + int GetDataCount() const + { + return Hi + 1; + } + + void Clear() + { + Hi = -1; + } +}; \ No newline at end of file diff --git a/sln/vc12/arithmetic/arithmetic.vcxproj b/sln/vc12/arithmetic/arithmetic.vcxproj index c48cffd..eeaaff2 100644 --- a/sln/vc12/arithmetic/arithmetic.vcxproj +++ b/sln/vc12/arithmetic/arithmetic.vcxproj @@ -20,12 +20,12 @@ StaticLibrary Unicode true - v110 + v142 StaticLibrary Unicode - v110 + v142 diff --git a/sln/vc12/gtest/gtest.vcxproj b/sln/vc12/gtest/gtest.vcxproj index 29ae51b..20d0706 100644 --- a/sln/vc12/gtest/gtest.vcxproj +++ b/sln/vc12/gtest/gtest.vcxproj @@ -20,12 +20,12 @@ StaticLibrary Unicode true - v110 + v142 StaticLibrary Unicode - v110 + v142 diff --git a/sln/vc12/sample/sample.vcxproj b/sln/vc12/sample/sample.vcxproj index e141fae..64c7134 100644 --- a/sln/vc12/sample/sample.vcxproj +++ b/sln/vc12/sample/sample.vcxproj @@ -20,12 +20,12 @@ Application Unicode true - v110 + v142 Application Unicode - v110 + v142 diff --git a/sln/vc12/tests/tests.vcxproj b/sln/vc12/tests/tests.vcxproj index dc65eeb..91e3c88 100644 --- a/sln/vc12/tests/tests.vcxproj +++ b/sln/vc12/tests/tests.vcxproj @@ -20,12 +20,12 @@ Application Unicode true - v110 + v142 Application Unicode - v110 + v142 diff --git a/test/test_stack.cpp b/test/test_stack.cpp index d99d62a..60d0d16 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -1,4 +1,45 @@ // тесты для стека #include "stack.h" -#include \ No newline at end of file +#include + +TEST(Stack, can_create_stack_with_pisitive_lenght) +{ + ASSERT_NO_THROW(Stack T(5)); +} + +TEST(Stack, throws_when_create_stack_with_negative_length) +{ + ASSERT_ANY_THROW(Stack T(-5)); +} + +TEST(Stack, new_stack_is_empty) +{ + Stack T(5); + EXPECT_TRUE(T.IsEmpty()); +} + +TEST(Stack, can_put_and_view) +{ + Stack T(5); + T.Put(1); + EXPECT_EQ(1, T.View()); +} + +TEST(Stack, get_delete_element) +{ + Stack T(5); + T.Put(1); + int tmp = T.Get(); + EXPECT_TRUE(T.IsEmpty()); +} + +TEST(Stack, can_clear) +{ + Stack T(5); + T.Put(1); + T.Put(2); + T.Put(3); + T.Clear(); + EXPECT_TRUE(T.IsEmpty()); +} \ No newline at end of file From 11ddd3df89f4c0350986aeea0ca7612a009d6aef Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 11 Nov 2021 00:19:11 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=84=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D0=B2=D1=8B=D1=80?= =?UTF-8?q?=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/arithmetic.h | 55 ++++- samples/main_arithmetic.cpp | 6 + sln/vc12/arithmetic/arithmetic.vcxproj | 4 +- sln/vc12/gtest/gtest.vcxproj | 4 +- sln/vc12/sample/sample.vcxproj | 4 +- sln/vc12/tests/tests.vcxproj | 4 +- src/arithmetic.cpp | 276 ++++++++++++++++++++++++- 7 files changed, 343 insertions(+), 10 deletions(-) diff --git a/include/arithmetic.h b/include/arithmetic.h index 96a234e..021c5a9 100644 --- a/include/arithmetic.h +++ b/include/arithmetic.h @@ -1 +1,54 @@ -// объявление функций и классов для вычисления арифметических выражений \ No newline at end of file +// объявление функций и классов для вычисления арифметических выражений +#include "stack.h" +#include +#include +#include + +using namespace std; + +struct lexema +{ + string val; + int type; + double x; + lexema() + { + x = 0.0; + val = "\0"; + type = -100; + } + lexema(string s, int t = -100) + { + val = s; + type = t; + } + lexema(char s, int t = -100) + { + val = s; + type = t; + } +}; + +class Arithmetic +{ + string input; + double result; + vector inp_lex; + vector pol_lex; + int status; + + void enter(); + void split(); + int check_bkt(); + vector check_symbols(); + bool isCorrect(); + void converter(); + void set_values(); + void calculate(); + +public: + void launch(); + Arithmetic(string str = ""); + + +}; \ No newline at end of file diff --git a/samples/main_arithmetic.cpp b/samples/main_arithmetic.cpp index 6c875a5..fa50815 100644 --- a/samples/main_arithmetic.cpp +++ b/samples/main_arithmetic.cpp @@ -1,6 +1,12 @@ // реализация пользовательского приложения +#include "arithmetic.h" + int main() { + Arithmetic A; + A.launch(); + + return 0; } diff --git a/sln/vc12/arithmetic/arithmetic.vcxproj b/sln/vc12/arithmetic/arithmetic.vcxproj index eeaaff2..8ff3bee 100644 --- a/sln/vc12/arithmetic/arithmetic.vcxproj +++ b/sln/vc12/arithmetic/arithmetic.vcxproj @@ -20,12 +20,12 @@ StaticLibrary Unicode true - v142 + v143 StaticLibrary Unicode - v142 + v143 diff --git a/sln/vc12/gtest/gtest.vcxproj b/sln/vc12/gtest/gtest.vcxproj index 20d0706..d0cd8bc 100644 --- a/sln/vc12/gtest/gtest.vcxproj +++ b/sln/vc12/gtest/gtest.vcxproj @@ -20,12 +20,12 @@ StaticLibrary Unicode true - v142 + v143 StaticLibrary Unicode - v142 + v143 diff --git a/sln/vc12/sample/sample.vcxproj b/sln/vc12/sample/sample.vcxproj index 64c7134..2fff0e0 100644 --- a/sln/vc12/sample/sample.vcxproj +++ b/sln/vc12/sample/sample.vcxproj @@ -20,12 +20,12 @@ Application Unicode true - v142 + v143 Application Unicode - v142 + v143 diff --git a/sln/vc12/tests/tests.vcxproj b/sln/vc12/tests/tests.vcxproj index 91e3c88..7eab231 100644 --- a/sln/vc12/tests/tests.vcxproj +++ b/sln/vc12/tests/tests.vcxproj @@ -20,12 +20,12 @@ Application Unicode true - v142 + v143 Application Unicode - v142 + v143 diff --git a/src/arithmetic.cpp b/src/arithmetic.cpp index 7d04897..e4d65ec 100644 --- a/src/arithmetic.cpp +++ b/src/arithmetic.cpp @@ -1 +1,275 @@ -// реализация функций и классов для вычисления арифметических выражений \ No newline at end of file +#include "..\include\arithmetic.h" + +// реализация функций и классов для вычисления арифметических выражений + +Arithmetic::Arithmetic(string str) +{ + input = str; + if (str.empty()) + status = -1; + else + status = 0; +} + +void Arithmetic::enter() +{ + do + { + cout << "Enter arithmetic expression:" << endl; + getline(cin, input); + } while (input.empty()); + status = 0; +} + +void Arithmetic::split() +{ + for (size_t i = 0; i < input.length(); i++) + { + string abc = "abcdefghijklmnopqrstuvwxyz"; + string num = ".,0123456789"; + size_t p_abc = abc.find(input[i]); + size_t p_num = num.find(input[i]); + + lexema tmp(input[i]); + + if (input[i] != ' ') + { + if (input[i] == '(' || input[i] == '[' || input[i] == '{') + tmp.type = 0; + else if (input[i] == ')' || input[i] == ']' || input[i] == '}') + tmp.type = -1; + else if (input[i] == '+' || input[i] == '-') + tmp.type = 1; + else if (input[i] == '*' || input[i] == '/') + tmp.type = 2; + else if (input[i] == '^') + tmp.type = 3; + else if (p_abc != abc.npos) + { + if (input[i] == 's' && i < input.length() - 5) + { + if (input[i + 1] == 'i' && input[i + 2] == 'n' && input[i + 3] == '(') + { + tmp.type = 4; + tmp.val = "sin"; + i = i + 2; + } + } + else if (input[i] == 'c' && i < input.length() - 5) + { + if (input[i + 1] == 'o' && input[i + 2] == 's' && input[i + 3] == '(') + { + tmp.type = 4; + tmp.val = "cos"; + i = i + 2; + } + } + else if (input[i] == 'e' && i < input.length() - 5) + { + if (input[i + 1] == 'x' && input[i + 2] == 'p' && input[i + 3] == '(') + { + tmp.type = 4; + tmp.val = "exp"; + i = i + 2; + } + } + else + { + tmp.type = -2; + for (size_t j = i + 1; j < input.length(); j++) + { + p_abc = abc.find(input[j]); + if (p_abc != abc.npos) + { + tmp.val.push_back(input[j]); + i++; + } + else + j = input.length(); + } + } + + } + else if (p_num != num.npos) + { + tmp.type = -3; + for (size_t j = i + 1; j < input.length(); j++) + { + p_num = num.find(input[j]); + if (p_num != num.npos) + { + tmp.val.push_back(input[j]); + i++; + } + else + j = input.length(); + } + } + inp_lex.push_back(tmp); + } + } + + status = 1; +} + +int Arithmetic::check_bkt() +{ + int k = 0; + for (size_t i = 0; i < inp_lex.size(); i++) + { + if (inp_lex[i].type == 0) + k++; + if (inp_lex[i].type == -1) + k--; + } + return k; +} + +vector Arithmetic::check_symbols() +{ + vector err; + + for (size_t i = 0; i < inp_lex.size(); i++) + { + if (inp_lex[i].type == -100) + err.push_back(i); + } + + return err; +} + +bool Arithmetic::isCorrect() +{ + bool F = true; + int tmp = check_bkt(); + if (tmp > 0) + { + F = false; + cout << "Input error: missing " << tmp << "closing brackets!"; + } + else if (tmp < 0) + { + F = false; + cout << "Input error: missing " << -tmp << "opening brackets!"; + } + + vector err = check_symbols(); + if (!err.empty()) + { + F = false; + cout << "Input error: prohibited symbols in "; + cout << err[0]; + for (size_t i = 1; i < err.size(); i++) + cout << ", " << err[i]; + cout << " places!"; + } + + if (!F) + status = -1; + return F; +} + +void Arithmetic::converter() +{ + Stack T; + for (size_t i = 0; i < inp_lex.size(); i++) + { + if (inp_lex[i].type < -1) + pol_lex.push_back(inp_lex[i]); + else if (inp_lex[i].type == -1) + { + while (T.View().type != 0) + pol_lex.push_back(T.Get()); + + T.Get(); + } + else if (inp_lex[i].type == 0) + { + T.Put(inp_lex[i]); + } + else + { + while (!T.IsEmpty() && T.View().type >= inp_lex[i].type) + pol_lex.push_back(T.Get()); + + T.Put(inp_lex[i]); + } + } + while (!T.IsEmpty()) + { + pol_lex.push_back(T.Get()); + } + + status = 2; +} + +void Arithmetic::set_values() +{ + for (size_t i = 0; i < pol_lex.size(); i++) + { + if (pol_lex[i].type == -3) + pol_lex[i].x = stod(pol_lex[i].val); + + if (pol_lex[i].type == -2) + { + cout << "Enter the value of the variable '" << pol_lex[i].val << "': "; + cin >> pol_lex[i].x; + } + } + + status = 3; +} + +void Arithmetic::calculate() +{ + Stack T; + for (size_t i = 0; i < pol_lex.size(); i++) + { + if (pol_lex[i].type < -1) + T.Put(pol_lex[i].x); + else + { + double x = T.Get(); + if (pol_lex[i].val == "sin") + T.Put(sin(x)); + else if (pol_lex[i].val == "cos") + T.Put(cos(x)); + else if (pol_lex[i].val == "exp") + T.Put(exp(x)); + else + { + double y = T.Get(); + if (pol_lex[i].val == "+") + T.Put(x + y); + else if (pol_lex[i].val == "-") + T.Put(y - x); + else if (pol_lex[i].val == "*") + T.Put(x * y); + else if (pol_lex[i].val == "/") + T.Put(y / x); + else if (pol_lex[i].val == "^") + T.Put(pow(y, x)); + } + } + } + + result = T.Get(); + status = 4; +} + +void Arithmetic::launch() +{ + if (status == -1) + enter(); + if (status == 0) + split(); + if (status == 1 && isCorrect()) + converter(); + if (status == 2) + set_values(); + if (status == 3) + calculate(); + if (status == 4) + cout << "RESULT: " << result << endl; +} + From b021d8996353f00f4746560b4b9b16564eb59937 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 12 Nov 2021 01:42:15 +0300 Subject: [PATCH 3/5] =?UTF-8?q?+=D0=BD=D0=B0=D1=82=D1=83=D1=80=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BB=D0=BE=D0=B3=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D1=84=D0=BC=20+=D1=83=D0=BD=D0=B0=D1=80=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BC=D0=B8=D0=BD=D1=83=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/arithmetic.h | 2 - include/stack.h | 8 +- src/arithmetic.cpp | 279 +++++++++++++++++++++++-------------------- 3 files changed, 154 insertions(+), 135 deletions(-) diff --git a/include/arithmetic.h b/include/arithmetic.h index 021c5a9..0926d93 100644 --- a/include/arithmetic.h +++ b/include/arithmetic.h @@ -49,6 +49,4 @@ class Arithmetic public: void launch(); Arithmetic(string str = ""); - - }; \ No newline at end of file diff --git a/include/stack.h b/include/stack.h index 8f4b7ba..1f00769 100644 --- a/include/stack.h +++ b/include/stack.h @@ -1,9 +1,9 @@ // объявление и реализация шаблонного стека -// стек поддерживает операции: -// - вставка элемента, -// - извлечение элемента, +// стек поддерживает операции: +// - вставка элемента, +// - извлечение элемента, // - просмотр верхнего элемента (без удаления) -// - проверка на пустоту, +// - проверка на пустоту, // - получение количества элементов в стеке // - очистка стека // при вставке в полный стек должна перевыделяться память diff --git a/src/arithmetic.cpp b/src/arithmetic.cpp index e4d65ec..2d02bbb 100644 --- a/src/arithmetic.cpp +++ b/src/arithmetic.cpp @@ -23,80 +23,82 @@ void Arithmetic::enter() void Arithmetic::split() { - for (size_t i = 0; i < input.length(); i++) - { - string abc = "abcdefghijklmnopqrstuvwxyz"; - string num = ".,0123456789"; - size_t p_abc = abc.find(input[i]); - size_t p_num = num.find(input[i]); + for (size_t i = 0; i < input.length(); i++) + { + string abc = "abcdefghijklmnopqrstuvwxyz"; + string num = ".,0123456789"; + size_t p_abc = abc.find(input[i]); + size_t p_num = num.find(input[i]); - lexema tmp(input[i]); + lexema tmp(input[i]); - if (input[i] != ' ') + if (input[i] != ' ') + { + if (input[i] == '(' || input[i] == '[' || input[i] == '{') + tmp.type = 0; + else if (input[i] == ')' || input[i] == ']' || input[i] == '}') + tmp.type = -1; + else if (input[i] == '+') + tmp.type = 1; + else if (input[i] == '*' || input[i] == '/') + tmp.type = 2; + else if (input[i] == '^') + tmp.type = 3; + else if (input[i] == '-') { - if (input[i] == '(' || input[i] == '[' || input[i] == '{') - tmp.type = 0; - else if (input[i] == ')' || input[i] == ']' || input[i] == '}') - tmp.type = -1; - else if (input[i] == '+' || input[i] == '-') + if (inp_lex.empty() || (inp_lex.back().type > -1 && inp_lex.back().type < 4)) + { + tmp.val = "--"; + tmp.type = 4; + } + else tmp.type = 1; - else if (input[i] == '*' || input[i] == '/') - tmp.type = 2; - else if (input[i] == '^') - tmp.type = 3; - else if (p_abc != abc.npos) + } + else if (p_abc != abc.npos) + { + if (input[i] == 's' && i < input.length() - 5) { - if (input[i] == 's' && i < input.length() - 5) + if (input[i + 1] == 'i' && input[i + 2] == 'n' && input[i + 3] == '(') { - if (input[i + 1] == 'i' && input[i + 2] == 'n' && input[i + 3] == '(') - { - tmp.type = 4; - tmp.val = "sin"; - i = i + 2; - } + tmp.type = 5; + tmp.val = "sin"; + i = i + 2; } - else if (input[i] == 'c' && i < input.length() - 5) + } + else if (input[i] == 'c' && i < input.length() - 5) + { + if (input[i + 1] == 'o' && input[i + 2] == 's' && input[i + 3] == '(') { - if (input[i + 1] == 'o' && input[i + 2] == 's' && input[i + 3] == '(') - { - tmp.type = 4; - tmp.val = "cos"; - i = i + 2; - } + tmp.type = 5; + tmp.val = "cos"; + i = i + 2; } - else if (input[i] == 'e' && i < input.length() - 5) + } + else if (input[i] == 'e' && i < input.length() - 5) + { + if (input[i + 1] == 'x' && input[i + 2] == 'p' && input[i + 3] == '(') { - if (input[i + 1] == 'x' && input[i + 2] == 'p' && input[i + 3] == '(') - { - tmp.type = 4; - tmp.val = "exp"; - i = i + 2; - } + tmp.type = 5; + tmp.val = "exp"; + i = i + 2; } - else + } + else if (input[i] == 'l' && i < input.length() - 4) + { + if (input[i + 1] == 'n' && input[i + 2] == '(') { - tmp.type = -2; - for (size_t j = i + 1; j < input.length(); j++) - { - p_abc = abc.find(input[j]); - if (p_abc != abc.npos) - { - tmp.val.push_back(input[j]); - i++; - } - else - j = input.length(); - } + tmp.type = 5; + tmp.val = "ln"; + i = i + 1; } - } - else if (p_num != num.npos) + else { - tmp.type = -3; + tmp.type = -2; for (size_t j = i + 1; j < input.length(); j++) { - p_num = num.find(input[j]); - if (p_num != num.npos) + p_abc = abc.find(input[j]); + if (p_abc != abc.npos) { tmp.val.push_back(input[j]); i++; @@ -105,11 +107,27 @@ void Arithmetic::split() j = input.length(); } } - inp_lex.push_back(tmp); } + else if (p_num != num.npos) + { + tmp.type = -3; + for (size_t j = i + 1; j < input.length(); j++) + { + p_num = num.find(input[j]); + if (p_num != num.npos) + { + tmp.val.push_back(input[j]); + i++; + } + else + j = input.length(); + } + } + inp_lex.push_back(tmp); } + } - status = 1; + status = 1; } int Arithmetic::check_bkt() @@ -132,7 +150,7 @@ vector Arithmetic::check_symbols() for (size_t i = 0; i < inp_lex.size(); i++) { if (inp_lex[i].type == -100) - err.push_back(i); + err.push_back(i + 1); } return err; @@ -145,12 +163,12 @@ bool Arithmetic::isCorrect() if (tmp > 0) { F = false; - cout << "Input error: missing " << tmp << "closing brackets!"; + cout << "Input error: missing " << tmp << "closing brackets!\n"; } else if (tmp < 0) { F = false; - cout << "Input error: missing " << -tmp << "opening brackets!"; + cout << "Input error: missing " << -tmp << "opening brackets!\n"; } vector err = check_symbols(); @@ -158,12 +176,12 @@ bool Arithmetic::isCorrect() { F = false; cout << "Input error: prohibited symbols in "; - cout << err[0]; + cout << err[0] << "th"; for (size_t i = 1; i < err.size(); i++) - cout << ", " << err[i]; - cout << " places!"; + cout << ", " << err[i] << "th"; + cout << " places!\n"; } - + if (!F) status = -1; return F; @@ -171,90 +189,94 @@ bool Arithmetic::isCorrect() void Arithmetic::converter() { - Stack T; - for (size_t i = 0; i < inp_lex.size(); i++) + Stack T; + for (size_t i = 0; i < inp_lex.size(); i++) + { + if (inp_lex[i].type < -1) + pol_lex.push_back(inp_lex[i]); + else if (inp_lex[i].type == -1) { - if (inp_lex[i].type < -1) - pol_lex.push_back(inp_lex[i]); - else if (inp_lex[i].type == -1) - { - while (T.View().type != 0) - pol_lex.push_back(T.Get()); - - T.Get(); - } - else if (inp_lex[i].type == 0) - { - T.Put(inp_lex[i]); - } - else - { - while (!T.IsEmpty() && T.View().type >= inp_lex[i].type) - pol_lex.push_back(T.Get()); + while (T.View().type != 0) + pol_lex.push_back(T.Get()); - T.Put(inp_lex[i]); - } + T.Get(); } - while (!T.IsEmpty()) + else if (inp_lex[i].type == 0) { - pol_lex.push_back(T.Get()); + T.Put(inp_lex[i]); } + else + { + while (!T.IsEmpty() && T.View().type >= inp_lex[i].type) + pol_lex.push_back(T.Get()); - status = 2; + T.Put(inp_lex[i]); + } + } + while (!T.IsEmpty()) + { + pol_lex.push_back(T.Get()); + } + + status = 2; } void Arithmetic::set_values() { - for (size_t i = 0; i < pol_lex.size(); i++) - { - if (pol_lex[i].type == -3) - pol_lex[i].x = stod(pol_lex[i].val); + for (size_t i = 0; i < pol_lex.size(); i++) + { + if (pol_lex[i].type == -3) + pol_lex[i].x = stod(pol_lex[i].val); - if (pol_lex[i].type == -2) - { - cout << "Enter the value of the variable '" << pol_lex[i].val << "': "; - cin >> pol_lex[i].x; - } + if (pol_lex[i].type == -2) + { + cout << "Enter the value of the variable '" << pol_lex[i].val << "': "; + cin >> pol_lex[i].x; } + } - status = 3; + status = 3; } void Arithmetic::calculate() { - Stack T; - for (size_t i = 0; i < pol_lex.size(); i++) + Stack T; + for (size_t i = 0; i < pol_lex.size(); i++) + { + if (pol_lex[i].type < -1) + T.Put(pol_lex[i].x); + else { - if (pol_lex[i].type < -1) - T.Put(pol_lex[i].x); + double x = T.Get(); + if (pol_lex[i].val == "sin") + T.Put(sin(x)); + else if (pol_lex[i].val == "cos") + T.Put(cos(x)); + else if (pol_lex[i].val == "exp") + T.Put(exp(x)); + else if (pol_lex[i].val == "ln") + T.Put(log(x)); + else if (pol_lex[i].val == "--") + T.Put(-x); else { - double x = T.Get(); - if (pol_lex[i].val == "sin") - T.Put(sin(x)); - else if (pol_lex[i].val == "cos") - T.Put(cos(x)); - else if (pol_lex[i].val == "exp") - T.Put(exp(x)); - else - { - double y = T.Get(); - if (pol_lex[i].val == "+") - T.Put(x + y); - else if (pol_lex[i].val == "-") - T.Put(y - x); - else if (pol_lex[i].val == "*") - T.Put(x * y); - else if (pol_lex[i].val == "/") - T.Put(y / x); - else if (pol_lex[i].val == "^") - T.Put(pow(y, x)); - } + double y = T.Get(); + if (pol_lex[i].val == "+") + T.Put(x + y); + else if (pol_lex[i].val == "-") + T.Put(y - x); + else if (pol_lex[i].val == "*") + T.Put(x * y); + else if (pol_lex[i].val == "/") + T.Put(y / x); + else if (pol_lex[i].val == "^") + T.Put(pow(y, x)); } } + } - result = T.Get(); - status = 4; + result = T.Get(); + status = 4; } void Arithmetic::launch() @@ -271,5 +293,4 @@ void Arithmetic::launch() calculate(); if (status == 4) cout << "RESULT: " << result << endl; -} - +} \ No newline at end of file From ede7bcabfa137dc3d1f73713f4201f55393b0d53 Mon Sep 17 00:00:00 2001 From: Oleg Date: Sat, 13 Nov 2021 17:16:58 +0300 Subject: [PATCH 4/5] =?UTF-8?q?+=D0=B3=D1=83=D0=B3=D0=BB=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8B=20+=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=82=D0=BE=D1=87=D0=B5=D0=BA=20=D0=B2=20=D1=87?= =?UTF-8?q?=D0=B8=D1=81=D0=BB=D0=B0=D1=85=20+=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B0=20=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B9=20+=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B0=20=D1=81=D0=BA=D0=BE=D0=B1=D0=BE=D0=BA?= =?UTF-8?q?=20+=D0=BC=D0=BD=D0=BE=D0=B6=D0=B5=D1=81=D1=82=D0=B2=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/arithmetic.h | 16 +++- include/stack.h | 7 +- samples/main_arithmetic.cpp | 6 +- src/arithmetic.cpp | 147 ++++++++++++++++++++++++++---------- test/test_arithmetic.cpp | 123 +++++++++++++++++++++++++++++- test/test_stack.cpp | 2 +- 6 files changed, 247 insertions(+), 54 deletions(-) diff --git a/include/arithmetic.h b/include/arithmetic.h index 0926d93..00ba406 100644 --- a/include/arithmetic.h +++ b/include/arithmetic.h @@ -19,14 +19,20 @@ struct lexema } lexema(string s, int t = -100) { + x = 0.0; val = s; type = t; } lexema(char s, int t = -100) { + x = 0.0; val = s; type = t; } + int operator==(const lexema& l) + { + return ((val == l.val) && (type == l.type)); + } }; class Arithmetic @@ -37,16 +43,20 @@ class Arithmetic vector pol_lex; int status; +public: void enter(); void split(); - int check_bkt(); + bool check_bkt(); vector check_symbols(); + bool check_points(); + bool check_operations(); bool isCorrect(); void converter(); void set_values(); void calculate(); - -public: void launch(); Arithmetic(string str = ""); + vector get_input_lex(); + vector get_polish_lex(); + double get_result(); }; \ No newline at end of file diff --git a/include/stack.h b/include/stack.h index 1f00769..87ca564 100644 --- a/include/stack.h +++ b/include/stack.h @@ -35,7 +35,7 @@ class Stack void Put(const T& val) { - if (IsFull()) + if (Hi == (MemSize - 1)) { T* tmp = new T[++MemSize]; for (size_t i = 0; i < MemSize; i++) @@ -65,11 +65,6 @@ class Stack return Hi == -1; } - int IsFull() const - { - return (Hi == (MemSize - 1)); - } - int GetDataCount() const { return Hi + 1; diff --git a/samples/main_arithmetic.cpp b/samples/main_arithmetic.cpp index fa50815..2e2f756 100644 --- a/samples/main_arithmetic.cpp +++ b/samples/main_arithmetic.cpp @@ -1,12 +1,10 @@ // реализация пользовательского приложения #include "arithmetic.h" - int main() { Arithmetic A; A.launch(); - - return 0; -} + return 0; +} \ No newline at end of file diff --git a/src/arithmetic.cpp b/src/arithmetic.cpp index 2d02bbb..6e359c2 100644 --- a/src/arithmetic.cpp +++ b/src/arithmetic.cpp @@ -11,6 +11,30 @@ Arithmetic::Arithmetic(string str) status = 0; } +vector Arithmetic::get_input_lex() +{ + if (status == 1) + return inp_lex; + else + throw exception("not split"); +} + +vector Arithmetic::get_polish_lex() +{ + if (status == 2) + return pol_lex; + else + throw exception("not converted"); +} + +double Arithmetic::get_result() +{ + if (status == 4) + return result; + else + throw exception("not calculated"); +} + void Arithmetic::enter() { do @@ -46,7 +70,7 @@ void Arithmetic::split() tmp.type = 3; else if (input[i] == '-') { - if (inp_lex.empty() || (inp_lex.back().type > -1 && inp_lex.back().type < 4)) + if (inp_lex.empty() || (inp_lex.back().type > -1 && inp_lex.back().type < 5)) { tmp.val = "--"; tmp.type = 4; @@ -56,41 +80,29 @@ void Arithmetic::split() } else if (p_abc != abc.npos) { - if (input[i] == 's' && i < input.length() - 5) + if (input[i] == 's' && input[i + 1] == 'i' && input[i + 2] == 'n' && input[i + 3] == '(') { - if (input[i + 1] == 'i' && input[i + 2] == 'n' && input[i + 3] == '(') - { - tmp.type = 5; - tmp.val = "sin"; - i = i + 2; - } + tmp.type = 5; + tmp.val = "sin"; + i = i + 2; } - else if (input[i] == 'c' && i < input.length() - 5) + else if (input[i] == 'c' && input[i + 1] == 'o' && input[i + 2] == 's' && input[i + 3] == '(') { - if (input[i + 1] == 'o' && input[i + 2] == 's' && input[i + 3] == '(') - { - tmp.type = 5; - tmp.val = "cos"; - i = i + 2; - } + tmp.type = 5; + tmp.val = "cos"; + i = i + 2; } - else if (input[i] == 'e' && i < input.length() - 5) + else if (input[i] == 'e' && input[i + 1] == 'x' && input[i + 2] == 'p' && input[i + 3] == '(') { - if (input[i + 1] == 'x' && input[i + 2] == 'p' && input[i + 3] == '(') - { - tmp.type = 5; - tmp.val = "exp"; - i = i + 2; - } + tmp.type = 5; + tmp.val = "exp"; + i = i + 2; } - else if (input[i] == 'l' && i < input.length() - 4) + else if (input[i] == 'l' && input[i + 1] == 'n' && input[i + 2] == '(') { - if (input[i + 1] == 'n' && input[i + 2] == '(') - { - tmp.type = 5; - tmp.val = "ln"; - i = i + 1; - } + tmp.type = 5; + tmp.val = "ln"; + i = i + 1; } else { @@ -130,17 +142,22 @@ void Arithmetic::split() status = 1; } -int Arithmetic::check_bkt() +bool Arithmetic::check_bkt() { - int k = 0; + Stack T; for (size_t i = 0; i < inp_lex.size(); i++) { if (inp_lex[i].type == 0) - k++; + T.Put('('); if (inp_lex[i].type == -1) - k--; + { + if (T.IsEmpty()) + return false; + else + T.Get(); + } } - return k; + return T.IsEmpty(); } vector Arithmetic::check_symbols() @@ -156,19 +173,71 @@ vector Arithmetic::check_symbols() return err; } +bool Arithmetic::check_points() +{ + for (size_t i = 0; i < inp_lex.size(); i++) + { + if (inp_lex[i].type == -3) + { + size_t p = inp_lex[i].val.find_first_of('.'); + p = inp_lex[i].val.find_first_of('.', p + 1); + if (p != inp_lex[i].val.npos) + return false; + } + } + return true; +} + +bool Arithmetic::check_operations() +{ + if (inp_lex[0].type > 0 && inp_lex[0].type < 4) + { + return false; + } + if (inp_lex.back().type > 0 && inp_lex.back().type < 4) + { + return false; + } + + for (size_t i = 0; i < inp_lex.size(); i++) + { + if ((inp_lex[i].type > 0 && inp_lex[i].type < 4) && (inp_lex[i + 1].type > 0 && inp_lex[i + 1].type < 4)) + { + return false; + } + if (inp_lex[i].type == 4 && inp_lex[i + 1].type == 4) + { + return false; + } + if (i != inp_lex.size() - 1) + if (inp_lex[i].type == -1 && (inp_lex[i + 1].type == -3 || inp_lex[i + 1].type == -2 || inp_lex[i + 1].type == 0 || inp_lex[i + 1].type == 5)) + { + return false; + } + } + return true; +} + bool Arithmetic::isCorrect() { bool F = true; - int tmp = check_bkt(); - if (tmp > 0) + + if (!check_points()) { + cout << "Input error: extra point in number" << endl; F = false; - cout << "Input error: missing " << tmp << "closing brackets!\n"; } - else if (tmp < 0) + + if (!check_bkt()) + { + cout << "Input error: brackets" << endl; + F = false; + } + + if (!check_operations()) { + cout << "Input error: operations" << endl; F = false; - cout << "Input error: missing " << -tmp << "opening brackets!\n"; } vector err = check_symbols(); diff --git a/test/test_arithmetic.cpp b/test/test_arithmetic.cpp index 34e479e..63a3eb8 100644 --- a/test/test_arithmetic.cpp +++ b/test/test_arithmetic.cpp @@ -1,3 +1,124 @@ // тесты для вычисления арифметических выражений -#include \ No newline at end of file +#include +#include "arithmetic.h" + +TEST(arithmetic, can_create_arithmetic) +{ + ASSERT_NO_THROW(Arithmetic A("5 + 5")); +} + +TEST(arithmetic, split_correct) +{ + Arithmetic A("(sin(2*exp(log - 10)) + cos(2^2)) / -ln(a)"); + A.split(); + vector inp = A.get_input_lex(); + vector v; + v.push_back(lexema("(", 0)); + v.push_back(lexema("sin", 5)); + v.push_back(lexema("(", 0)); + v.push_back(lexema("2", -3)); + v.push_back(lexema("*", 2)); + v.push_back(lexema("exp", 5)); + v.push_back(lexema("(", 0)); + v.push_back(lexema("log", -2)); + v.push_back(lexema("-", 1)); + v.push_back(lexema("10", -3)); + v.push_back(lexema(")", -1)); + v.push_back(lexema(")", -1)); + v.push_back(lexema("+", 1)); + v.push_back(lexema("cos", 5)); + v.push_back(lexema("(", 0)); + v.push_back(lexema("2", -3)); + v.push_back(lexema("^", 3)); + v.push_back(lexema("2", -3)); + v.push_back(lexema(")", -1)); + v.push_back(lexema(")", -1)); + v.push_back(lexema("/", 2)); + v.push_back(lexema("--", 4)); + v.push_back(lexema("ln", 5)); + v.push_back(lexema("(", 0)); + v.push_back(lexema("a", -2)); + v.push_back(lexema(")", -1)); + + bool F = true; + for (size_t i = 0; i < v.size(); i++) + { + if (!(inp[i] == v[i])) + F = false; + } + + EXPECT_TRUE(F); +} + +TEST(arithmetic, check_bkt) +{ + Arithmetic A("4 + ( 4 - 1 ) )"); + A.split(); + EXPECT_FALSE(A.check_bkt()); +} + +TEST(arithmetic, check_symbols) +{ + Arithmetic A("(5 + 5) & 4"); + A.split(); + EXPECT_EQ(6, A.check_symbols().front()); +} + +TEST(arithmetic, check_points) +{ + Arithmetic A("5.0001.1 + 1"); + A.split(); + EXPECT_FALSE(A.check_points()); +} + +TEST(arithmetic, check_operation) +{ + Arithmetic A("5 + + 1"); + A.split(); + EXPECT_FALSE(A.check_operations()); +} + +TEST(arithmetic, converter_correct) +{ + Arithmetic A("(sin(2*exp(log - 10)) + cos(2^2)) / -ln(a)"); + A.split(); + A.converter(); + vector inp = A.get_polish_lex(); + vector v; + v.push_back(lexema("2", -3)); + v.push_back(lexema("log", -2)); + v.push_back(lexema("10", -3)); + v.push_back(lexema("-", 1)); + v.push_back(lexema("exp", 5)); + v.push_back(lexema("*", 2)); + v.push_back(lexema("sin", 5)); + v.push_back(lexema("2", -3)); + v.push_back(lexema("2", -3)); + v.push_back(lexema("^", 3)); + v.push_back(lexema("cos", 5)); + v.push_back(lexema("+", 1)); + v.push_back(lexema("a", -2)); + v.push_back(lexema("ln", 5)); + v.push_back(lexema("--", 4)); + v.push_back(lexema("/", 2)); + + bool F = true; + for (size_t i = 0; i < v.size(); i++) + { + if (!(inp[i] == v[i])) + F = false; + } + + EXPECT_TRUE(F); +} + +TEST(arithmetic, calculate_correct) +{ + Arithmetic A("(sin(2*exp(11 - 10)) + cos(2^2)) / -ln(2.71)"); + A.split(); + A.converter(); + A.set_values(); + A.calculate(); + EXPECT_FLOAT_EQ(1.406983, A.get_result()); +} \ No newline at end of file diff --git a/test/test_stack.cpp b/test/test_stack.cpp index 60d0d16..69c3ad7 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -26,7 +26,7 @@ TEST(Stack, can_put_and_view) EXPECT_EQ(1, T.View()); } -TEST(Stack, get_delete_element) +TEST(Stack, get_deletes_element) { Stack T(5); T.Put(1); From e80d21abf0aea32e4e144e64afcbeabf6368b5af Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 26 Nov 2021 20:22:28 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20Get()=20=D1=82=D0=B5=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D1=8C=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/stack.h | 2 +- src/arithmetic.cpp | 2 +- test/test_arithmetic.cpp | 200 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 197 insertions(+), 7 deletions(-) diff --git a/include/stack.h b/include/stack.h index 87ca564..a777a07 100644 --- a/include/stack.h +++ b/include/stack.h @@ -46,7 +46,7 @@ class Stack pMem[++Hi] = val; } - T Get() + T& Get() { if (IsEmpty()) throw std::exception("Stack is empty!"); diff --git a/src/arithmetic.cpp b/src/arithmetic.cpp index 6e359c2..c1e33af 100644 --- a/src/arithmetic.cpp +++ b/src/arithmetic.cpp @@ -50,7 +50,7 @@ void Arithmetic::split() for (size_t i = 0; i < input.length(); i++) { string abc = "abcdefghijklmnopqrstuvwxyz"; - string num = ".,0123456789"; + string num = ".0123456789"; size_t p_abc = abc.find(input[i]); size_t p_num = num.find(input[i]); diff --git a/test/test_arithmetic.cpp b/test/test_arithmetic.cpp index 63a3eb8..dca48dd 100644 --- a/test/test_arithmetic.cpp +++ b/test/test_arithmetic.cpp @@ -8,7 +8,7 @@ TEST(arithmetic, can_create_arithmetic) ASSERT_NO_THROW(Arithmetic A("5 + 5")); } -TEST(arithmetic, split_correct) +TEST(arithmetic, split_correct1) { Arithmetic A("(sin(2*exp(log - 10)) + cos(2^2)) / -ln(a)"); A.split(); @@ -51,13 +51,118 @@ TEST(arithmetic, split_correct) EXPECT_TRUE(F); } -TEST(arithmetic, check_bkt) +TEST(arithmetic, split_correct2) +{ + Arithmetic A("-(3*3)^sin(1)*ln(10)"); + A.split(); + vector inp = A.get_input_lex(); + vector v; + v.push_back(lexema("--", 4)); + v.push_back(lexema("(", 0)); + v.push_back(lexema("3", -3)); + v.push_back(lexema("*", 2)); + v.push_back(lexema("3", -3)); + v.push_back(lexema(")", -1)); + v.push_back(lexema("^", 3)); + v.push_back(lexema("sin", 5)); + v.push_back(lexema("(", 0)); + v.push_back(lexema("1", -3)); + v.push_back(lexema(")", -1)); + v.push_back(lexema("*", 2)); + v.push_back(lexema("ln", 5)); + v.push_back(lexema("(", 0)); + v.push_back(lexema("10", -3)); + v.push_back(lexema(")", -1)); + + bool F = true; + for (size_t i = 0; i < v.size(); i++) + { + if (!(inp[i] == v[i])) + F = false; + } + + EXPECT_TRUE(F); +} + +TEST(arithmetic, split_correct3) +{ + Arithmetic A("5 + si"); + A.split(); + vector inp = A.get_input_lex(); + vector v; + v.push_back(lexema("5", -3)); + v.push_back(lexema("+", 1)); + v.push_back(lexema("si", -2)); + + bool F = true; + for (size_t i = 0; i < v.size(); i++) + { + if (!(inp[i] == v[i])) + F = false; + } + + EXPECT_TRUE(F); +} + +TEST(arithmetic, split_correct4) +{ + Arithmetic A("ln + exp + sin + cos"); + A.split(); + vector inp = A.get_input_lex(); + vector v; + v.push_back(lexema("ln", -2)); + v.push_back(lexema("+", 1)); + v.push_back(lexema("exp", -2)); + v.push_back(lexema("+", 1)); + v.push_back(lexema("sin", -2)); + v.push_back(lexema("+", 1)); + v.push_back(lexema("cos", -2)); + + bool F = true; + for (size_t i = 0; i < v.size(); i++) + { + if (!(inp[i] == v[i])) + F = false; + } + + EXPECT_TRUE(F); +} + +TEST(arithmetic, check_incorrect_bkt1) { Arithmetic A("4 + ( 4 - 1 ) )"); A.split(); EXPECT_FALSE(A.check_bkt()); } +TEST(arithmetic, check_incorrect_bkt2) +{ + Arithmetic A("((( 1 + 2) * (2 - 3) ) / ) (3 – 5) + 7 ) * 5"); + A.split(); + EXPECT_FALSE(A.check_bkt()); +} + +TEST(arithmetic, check_incorrect_bkt3) +{ + Arithmetic A("{4 - 5 * [(3 + 5)}"); + A.split(); + EXPECT_FALSE(A.check_bkt()); +} + +TEST(arithmetic, check_correct_bkt1) +{ + Arithmetic A("{5 - [4 * 4] + sin(4)}"); + A.split(); + EXPECT_TRUE(A.check_bkt()); +} + +TEST(arithmetic, check_correct_bkt2) +{ + Arithmetic A("(5 + 5)^ln(5) - [4 + 5]"); + A.split(); + EXPECT_TRUE(A.check_bkt()); +} + TEST(arithmetic, check_symbols) { Arithmetic A("(5 + 5) & 4"); @@ -72,14 +177,29 @@ TEST(arithmetic, check_points) EXPECT_FALSE(A.check_points()); } -TEST(arithmetic, check_operation) +TEST(arithmetic, check_operation1) { Arithmetic A("5 + + 1"); A.split(); EXPECT_FALSE(A.check_operations()); } -TEST(arithmetic, converter_correct) +TEST(arithmetic, check_operation2) +{ + Arithmetic A("[4 + ) 5 * 5 ( - 6]"); + A.split(); + //EXPECT_FALSE(A.check_bkt()); + EXPECT_FALSE(A.check_operations()); +} + +TEST(arithmetic, check_operation3) +{ + Arithmetic A("- - 5"); + A.split(); + EXPECT_FALSE(A.check_operations()); +} + +TEST(arithmetic, converter_correct1) { Arithmetic A("(sin(2*exp(log - 10)) + cos(2^2)) / -ln(a)"); A.split(); @@ -113,7 +233,57 @@ TEST(arithmetic, converter_correct) EXPECT_TRUE(F); } -TEST(arithmetic, calculate_correct) +TEST(arithmetic, converter_correct2) +{ + Arithmetic A("-sin(1.7)^5"); + A.split(); + A.converter(); + vector inp = A.get_polish_lex(); + vector v; + v.push_back(lexema("1.7", -3)); + v.push_back(lexema("sin", 5)); + v.push_back(lexema("--", 4)); + v.push_back(lexema("5", -3)); + v.push_back(lexema("^", 3)); + + bool F = true; + for (size_t i = 0; i < v.size(); i++) + { + if (!(inp[i] == v[i])) + F = false; + } + + EXPECT_TRUE(F); +} + +TEST(arithmetic, converter_correct3) +{ + Arithmetic A("-5*(5+5)^-1"); + A.split(); + A.converter(); + vector inp = A.get_polish_lex(); + vector v; + v.push_back(lexema("5", -3)); + v.push_back(lexema("--", 4)); + v.push_back(lexema("5", -3)); + v.push_back(lexema("5", -3)); + v.push_back(lexema("+", 1)); + v.push_back(lexema("1", -3)); + v.push_back(lexema("--", 4)); + v.push_back(lexema("^", 3)); + v.push_back(lexema("*", 2)); + + bool F = true; + for (size_t i = 0; i < v.size(); i++) + { + if (!(inp[i] == v[i])) + F = false; + } + + EXPECT_TRUE(F); +} + +TEST(arithmetic, calculate_correct1) { Arithmetic A("(sin(2*exp(11 - 10)) + cos(2^2)) / -ln(2.71)"); A.split(); @@ -121,4 +291,24 @@ TEST(arithmetic, calculate_correct) A.set_values(); A.calculate(); EXPECT_FLOAT_EQ(1.406983, A.get_result()); +} + +TEST(arithmetic, calculate_correct2) +{ + Arithmetic A("-(3*3)^3*ln(7)"); + A.split(); + A.converter(); + A.set_values(); + A.calculate(); + EXPECT_FLOAT_EQ(-1418.56849866, A.get_result()); +} + +TEST(arithmetic, calculate_correct3) +{ + Arithmetic A("sin(-4.21*5^ln(5.78)/cos(1.45 + 3.54))"); + A.split(); + A.converter(); + A.set_values(); + A.calculate(); + EXPECT_FLOAT_EQ(-0.86246998, A.get_result()); } \ No newline at end of file