Skip to content

Mgavryliuk/polish calc#4

Open
Michael1249 wants to merge 4 commits intoalexkutsan:masterfrom
Michael1249:mgavryliuk/PolishCalc
Open

Mgavryliuk/polish calc#4
Michael1249 wants to merge 4 commits intoalexkutsan:masterfrom
Michael1249:mgavryliuk/PolishCalc

Conversation

@Michael1249
Copy link
Copy Markdown

No description provided.


class IOperandsMemory{
public:
virtual value_t getOperand() = 0;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like method should not change class state. May be const?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

public:
virtual value_t getOperand() = 0;
virtual void putOperand(const value_t&) = 0;
virtual void applyOperation(operation_t) = 0;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear output of the method

@@ -0,0 +1,24 @@
#include "operandsmemory.h"

PolishCalcComponent::value_t PolishCalcComponent::OperandsMemory::getOperand()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename to Pop operand


class OperandsMemory: public IOperandsMemory{
public:
virtual value_t getOperand() override;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++ note.
Virtual and override keywords on the same place are redundant.

using value_t = double;

class IOperandsMemory;
using operation_t = std::function<void(PolishCalcComponent::IOperandsMemory*)>;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operation_t naming (OperationType) is a bit confusing.
I would rename it just to an Operation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as default, for typedef and using i use *_t

std::vector<std::string> tokens;
PolishCalcComponent::split2Tokens(inputStr, tokens);

std::unique_ptr<IOperandsMemory> memory(makeMemory());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++ suggest :
auto memory = make_memory()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


std::unique_ptr<IOperandsMemory> memory(makeMemory());

processTokens(tokens, memory.get());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if processTokens does not control memory life-cycle I would provide it by reference


processTokens(tokens, memory.get());

assert(1 == memory->size());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on user input. Please do not assert user input


// Decompose statement
while( pos != std::string::npos ) {
out.push_back( in.substr( initialPos, pos - initialPos ) );
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make microrefactoring of this method and use std lib


//TODO: fix negative tests

//TEST_F(CalcTest, LogicErrorExtraOperator) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not comment failed tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants