-
Notifications
You must be signed in to change notification settings - Fork 0
Hw4 parse tree #7
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
base: master
Are you sure you want to change the base?
Conversation
yurii-litvinov
left a comment
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.
Архитектурно всё правильно (почти), но код сыроват
| } | ||
|
|
||
| [TestCase] | ||
| public void TestSubstraction() |
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.
| public void TestSubstraction() | |
| public void TestSubtraction() |
| } | ||
|
|
||
| [TestCase] | ||
| public void TestMultiplacation() |
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.
| public void TestMultiplacation() | |
| public void TestMultiplication() |
| Assert.AreEqual(1, tree.Calculate()); | ||
| } | ||
|
|
||
| [TestCase] |
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.
Что-то с отступом не то
|
|
||
| namespace hw4ParseTree | ||
| { | ||
| public class Addition : Operator |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
||
| public Addition(char sign, INode leftChild, INode rightChild) | ||
| { | ||
| Sign = sign; |
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.
А разве Addition не знает, какой у него sign? :)
| Console.Write(Sign); | ||
| RightChild.Print(); | ||
| Console.Write(")"); | ||
| } |
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.
Надо перевод строки :)
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.
Напоминаю
| private INode root; | ||
|
|
||
| /// <summary> | ||
| /// Функция потсроения дерева разбора |
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.
| /// Функция потсроения дерева разбора | |
| /// Функция построения дерева разбора |
| } | ||
| else if (line[index] == ')') | ||
| { | ||
| countBrackets--; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| throw new InvalidExpressionException(); | ||
| } | ||
| } | ||
| return root; |
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.
Ой, а тут с отступом совсем беда
hw4ParseTree/hw4ParseTree/Program.cs
Outdated
| { | ||
| var tree = new ParseTree(); | ||
| Console.WriteLine("Введите выражение -"); | ||
| var expression = Console.ReadLine(); |
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.
Вроде как хотелось из файла читать
yurii-litvinov
left a comment
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.
Тут уже однозначно стало лучше, но недостаточно лучше для того, чтобы можно было поставить полные баллы
| { | ||
| var str = "( / 3 2 )"; | ||
| tree.BuildTree(str); | ||
| Assert.AreEqual(1.5, tree.Calculate()); |
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.
Ой, вещественные числа нельзя сравнивать через AreEqual с двумя аргументами. См. https://docs.nunit.org/articles/nunit/writing-tests/assertions/classic-assertions/Assert.AreEqual.html
| namespace Hw4ParseTree | ||
| { | ||
| /// <summary> | ||
| /// класс для сложения |
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.
Я бы написал, что это узел синтаксического дерева, который представляет оператор сложения, но так тоже ок :)
| /// </summary> | ||
| public class Addition : Operator | ||
| { | ||
| public override char Sign { get; } |
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.
| public override char Sign { get; } | |
| public override char Sign => '+'; |
И тогда в конструкторе не надо его инициализировать
| namespace Hw4ParseTree | ||
| { | ||
| /// <summary> | ||
| /// исключение для неправильных выражений6 |
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.
| /// исключение для неправильных выражений6 | |
| /// исключение для неправильных выражений. |
|
|
||
| namespace Hw4ParseTree | ||
| { | ||
| class Operand : 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.
А тут и ниже комментариев всё равно нет
hw4ParseTree/hw4ParseTree/Operand.cs
Outdated
| { | ||
| class Operand : INode | ||
| { | ||
| public double Number { 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.
И я не думаю, что ему нужен сеттер (только не делайте его public-полем, пожалуйста)
hw4ParseTree/hw4ParseTree/Operand.cs
Outdated
| public Operand(double number) | ||
| { | ||
| Number = number; | ||
| } | ||
|
|
||
| public void Print() | ||
| { | ||
| Console.Write($" {Number} "); | ||
| } |
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.
Это тоже можно через =>
| Console.Write(Sign); | ||
| RightChild.Print(); | ||
| Console.Write(")"); | ||
| } |
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.
Напоминаю
| '-' => new Subtraction(Build(line, ref index), Build(line, ref index)), | ||
| '/' => new Division(Build(line, ref index), Build(line, ref index)), | ||
| '*' => new Multiplication(Build(line, ref index), Build(line, ref index)), | ||
| _ => throw new Exception(), |
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.
Есть же специальное исключение для неправильных выражений
yurii-litvinov
left a comment
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.
Окей, зачтена
| /// </summary> | ||
| class Operand : INode | ||
| { | ||
| private double Number; |
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.
Поля, как известно, именуются со строчной. Если Вам сложно запомнить такие мелочи, используйте StyleCop.
No description provided.