-
Notifications
You must be signed in to change notification settings - Fork 0
Hw2 calculator #3
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.
По существу всё правильно, но уж очень неаккуратно
| if ((!isCorrect1 || !isCorrect2) || (result1 != mainResult || result2 != mainResult)) | ||
| { | ||
| return false; | ||
| } | ||
| return true; |
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.
Какой ужас :) Просто return то, что написано в if
|
|
||
| private bool CheckFalseExpression(bool isCorrect1, bool isCorrect2) | ||
| { | ||
| return (!isCorrect1 && !isCorrect2); |
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.
Тут, кстати, скобки лишние :)
| return (!isCorrect1 && !isCorrect2); | ||
| } | ||
|
|
||
| [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.
На самом деле, просто Test, TestCase --- это если бы Вы параметры в метод передавали
| { | ||
| private bool CheckTrueExpression(bool isCorrect1, bool isCorrect2, double result1, double result2, double mainResult) | ||
| { | ||
| if ((!isCorrect1 || !isCorrect2) || (result1 != mainResult || result2 != mainResult)) |
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.
Оо, кто-то всё-таки сравнивает double-ы через !=. Это не совсем == и сравнение с нулём, но уровень непонимания представления вещественных чисел такой же :) См. https://0.30000000000000004.com/
| IStack stack2 = new StackArray(); | ||
| stack1.Push(9); | ||
| stack2.Push(8); | ||
| Assert.IsTrue((stack1.Pop() == 9 && stack2.Pop() == 8)); |
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. Тут, если тест не пройдёт, Вам скажут "ну, тест не прошёл", а если сделать правильно, то напишут, что конкретно чему не равно, что упростит отладку
| private static bool IsOperand(char symbol) | ||
| { | ||
| return symbol == '+' || symbol == '-' || symbol == '*' || symbol == '/'; | ||
| } |
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.
Не поправлено
| @@ -0,0 +1,60 @@ | |||
| using NUnit.Framework; | |||
|
|
|||
| namespace hw2Calculator.Test | |||
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.
Пространства имён в .NET именуются с заглваной всегда
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 bool IsEmpty() | ||
| { | ||
| return countNumbersInStack == 0; | ||
| } |
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.
Тоже лучше через =>
| return countNumbersInStack == 0; | ||
| } | ||
|
|
||
| public void DeleteStack() |
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.
Скорее, ClearStack, чтобы не смущать C++-ников и вообще. Мы же стек не удаляем, мы просто выкидываем все его элементы и возвращаем его в начальное состояние
Co-authored-by: Yurii Litvinov <yurii.litvinov@gmail.com>
| IStack stack1 = new StackList(); | ||
| IStack stack2 = new StackArray(); | ||
| (var result1, var isCorrect1) = Calculator.CalculatorExpression(expresion, stack1); | ||
| (var result2, var isCorrect2) = Calculator.CalculatorExpression(expresion, stack2); |
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.
Условие "при этом не содержать дублирующегося кода" не выполнено. Посмотрите https://docs.nunit.org/articles/nunit/writing-tests/attributes/testcasesource.html и https://docs.nunit.org/articles/nunit/writing-tests/attributes/testcase.html
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.
Надо ещё немного поправить
| @@ -0,0 +1,60 @@ | |||
| using NUnit.Framework; | |||
|
|
|||
| namespace hw2Calculator.Test | |||
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 bool CheckFalseExpression(bool isCorrect1, bool isCorrect2) | ||
| { | ||
| return (!isCorrect1 && !isCorrect2); |
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 bool CheckTrueExpression(bool isCorrect1, bool isCorrect2, double result1, double result2, double mainResult) | ||
| { | ||
| return (!isCorrect1 || !isCorrect2) || (result1 - mainResult < 0.000001 || result2 - mainResult < 0.000001); |
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.
Ой, математика говорит, что если mainResult достаточно большой, эта штука его одобрит
| return (0, false); | ||
| } | ||
|
|
||
| private static bool IsOperand(char symbol) |
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.
Скорее IsOperator
| private static bool IsOperand(char symbol) | ||
| { | ||
| return symbol == '+' || symbol == '-' || symbol == '*' || symbol == '/'; | ||
| } |
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.
Не поправлено
| return !isCorrect || Math.Abs(result - mainResult) < 0.000001; | ||
| } | ||
|
|
||
| private static (string Test, double Result)[] CorrectDataForTests = new[] |
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 TestCaseData(new StackArray(), DataForTests.Test, DataForTests.Result) | ||
| }); | ||
|
|
||
| private static string[] UncorrectDataForTests = new[] |
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.
"IncorrectDataForTests"
| [TestCaseSource(nameof(CorrectDataForTest))] | ||
| public void CalculatorTestForUncorrectData(IStack stack, string expresion, double mainResult) |
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.
Что-то имя источника данных в TestCaseSource противоречит имени теста
| Assert.IsTrue(CheckTrueExpression(isCorrect, result, mainResult)); | ||
| } | ||
|
|
||
| private static IEnumerable<TestCaseData> UncorrectDataForTest |
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.
Ещё, кстати, у Вас две пары полей, которые называются почти одинаково. Это плохо, это запутывает читателя. Назовите их по смыслу.
| IStack stack1; | ||
| IStack stack2; |
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
| stack1 = new StackList(); | ||
| stack2 = new StackArray(); |
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.
Тут тоже стоило data-driven-тесты использовать, потому что стеки реализуют один интерфейс и обязаны вести себя одинаково
hw2Calculator/hw2Calculator/Test.cs
Outdated
|
|
||
| namespace Hw2Calculator | ||
| { | ||
| class Test |
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.
А это теперь не надо :)
| double delete = stackElements[countNumbersInStack]; | ||
| return delete; |
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.
Но зачем? Это же просто return stackElements[countNumbersInStack];
| public bool IsEmpty() | ||
| => countNumbersInStack == 0; | ||
|
|
||
|
|
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.
Да, теперь всё хорошо, зачтена
| } | ||
|
|
||
| private static IEnumerable<TestCaseData> UncorrectDataForTest | ||
| private static IEnumerable<TestCaseData> TestIncorrectDate |
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.
Date --- в смысле "свидание"?
| private bool CheckTrueExpression(bool isCorrect, double result, double mainResult) | ||
| { | ||
| return !isCorrect || Math.Abs(result - mainResult) < 0.000001; | ||
| } |
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.
Тут лучше через =>
No description provided.