From 21431f8a70613715edf7eef99ba2c0b10fa6eea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D0=B6=D0=B5=D0=BB=D0=B5=D0=B2=20=D0=90=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=BD=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Wed, 5 Dec 2018 16:19:18 +0300 Subject: [PATCH 1/2] Aded trigonometry --- GoogleTest/test-calc.cpp | 273 ++++++++++++++++++++++++++++++++++ Graphics/Project3/MyForm.h | 10 +- Graphics/Project3/MyForm.resx | 120 +++++++++++++++ mp2-lab3-stack/TCalc.cpp | 58 ++++++++ mp2-lab3-stack/TCalc.h | 3 + 5 files changed, 461 insertions(+), 3 deletions(-) create mode 100644 GoogleTest/test-calc.cpp create mode 100644 Graphics/Project3/MyForm.resx diff --git a/GoogleTest/test-calc.cpp b/GoogleTest/test-calc.cpp new file mode 100644 index 0000000..ebd34e1 --- /dev/null +++ b/GoogleTest/test-calc.cpp @@ -0,0 +1,273 @@ +#include "gtest.h" +#include "..\mp2-lab3-stack\TCalc.h" + +TEST(TCalculator, check_brackets_1_true) +{ + TCalculator tmp; + tmp.SetInfix("()"); + EXPECT_EQ(true, tmp.CheckBrackets()); +} + +TEST(TCalculator, check_brackets_2_true) +{ + TCalculator tmp; + tmp.SetInfix("(())"); + EXPECT_EQ(true, tmp.CheckBrackets()); +} + +TEST(TCalculator, check_brackets_3_true) +{ + TCalculator tmp; + tmp.SetInfix("()()"); + EXPECT_EQ(true, tmp.CheckBrackets()); +} + +TEST(TCalculator, check_brackets_4_true) +{ + TCalculator tmp; + tmp.SetInfix("(()())"); + EXPECT_EQ(true, tmp.CheckBrackets()); +} + +TEST(TCalculator, check_brakets_1_false) +{ + TCalculator tmp; + tmp.SetInfix("("); + EXPECT_EQ(false, tmp.CheckBrackets()); +} +TEST(TCalculator, check_brakets_2_false) +{ + TCalculator tmp; + tmp.SetInfix(")"); + EXPECT_EQ(false, tmp.CheckBrackets()); +} +TEST(TCalculator, check_brakets_3_false) +{ + TCalculator tmp; + tmp.SetInfix("(()"); + EXPECT_EQ(false, tmp.CheckBrackets()); +} +TEST(TCalculator, check_brakets_4_false) +{ + TCalculator tmp; + tmp.SetInfix("())"); + EXPECT_EQ(false, tmp.CheckBrackets()); +} +TEST(TCalculator, check_brakets_5_false) +{ + TCalculator tmp; + tmp.SetInfix("()("); + EXPECT_EQ(false, tmp.CheckBrackets()); +} +TEST(TCalculator, check_brakets_6_false) +{ + TCalculator tmp; + tmp.SetInfix("((()"); + EXPECT_EQ(false, tmp.CheckBrackets()); +} +TEST(TCalculator, check_brakets_7_false) +{ + TCalculator tmp; + tmp.SetInfix("(()))"); + EXPECT_EQ(false, tmp.CheckBrackets()); +} + +TEST(TCalculator, check_empty_string) +{ + TCalculator tmp; + EXPECT_ANY_THROW(tmp.CheckBrackets()); +} +TEST(TCalculator, check_operator_1_true) +{ + TCalculator tmp; + tmp.SetInfix("2+2"); + EXPECT_EQ(true, tmp.CheckOperator()); +} +TEST(TCalculator, check_operator_2_true) +{ + TCalculator tmp; + tmp.SetInfix("(2+2)*2"); + EXPECT_EQ(true, tmp.CheckOperator()); +} +TEST(TCalculator, check_operator_3_true) +{ + TCalculator tmp; + tmp.SetInfix("(2+2)*1-(1/4)"); + EXPECT_EQ(true, tmp.CheckOperator()); +} + +TEST(TCalculator, check_operator_1_false) +{ + TCalculator tmp; + tmp.SetInfix("2++2"); + EXPECT_EQ(false, tmp.CheckOperator()); +} +TEST(TCalculator, check_operator_2_false) +{ + TCalculator tmp; + tmp.SetInfix("(2+2)+*5"); + EXPECT_EQ(false, tmp.CheckOperator()); +} + +TEST(TCalculator, check_operator_3_false) +{ + TCalculator tmp; + tmp.SetInfix("*58+45"); + EXPECT_EQ(false, tmp.CheckOperator()); +} +TEST(TCalculator, check_operator_4_false) +{ + TCalculator tmp; + tmp.SetInfix("4568-468+"); + EXPECT_EQ(false, tmp.CheckOperator()); +} + +TEST(TCalculator, simple_example_plus) +{ + TCalculator tmp; + tmp.SetInfix("2+2"); + tmp.ToPostfix(); + EXPECT_EQ("2 2+", tmp.GetPostfix()); + EXPECT_EQ(4, tmp.Calculator()); +} + +TEST(TCalculator, simple_example_minus) +{ + TCalculator tmp; + tmp.SetInfix("2-2"); + tmp.ToPostfix(); + EXPECT_EQ("2 2-", tmp.GetPostfix()); + EXPECT_EQ(0, tmp.Calculator()); +} + +TEST(TCalculator, ToPostfix_only_minus) +{ + TCalculator tmp; + tmp.SetInfix("-5"); + tmp.ToPostfix(); + cout << tmp.GetPostfix(); + EXPECT_EQ("0 5-", tmp.GetPostfix()); +} +TEST(TCalculator, simple_example_multiplication) +{ + TCalculator tmp; + tmp.SetInfix("2*3"); + tmp.ToPostfix(); + EXPECT_EQ("2 3*", tmp.GetPostfix()); + EXPECT_EQ(6, tmp.Calculator()); +} +TEST(TCalculator, simple_example_division) +{ + TCalculator tmp; + tmp.SetInfix("2/4"); + tmp.ToPostfix(); + EXPECT_EQ("2 4/", tmp.GetPostfix()); + EXPECT_EQ(0.5, tmp.Calculator()); + +} +TEST(TCalculator, simple_example_degree) +{ + TCalculator tmp; + tmp.SetInfix("2^3"); + tmp.ToPostfix(); + EXPECT_EQ("2 3^", tmp.GetPostfix()); + EXPECT_EQ(8, tmp.Calculator()); +} +TEST(TCalculator, example_1) +{ + TCalculator tmp; + tmp.SetInfix("(2+2)*3"); + tmp.ToPostfix(); + EXPECT_EQ("2 2+ 3*", tmp.GetPostfix()); + EXPECT_EQ(12, tmp.Calculator()); +} + +TEST(TCalculator, example_2) +{ + TCalculator tmp; + tmp.SetInfix("2/(2+2)+2"); + tmp.ToPostfix(); + EXPECT_EQ("2 2 2+ /2+", tmp.GetPostfix()); + EXPECT_EQ(2.5, tmp.Calculator()); +} +TEST(TCalculator, example_3) +{ + TCalculator tmp; + tmp.SetInfix("1/(1+1)^3+2"); + tmp.ToPostfix(); + EXPECT_EQ("1 1 1+ 3 ^/2+", tmp.GetPostfix()); + EXPECT_EQ(2.125, tmp.Calculator()); +} + +TEST(TCalculator, example_4) +{ + TCalculator tmp; + tmp.SetInfix("(5+7)/40*2^5"); + tmp.ToPostfix(); + EXPECT_EQ("5 7+ 40 /2 5^*", tmp.GetPostfix()); + EXPECT_EQ(9.6, tmp.Calculator()); +} +TEST(TCalculator, example_5) +{ + TCalculator tmp; + tmp.SetInfix("256-12^2/2"); + tmp.ToPostfix(); + EXPECT_EQ("256 12 2 ^2/-", tmp.GetPostfix()); + EXPECT_EQ(184, tmp.Calculator()); +} +TEST(TCalculator, test_sin) +{ + TCalculator tmp; + tmp.SetInfix("sin(30)"); + tmp.ToPostfix(); + EXPECT_EQ("30s", tmp.GetPostfix()); + EXPECT_EQ(0.5, tmp.Calculator()); +} +TEST(Tcalculator, test_sin_2) +{ + TCalculator tmp; + tmp.SetInfix("5*sin(30)+2"); + tmp.ToPostfix(); + EXPECT_EQ("5 30 s*2+", tmp.GetPostfix()); + EXPECT_EQ(4.5, tmp.Calculator()); +} +TEST(TCalculator, test_cos) +{ + TCalculator tmp; + tmp.SetInfix("cos(60)"); + tmp.ToPostfix(); + EXPECT_EQ("60c", tmp.GetPostfix()); + EXPECT_EQ(0.5, tmp.Calculator()); +} + +TEST(TCalculator, test_cos_2) +{ + TCalculator tmp; + tmp.SetInfix("cos(60)*2"); + tmp.ToPostfix(); + EXPECT_EQ("60 c2*", tmp.GetPostfix()); + EXPECT_EQ(1, tmp.Calculator()); +} + +TEST(TCalculator, test_tg) +{ + TCalculator tmp; + tmp.SetInfix("tg(45)"); + tmp.ToPostfix(); + EXPECT_EQ("45t", tmp.GetPostfix()); + EXPECT_EQ(1, tmp.Calculator()); +} +TEST(TCalculator, test_tg_2) +{ + TCalculator tmp; + tmp.SetInfix("tg(10+35)*2"); + tmp.ToPostfix(); + EXPECT_EQ("10 35+ t2*", tmp.GetPostfix()); + EXPECT_EQ(2, tmp.Calculator()); +} +TEST(TCalculator, error_symbol) +{ + TCalculator tmp; + tmp.SetInfix("son(35)"); + EXPECT_ANY_THROW(tmp.ToPostfix()); +} \ No newline at end of file diff --git a/Graphics/Project3/MyForm.h b/Graphics/Project3/MyForm.h index d39d54b..28d4f77 100644 --- a/Graphics/Project3/MyForm.h +++ b/Graphics/Project3/MyForm.h @@ -82,6 +82,8 @@ namespace Project3 { // // textBox1 // + this->textBox1->Font = (gcnew System::Drawing::Font(L"MV Boli", 12, static_cast((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic)), + System::Drawing::GraphicsUnit::Point, static_cast(0))); this->textBox1->Location = System::Drawing::Point(12, 28); this->textBox1->Multiline = true; this->textBox1->Name = L"textBox1"; @@ -92,9 +94,11 @@ namespace Project3 { // label1 // this->label1->AutoSize = true; + this->label1->Font = (gcnew System::Drawing::Font(L"MV Boli", 12, static_cast((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic)), + System::Drawing::GraphicsUnit::Point, static_cast(0))); this->label1->Location = System::Drawing::Point(443, 36); this->label1->Name = L"label1"; - this->label1->Size = System::Drawing::Size(34, 13); + this->label1->Size = System::Drawing::Size(53, 21); this->label1->TabIndex = 4; this->label1->Text = L"Solve"; this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click); @@ -103,7 +107,7 @@ namespace Project3 { // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; - this->ClientSize = System::Drawing::Size(596, 192); + this->ClientSize = System::Drawing::Size(569, 128); this->Controls->Add(this->label1); this->Controls->Add(this->textBox1); this->Controls->Add(this->button1); @@ -124,7 +128,7 @@ namespace Project3 { calc.SetInfix(infix); calc.ToPostFix(); double res = calc.Calc(); - textBox1->Text = Convert::ToString(res); + label1->Text = Convert::ToString(res); } private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) { } diff --git a/Graphics/Project3/MyForm.resx b/Graphics/Project3/MyForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Graphics/Project3/MyForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/mp2-lab3-stack/TCalc.cpp b/mp2-lab3-stack/TCalc.cpp index 3784d74..4637248 100644 --- a/mp2-lab3-stack/TCalc.cpp +++ b/mp2-lab3-stack/TCalc.cpp @@ -1,6 +1,9 @@ #include "TCalc.h" #include #include +#define _USE_MATH_DEFINES +#include + using namespace std; int TCalc::GetPriority(char m) { @@ -34,6 +37,19 @@ void TCalc::ToPostFix() { while (GetPriority(tmp[i]) <= GetPriority(stop.Top()))postfix += stop.Pop(); stop.Push(tmp[i]); } + if (tmp[i] == 's' || tmp[i] == 'c' || tmp[i] == 't') + { + if (i == tmp.find("sin") || i == tmp.find("cos") || i == tmp.find("tg")) + { + stop.Push(tmp[i]); + if (tmp[i] == 's' || tmp[i] == 'c') + i += 2; + else + i++; + } + else + throw "Error symbol"; + } } } @@ -46,6 +62,30 @@ string TCalc::GetPostfix() { return postfix; } +bool TCalc::CheckBrackets() +{ + TStack bracket(infix.length()); + if (infix == "") + throw 'a'; + else + { + for (int i = 0; i < infix.length(); i++) + if (infix[i] == '(') + bracket.Push(infix[i]); + else if (infix[i] == ')') + { + if (bracket.IsEmpty()) + return false; + else + bracket.Pop(); + } + if (bracket.IsEmpty()) + return true; + else + return false; + } +} + double TCalc::Calc() { double num1, num2, res; stnum.clear(); @@ -76,6 +116,24 @@ double TCalc::Calc() { int l = p - &postfix[i]; i += l - 1; } + if (postfix[i] == 's' || postfix[i] == 'c' || postfix[i] == 't') + { + switch (postfix[i]) + { + case 's': + res = sin(stnum.Pop()*M_PI / 180); + stnum.Push(res); + break; + case 'c': + res = cos(stnum.Pop()*M_PI / 180); + stnum.Push(res); + break; + case 't': + res = tan(stnum.Pop()*M_PI / 180); + stnum.Push(res); + break; + } + } } TStack tmp(stnum); tmp.Pop(); diff --git a/mp2-lab3-stack/TCalc.h b/mp2-lab3-stack/TCalc.h index 4e9e9d1..3a3ffba 100644 --- a/mp2-lab3-stack/TCalc.h +++ b/mp2-lab3-stack/TCalc.h @@ -1,6 +1,8 @@ #pragma once #include "TStack.h" #include +#include +#define _USE_MATH_DEFINES class TCalc { std::string infix; @@ -13,4 +15,5 @@ class TCalc { void SetInfix(std::string inf); std::string GetPostfix(); double Calc(); + bool CheckBrackets(); }; \ No newline at end of file From 6b8da3cf0f5f58b7e3f861ea05866332b03b42cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D0=B6=D0=B5=D0=BB=D0=B5=D0=B2=20=D0=90=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=BD=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Wed, 12 Dec 2018 15:48:54 +0300 Subject: [PATCH 2/2] added test --- GoogleTest/test-calc.cpp | 248 +++++++++++++------------------------ GoogleTest/test_tstack.cpp | 1 + 2 files changed, 88 insertions(+), 161 deletions(-) diff --git a/GoogleTest/test-calc.cpp b/GoogleTest/test-calc.cpp index ebd34e1..321cac1 100644 --- a/GoogleTest/test-calc.cpp +++ b/GoogleTest/test-calc.cpp @@ -1,273 +1,199 @@ #include "gtest.h" #include "..\mp2-lab3-stack\TCalc.h" +#include -TEST(TCalculator, check_brackets_1_true) +TEST(TCalc, check_brackets_1_true) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("()"); EXPECT_EQ(true, tmp.CheckBrackets()); } -TEST(TCalculator, check_brackets_2_true) +TEST(TCalc, check_brackets_2_true) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("(())"); EXPECT_EQ(true, tmp.CheckBrackets()); } -TEST(TCalculator, check_brackets_3_true) +TEST(TCalc, check_brackets_3_true) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("()()"); EXPECT_EQ(true, tmp.CheckBrackets()); } -TEST(TCalculator, check_brackets_4_true) +TEST(TCalc, check_brackets_4_true) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("(()())"); EXPECT_EQ(true, tmp.CheckBrackets()); } -TEST(TCalculator, check_brakets_1_false) +TEST(TCalc, check_brakets_1_false) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("("); EXPECT_EQ(false, tmp.CheckBrackets()); } -TEST(TCalculator, check_brakets_2_false) +TEST(TCalc, check_brakets_2_false) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix(")"); EXPECT_EQ(false, tmp.CheckBrackets()); } -TEST(TCalculator, check_brakets_3_false) +TEST(TCalc, check_brakets_3_false) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("(()"); EXPECT_EQ(false, tmp.CheckBrackets()); } -TEST(TCalculator, check_brakets_4_false) +TEST(TCalc, check_brakets_4_false) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("())"); EXPECT_EQ(false, tmp.CheckBrackets()); } -TEST(TCalculator, check_brakets_5_false) +TEST(TCalc, check_brakets_5_false) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("()("); EXPECT_EQ(false, tmp.CheckBrackets()); } -TEST(TCalculator, check_brakets_6_false) +TEST(TCalc, check_brakets_6_false) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("((()"); EXPECT_EQ(false, tmp.CheckBrackets()); } TEST(TCalculator, check_brakets_7_false) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("(()))"); EXPECT_EQ(false, tmp.CheckBrackets()); } -TEST(TCalculator, check_empty_string) +TEST(TCalc, check_empty_string) { - TCalculator tmp; + TCalc tmp; EXPECT_ANY_THROW(tmp.CheckBrackets()); } -TEST(TCalculator, check_operator_1_true) +TEST(TCalc, simple_example_plus) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("2+2"); - EXPECT_EQ(true, tmp.CheckOperator()); -} -TEST(TCalculator, check_operator_2_true) -{ - TCalculator tmp; - tmp.SetInfix("(2+2)*2"); - EXPECT_EQ(true, tmp.CheckOperator()); -} -TEST(TCalculator, check_operator_3_true) -{ - TCalculator tmp; - tmp.SetInfix("(2+2)*1-(1/4)"); - EXPECT_EQ(true, tmp.CheckOperator()); -} - -TEST(TCalculator, check_operator_1_false) -{ - TCalculator tmp; - tmp.SetInfix("2++2"); - EXPECT_EQ(false, tmp.CheckOperator()); -} -TEST(TCalculator, check_operator_2_false) -{ - TCalculator tmp; - tmp.SetInfix("(2+2)+*5"); - EXPECT_EQ(false, tmp.CheckOperator()); -} - -TEST(TCalculator, check_operator_3_false) -{ - TCalculator tmp; - tmp.SetInfix("*58+45"); - EXPECT_EQ(false, tmp.CheckOperator()); -} -TEST(TCalculator, check_operator_4_false) -{ - TCalculator tmp; - tmp.SetInfix("4568-468+"); - EXPECT_EQ(false, tmp.CheckOperator()); -} - -TEST(TCalculator, simple_example_plus) -{ - TCalculator tmp; - tmp.SetInfix("2+2"); - tmp.ToPostfix(); + tmp.ToPostFix(); EXPECT_EQ("2 2+", tmp.GetPostfix()); - EXPECT_EQ(4, tmp.Calculator()); + EXPECT_EQ(4, tmp.Calc()); } -TEST(TCalculator, simple_example_minus) +TEST(TCalc, simple_example_minus) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("2-2"); - tmp.ToPostfix(); + tmp.ToPostFix(); EXPECT_EQ("2 2-", tmp.GetPostfix()); - EXPECT_EQ(0, tmp.Calculator()); -} - -TEST(TCalculator, ToPostfix_only_minus) -{ - TCalculator tmp; - tmp.SetInfix("-5"); - tmp.ToPostfix(); - cout << tmp.GetPostfix(); - EXPECT_EQ("0 5-", tmp.GetPostfix()); + EXPECT_EQ(0, tmp.Calc()); } -TEST(TCalculator, simple_example_multiplication) +TEST(TCalc, simple_example_multiplication) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("2*3"); - tmp.ToPostfix(); + tmp.ToPostFix(); EXPECT_EQ("2 3*", tmp.GetPostfix()); - EXPECT_EQ(6, tmp.Calculator()); + EXPECT_EQ(6, tmp.Calc()); } -TEST(TCalculator, simple_example_division) +TEST(TCalc, simple_example_division) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("2/4"); - tmp.ToPostfix(); + tmp.ToPostFix(); EXPECT_EQ("2 4/", tmp.GetPostfix()); - EXPECT_EQ(0.5, tmp.Calculator()); + EXPECT_EQ(0.5, tmp.Calc()); } -TEST(TCalculator, simple_example_degree) +TEST(TCalc, simple_example_degree) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("2^3"); - tmp.ToPostfix(); + tmp.ToPostFix(); EXPECT_EQ("2 3^", tmp.GetPostfix()); - EXPECT_EQ(8, tmp.Calculator()); + EXPECT_EQ(8, tmp.Calc()); } -TEST(TCalculator, example_1) +TEST(TCalc, example_1) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("(2+2)*3"); - tmp.ToPostfix(); + tmp.ToPostFix(); EXPECT_EQ("2 2+ 3*", tmp.GetPostfix()); - EXPECT_EQ(12, tmp.Calculator()); + EXPECT_EQ(12, tmp.Calc()); } -TEST(TCalculator, example_2) +TEST(TCalc, example_2) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("2/(2+2)+2"); - tmp.ToPostfix(); + tmp.ToPostFix(); EXPECT_EQ("2 2 2+ /2+", tmp.GetPostfix()); - EXPECT_EQ(2.5, tmp.Calculator()); + EXPECT_EQ(2.5, tmp.Calc()); } -TEST(TCalculator, example_3) +TEST(TCalc, example_3) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("1/(1+1)^3+2"); - tmp.ToPostfix(); + tmp.ToPostFix(); EXPECT_EQ("1 1 1+ 3 ^/2+", tmp.GetPostfix()); - EXPECT_EQ(2.125, tmp.Calculator()); + EXPECT_EQ(2.125, tmp.Calc()); } -TEST(TCalculator, example_4) +TEST(TCalc, example_4) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("(5+7)/40*2^5"); - tmp.ToPostfix(); + tmp.ToPostFix(); EXPECT_EQ("5 7+ 40 /2 5^*", tmp.GetPostfix()); - EXPECT_EQ(9.6, tmp.Calculator()); + EXPECT_EQ(9.6, tmp.Calc()); } -TEST(TCalculator, example_5) +TEST(TCalc, example_5) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("256-12^2/2"); - tmp.ToPostfix(); + tmp.ToPostFix(); EXPECT_EQ("256 12 2 ^2/-", tmp.GetPostfix()); - EXPECT_EQ(184, tmp.Calculator()); + EXPECT_EQ(184, tmp.Calc()); } -TEST(TCalculator, test_sin) +TEST(TCalc, test_sin) { - TCalculator tmp; + TCalc tmp; + bool check; tmp.SetInfix("sin(30)"); - tmp.ToPostfix(); + tmp.ToPostFix(); + if (abs(0.5 - tmp.Calc()) < pow(10, -10)) + check = true; + else + check = false; EXPECT_EQ("30s", tmp.GetPostfix()); - EXPECT_EQ(0.5, tmp.Calculator()); -} -TEST(Tcalculator, test_sin_2) -{ - TCalculator tmp; - tmp.SetInfix("5*sin(30)+2"); - tmp.ToPostfix(); - EXPECT_EQ("5 30 s*2+", tmp.GetPostfix()); - EXPECT_EQ(4.5, tmp.Calculator()); + EXPECT_EQ(true, check); } -TEST(TCalculator, test_cos) + +TEST(TCalcr, test_cos) { - TCalculator tmp; + TCalc tmp; + bool check; tmp.SetInfix("cos(60)"); - tmp.ToPostfix(); + tmp.ToPostFix(); + if (abs(0.5 - tmp.Calc()) < pow(10, -10)) + check = true; + else + check = false; EXPECT_EQ("60c", tmp.GetPostfix()); - EXPECT_EQ(0.5, tmp.Calculator()); + EXPECT_EQ(true, check); } -TEST(TCalculator, test_cos_2) -{ - TCalculator tmp; - tmp.SetInfix("cos(60)*2"); - tmp.ToPostfix(); - EXPECT_EQ("60 c2*", tmp.GetPostfix()); - EXPECT_EQ(1, tmp.Calculator()); -} - -TEST(TCalculator, test_tg) -{ - TCalculator tmp; - tmp.SetInfix("tg(45)"); - tmp.ToPostfix(); - EXPECT_EQ("45t", tmp.GetPostfix()); - EXPECT_EQ(1, tmp.Calculator()); -} -TEST(TCalculator, test_tg_2) -{ - TCalculator tmp; - tmp.SetInfix("tg(10+35)*2"); - tmp.ToPostfix(); - EXPECT_EQ("10 35+ t2*", tmp.GetPostfix()); - EXPECT_EQ(2, tmp.Calculator()); -} -TEST(TCalculator, error_symbol) +TEST(TCalc, error_symbol) { - TCalculator tmp; + TCalc tmp; tmp.SetInfix("son(35)"); - EXPECT_ANY_THROW(tmp.ToPostfix()); + EXPECT_ANY_THROW(tmp.ToPostFix()); + } \ No newline at end of file diff --git a/GoogleTest/test_tstack.cpp b/GoogleTest/test_tstack.cpp index 63254fe..9f60240 100644 --- a/GoogleTest/test_tstack.cpp +++ b/GoogleTest/test_tstack.cpp @@ -81,4 +81,5 @@ TEST(TStack, can_clear_stack) TS.clear(); ASSERT_TRUE(TS.IsEmpty()); + system("pause"); } \ No newline at end of file