Conversation
yurii-litvinov
left a comment
There was a problem hiding this comment.
Архитектурно всё правильно (почти), но код сыроват
| } | ||
|
|
||
| [TestCase] | ||
| public void TestSubstraction() |
There was a problem hiding this comment.
| public void TestSubstraction() | |
| public void TestSubtraction() |
| } | ||
|
|
||
| [TestCase] | ||
| public void TestMultiplacation() |
There was a problem hiding this comment.
| public void TestMultiplacation() | |
| public void TestMultiplication() |
| Assert.AreEqual(1, tree.Calculate()); | ||
| } | ||
|
|
||
| [TestCase] |
There was a problem hiding this comment.
Что-то с отступом не то
|
|
||
| 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.
А разве Addition не знает, какой у него sign? :)
| Console.Write(Sign); | ||
| RightChild.Print(); | ||
| Console.Write(")"); | ||
| } |
There was a problem hiding this comment.
Надо перевод строки :)
| private INode root; | ||
|
|
||
| /// <summary> | ||
| /// Функция потсроения дерева разбора |
There was a problem hiding this comment.
| /// Функция потсроения дерева разбора | |
| /// Функция построения дерева разбора |
| } | ||
| 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.
Ой, а тут с отступом совсем беда
hw4ParseTree/hw4ParseTree/Program.cs
Outdated
| { | ||
| var tree = new ParseTree(); | ||
| Console.WriteLine("Введите выражение -"); | ||
| var expression = Console.ReadLine(); |
There was a problem hiding this comment.
Вроде как хотелось из файла читать
yurii-litvinov
left a comment
There was a problem hiding this comment.
Тут уже однозначно стало лучше, но недостаточно лучше для того, чтобы можно было поставить полные баллы
| { | ||
| var str = "( / 3 2 )"; | ||
| tree.BuildTree(str); | ||
| Assert.AreEqual(1.5, tree.Calculate()); |
There was a problem hiding this comment.
Ой, вещественные числа нельзя сравнивать через 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.
Я бы написал, что это узел синтаксического дерева, который представляет оператор сложения, но так тоже ок :)
| /// </summary> | ||
| public class Addition : Operator | ||
| { | ||
| public override char Sign { get; } |
There was a problem hiding this comment.
| public override char Sign { get; } | |
| public override char Sign => '+'; |
И тогда в конструкторе не надо его инициализировать
| namespace Hw4ParseTree | ||
| { | ||
| /// <summary> | ||
| /// исключение для неправильных выражений6 |
There was a problem hiding this comment.
| /// исключение для неправильных выражений6 | |
| /// исключение для неправильных выражений. |
|
|
||
| namespace Hw4ParseTree | ||
| { | ||
| class Operand : INode |
There was a problem hiding this comment.
А тут и ниже комментариев всё равно нет
hw4ParseTree/hw4ParseTree/Operand.cs
Outdated
| { | ||
| class Operand : INode | ||
| { | ||
| public double Number { get; set; } |
There was a problem hiding this comment.
И я не думаю, что ему нужен сеттер (только не делайте его 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.
Это тоже можно через =>
| Console.Write(Sign); | ||
| RightChild.Print(); | ||
| Console.Write(")"); | ||
| } |
| '-' => 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.
Есть же специальное исключение для неправильных выражений
| /// </summary> | ||
| class Operand : INode | ||
| { | ||
| private double Number; |
There was a problem hiding this comment.
Поля, как известно, именуются со строчной. Если Вам сложно запомнить такие мелочи, используйте StyleCop.
No description provided.