-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse Tree #7
base: main
Are you sure you want to change the base?
Parse Tree #7
Conversation
@@ -0,0 +1,15 @@ | |||
namespace ParseTree; | |||
|
|||
public interface INode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Надо комментарий и к самому интерфейсу, и это даже важнее, чем комментарии к его методам
ParseTree/ParseTree/INode.cs
Outdated
/// <summary> | ||
/// Evaluates value of current node subtree. | ||
/// </summary> | ||
/// <returns></returns> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А вот пустые тэги не надо
ParseTree/ParseTree/IParseTree.cs
Outdated
enum NodeType | ||
{ | ||
Operator, | ||
Operand | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Антипаттерн "Тэг типа" :) По идее, дереву должно быть всё равно, оператор это или операнд
ParseTree/ParseTree/IParseTree.cs
Outdated
/// </summary> | ||
/// <param name="value"></param> | ||
/// <param name="operandOrOperator"></param> | ||
void AddNode(int value, NodeType operandOrOperator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У оператора не может быть value
/// <summary> | ||
/// Parent node of the current node. | ||
/// </summary> | ||
public INode? Parent { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И у оператора, и у операнда есть это свойство, можно поднять его в их общего предка
ParseTree/ParseTree/ParseTree.cs
Outdated
{ | ||
if (_currentNode == null) | ||
{ | ||
throw new Exception("Wrong input"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вообще, просто Exception кидать нельзя
ParseTree/ParseTree/ParseTree.cs
Outdated
{ | ||
throw new Exception("Wrong input"); | ||
} | ||
Operand newNode = new Operand(value) { Parent = _currentNode }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Operand newNode = new Operand(value) { Parent = _currentNode }; | |
var newNode = new Operand(value) { Parent = _currentNode }; |
testTree.Parse("../../../testExpression.txt"); | ||
Assert.AreEqual(testTree.Eval(), 957); | ||
|
||
strWriter = new StreamWriter(File.Open("../../../testExpression.txt", FileMode.Create)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Несколько тестовых сценариев --> несколько тестов
[Test] | ||
public void EvaluationOfLargeExpressionsShouldBeCorrect() | ||
{ | ||
StreamWriter strWriter = new StreamWriter(File.Open("../../../testExpression.txt", FileMode.Create)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StreamWriter strWriter = new StreamWriter(File.Open("../../../testExpression.txt", FileMode.Create)); | |
var strWriter = new StreamWriter(File.Open("../../../testExpression.txt", FileMode.Create)); |
strWriter.Close(); | ||
IParseTree testTree = new ParseTree(); | ||
testTree.Parse("../../../testExpression.txt"); | ||
Assert.AreEqual(testTree.Eval(), 957); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Наоборот, Assert.AreEqual(957, testTree.Eval());
No description provided.