Skip to content

Commit

Permalink
refactor(global): change code
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealPad committed Mar 4, 2024
1 parent 0aafc8c commit 5f22c72
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 23 deletions.
3 changes: 1 addition & 2 deletions src/Calculator/Calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Error.h"

namespace Calculator {

Calculator::Calculator() {
description();
}
Expand Down Expand Up @@ -52,6 +53,4 @@ namespace Calculator {
std::cout << "[calcul] => ";
}



} // Calculator
1 change: 0 additions & 1 deletion src/OperationsPriorities/OperationsPriorities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ namespace Operations {
blocks.push_back(block);
if (operators.size() != blocks.size() - 1)
throw ErrorCalculator::Error(ErrorCalculator::Error::TYPO_USER_INPUT);
// mettre dans la première boucle
for (auto &b : blocks) {
if (b[0] == '(') {
std::string tmp = b.substr(1, b.size() - 2);
Expand Down
18 changes: 1 addition & 17 deletions src/OperationsPriorities/ProxyOperationsPriorities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,11 @@ namespace Operations {
this->_operationsPriorities = std::make_unique<OperationsPriorities>();
}

bool ProxyOperationsPriorities::checkParenthesis(std::string const &operation) {
unsigned int nbrLeftParenthesis = 0;

for (auto const &c : operation) {
if (c == '(')
++nbrLeftParenthesis;
if (c == ')' && nbrLeftParenthesis == 0)
return false;
if (c == ')')
--nbrLeftParenthesis;
}
return nbrLeftParenthesis == 0;
}


std::string ProxyOperationsPriorities::makeOperation(std::string &operation) {
std::regex self_regex("^[0-9()+*/%\\- ]+$",std::regex_constants::ECMAScript | std::regex_constants::icase);
if (!std::regex_search(operation, self_regex) || !this->checkParenthesis(operation))
if (!std::regex_search(operation, self_regex))
throw ErrorCalculator::Error(ErrorCalculator::Error::TYPO_USER_INPUT);
return this->_operationsPriorities->makeOperation(operation);
}


}
2 changes: 0 additions & 2 deletions src/OperationsPriorities/ProxyOperationsPriorities.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ namespace Operations {
std::string makeOperation(std::string &operation) override;

private:
bool checkParenthesis(std::string const &operation);

std::unique_ptr<OperationsPriorities> _operationsPriorities;
};

Expand Down
2 changes: 1 addition & 1 deletion tests/OperationsPriorities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ TEST(ProxyOperationsPriorities, InvalidStringFour)
} catch (ErrorCalculator::Error &e) {
isValid = false;
}
EXPECT_EQ(isValid, false);
EXPECT_EQ(isValid, true);
}

TEST(ProxyOperationsPriorities, InvalidStringFive)
Expand Down

0 comments on commit 5f22c72

Please sign in to comment.