-
Notifications
You must be signed in to change notification settings - Fork 57
Зубков Артём ДЗ №1 #55
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
Open
artem7841
wants to merge
14
commits into
kontur-courses:master
Choose a base branch
from
artem7841:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bd903db
homework done
artem7841 788579a
исправлен тест CheckCurrentTsarFluentAssertions для вложенных Parent
artem7841 0d22773
удалены старые тесты
artem7841 47dae77
тесты переименованы на английский, и исправлены в соответсвии с презе…
artem7841 81a3eeb
удалены лишнее комменты, тесты сгруппированны
artem7841 f4ce550
добавлены TestCase, все тесты переписаны на FluentAssertions
artem7841 3df44ce
удален дублирующий тест для конструктора
artem7841 b939226
удален второй тест на превышение preсision
artem7841 f67c7f2
тест для режима OnlyPositive разделен на 2
artem7841 5611bcb
добавлен тест на запятую
artem7841 7a696cb
Удаление лишних файлов из репозитория
artem7841 7c94a52
Удаление sln.DotSettings.user из репозитория
artem7841 28c71cb
правки в ObjectComparison
artem7841 6996e46
правки в NumberValidatorTests
artem7841 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| bin/ | ||
| obj/ | ||
| .vs/ | ||
| .idea/ | ||
| *.sln.DotSettings.user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 70 additions & 19 deletions
89
Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,82 @@ | ||
| | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Legacy; | ||
| using FluentAssertions; | ||
|
|
||
| namespace HomeExercise.Tasks.NumberValidator; | ||
|
|
||
|
|
||
| [TestFixture] | ||
| public class NumberValidatorTests | ||
| { | ||
| [Test] | ||
| public void Test() | ||
| [TestCase(-1, 2, "Исключение, когда precision отрицательная")] | ||
| [TestCase(5, -1, "Исключение, когда scale отрицательный")] | ||
| [TestCase(5, 6, "Исключение, когда scale больше precision")] | ||
| public void Constructor_WithInvalidParameters_ThrowsArgumentException(int precision, int scale, string description) | ||
| { | ||
| Action action = () => new NumberValidator(precision, scale); | ||
|
|
||
| action.Should().Throw<ArgumentException>(description); | ||
| } | ||
|
|
||
|
|
||
| [TestCase("0", "Целый ноль")] | ||
| [TestCase("0.0", "Десятичный ноль")] | ||
| [TestCase("123.45", "Корректное десятичное")] | ||
| [TestCase("+1.23", "С явным плюсом")] | ||
| public void IsValidNumber_WithValidNumberFormats_ReturnsTrue(string number, string description) | ||
| { | ||
| var validator = new NumberValidator(5, 2, true); | ||
|
|
||
| validator.IsValidNumber(number).Should().BeTrue(description); | ||
| } | ||
|
|
||
| [TestCase("-1.23", "Отрицательное при onlyPositive=true")] | ||
| [TestCase("00.000", "Превышение precision в дробной части")] | ||
| [TestCase("1234.56", "Превышение precision в целой части")] | ||
| [TestCase("0.000", "Превышение scale")] | ||
| [TestCase("a.sd", "Нечисловой формат")] | ||
| [TestCase("", "Пустая строка")] | ||
| [TestCase(null, "Null")] | ||
| public void IsValidNumber_WithInvalidNumberFormats_ReturnsFalse(string number, string description) | ||
| { | ||
| var validator = new NumberValidator(5, 2, true); | ||
|
|
||
| validator.IsValidNumber(number).Should().BeFalse(description); | ||
| } | ||
|
|
||
| [TestCase("1.23", "Максимальная precision и scale")] | ||
| [TestCase("12.3", "Граница precision")] | ||
| [TestCase("0.12", "Граница scale")] | ||
| [TestCase("1,23", "Запятая в качестве разделителя")] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Этот тест с запятой все таки должен лежать в группе |
||
| public void IsValidNumber_WithValidPrecisionAndScale_ReturnsTrue(string number, string description) | ||
| { | ||
| var strictValidator = new NumberValidator(3, 2); | ||
|
|
||
| strictValidator.IsValidNumber(number).Should().BeTrue(description); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| [TestCase("-1.23", "Отрицательное число")] | ||
| [TestCase("-0", "Отрицательный ноль")] | ||
| public void IsValidNumber_WithOnlyPositiveFalse_AcceptsNegativeNumbers(string number, string description) | ||
| { | ||
| Assert.Throws<ArgumentException>(() => new NumberValidator(-1, 2, true)); | ||
| Assert.DoesNotThrow(() => new NumberValidator(1, 0, true)); | ||
| Assert.Throws<ArgumentException>(() => new NumberValidator(-1, 2, false)); | ||
| Assert.DoesNotThrow(() => new NumberValidator(1, 0, true)); | ||
|
|
||
| ClassicAssert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0.0")); | ||
| ClassicAssert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0")); | ||
| ClassicAssert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0.0")); | ||
| ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("00.00")); | ||
| ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("-0.00")); | ||
| ClassicAssert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0.0")); | ||
| ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("+0.00")); | ||
| ClassicAssert.IsTrue(new NumberValidator(4, 2, true).IsValidNumber("+1.23")); | ||
| ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("+1.23")); | ||
| ClassicAssert.IsFalse(new NumberValidator(17, 2, true).IsValidNumber("0.000")); | ||
| ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("-1.23")); | ||
| ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd")); | ||
| var anyNum = new NumberValidator(5, 2, false); | ||
|
|
||
| anyNum.IsValidNumber(number).Should().BeTrue(description); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| [TestCase("12..34", "Две точки")] | ||
| [TestCase(".123", "Начинается с точки")] | ||
| [TestCase("123.", "Оканчивается точкой")] | ||
| public void IsValidNumber_WithInvalidFormats_ReturnsFalse(string number, string description) | ||
| { | ||
| var validator = new NumberValidator(10, 2); | ||
|
|
||
| validator.IsValidNumber(number).Should().BeFalse(description); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Тут все верно, но у кастмного решения есть еще проблема с рекурсией, там она потенциально бесконечная. У FluentAssertions есть ограничение по глубине рекурсии