-
Notifications
You must be signed in to change notification settings - Fork 57
Якшибаев Данил #47
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
gogy4
wants to merge
3
commits into
kontur-courses:master
Choose a base branch
from
gogy4: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
Якшибаев Данил #47
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
168 changes: 147 additions & 21 deletions
168
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,157 @@ | ||
| | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Legacy; | ||
| using System.Collections; | ||
|
|
||
| namespace HomeExercise.Tasks.NumberValidator; | ||
|
|
||
| [TestFixture] | ||
| public class NumberValidatorTests | ||
| { | ||
| [Test] | ||
| public void Test() | ||
| #region Конструктор | ||
|
|
||
| [Test, TestCaseSource(nameof(InvalidArguments_NegativeOrScaleTooBig))] | ||
| public void Constructor_ShouldThrow_WhenArgumentsAreNegativeOrScaleAtLeastPrecision(int precision, int scale, | ||
| string expectedMessage) | ||
| { | ||
| var act = () => new NumberValidator(precision, scale); | ||
| act | ||
| .Should() | ||
| .Throw<ArgumentException>($"{expectedMessage}. " | ||
| + $"Параметры: precision={precision}, scale={scale}"); | ||
| } | ||
|
|
||
| [TestCase(1, 0, true)] | ||
| [TestCase(10, 5, false)] | ||
| public void Constructor_DoesNotThrow_WhenPrecisionScaleAndOnlyPositiveAreValid(int precision, int scale, | ||
| bool onlyPositive) | ||
| { | ||
| var act = () => new NumberValidator(precision, scale, onlyPositive); | ||
| act | ||
| .Should() | ||
| .NotThrow($"precision={precision}, scale={scale}, onlyPositive={onlyPositive} допустимы"); | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| #region Валидация чисел | ||
|
|
||
| [TestCaseSource(nameof(ValidNumbers))] | ||
| public void IsValidNumber_ShouldReturnTrue_ForValidNumbers(int precision, int scale, bool onlyPositive, | ||
| string input, string expectedMessage) | ||
| { | ||
| var validator = new NumberValidator(precision, scale, onlyPositive); | ||
| validator | ||
| .IsValidNumber(input) | ||
| .Should() | ||
| .BeTrue($"{input}. {expectedMessage}. " + $"Параметры: precision={precision}, scale={scale}, " + | ||
| $"onlyPositive={onlyPositive}"); | ||
| } | ||
|
|
||
| [TestCaseSource(nameof(InvalidNumbers))] | ||
| public void IsValidNumber_ShouldReturnFalse_ForInvalidNumbers(int precision, int scale, bool onlyPositive, | ||
| string input, string expectedMessage) | ||
| { | ||
| 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 validator = new NumberValidator(precision, scale, onlyPositive); | ||
| validator | ||
| .IsValidNumber(input) | ||
| .Should() | ||
| .BeFalse($"{input}. {expectedMessage}. " + $"Параметры: precision={precision}, scale={scale}, " + | ||
| $"onlyPositive={onlyPositive}"); | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| private static IEnumerable<TestCaseData> InvalidNumbers() | ||
| { | ||
| yield return new TestCaseData(3, 2, true, "+0.00", "число превышает допустимое количество знаков") | ||
| .SetName("InvalidNumber_TooManyDigits_PositiveZero"); | ||
|
|
||
| yield return new TestCaseData(7, 2, true, "-1.231", | ||
| "число превышает допустимое количество знаков после запятой") | ||
| .SetName("InvalidNumber_TooManyDecimals_Negative"); | ||
|
|
||
| yield return new TestCaseData(3, 2, true, "a.sd", "содержит недопустимые символы") | ||
| .SetName("InvalidNumber_InvalidCharacters"); | ||
|
|
||
| yield return new TestCaseData(3, 2, true, "", "пустая строка") | ||
| .SetName("InvalidNumber_EmptyString"); | ||
|
|
||
| yield return new TestCaseData(3, 2, true, " ", "строка содержит только пробел") | ||
| .SetName("InvalidNumber_WhitespaceOnly"); | ||
|
|
||
| yield return new TestCaseData(3, 2, true, "+", "строка содержит только знак без числа") | ||
| .SetName("InvalidNumber_SignOnlyPlus"); | ||
|
|
||
| yield return new TestCaseData(3, 2, true, "-", "строка содержит только знак без числа") | ||
| .SetName("InvalidNumber_SignOnlyMinus"); | ||
|
|
||
| yield return new TestCaseData(2, 0, true, "211", "число превышает допустимую длину целой части") | ||
| .SetName("InvalidNumber_IntegerTooLong"); | ||
|
|
||
| yield return new TestCaseData(3, 0, true, "0.1", "число превышает допустимую длину дробной части") | ||
| .SetName("InvalidNumber_ScaleTooLong"); | ||
|
|
||
| yield return new TestCaseData(17, 2, true, "0.000", "число превышает допустимую длину дробной части") | ||
| .SetName("InvalidNumber_ScaleTooLong2"); | ||
|
|
||
| yield return new TestCaseData(3, 0, true, "0.-12", "недопустимый знак внутри числа") | ||
| .SetName("InvalidNumber_InternalSignMinus"); | ||
|
|
||
| yield return new TestCaseData(3, 0, true, "0.+12", "недопустимый знак внутри числа") | ||
| .SetName("InvalidNumber_InternalSignPlus"); | ||
|
|
||
| yield return new TestCaseData(3, 0, true, "0.12.12", "число содержит несколько разделителей") | ||
| .SetName("InvalidNumber_MultipleSeparators"); | ||
|
|
||
| yield return new TestCaseData(3, 0, true, "0.,12.12", "число содержит несколько разделителей") | ||
| .SetName("InvalidNumber_MixedSeparators1"); | ||
|
|
||
| yield return new TestCaseData(3, 0, true, "0.2,12", "число содержит несколько разделителей") | ||
| .SetName("InvalidNumber_MixedSeparators2"); | ||
|
|
||
| yield return new TestCaseData(3, 0, true, "0,2.12", "число содержит несколько разделителей") | ||
| .SetName("InvalidNumber_MixedSeparators3"); | ||
|
|
||
| yield return new TestCaseData(3, 2, true, null, "значение null недопустимо") | ||
| .SetName("InvalidNumber_NullValue"); | ||
| } | ||
|
|
||
|
|
||
| private static IEnumerable<TestCaseData> ValidNumbers() | ||
| { | ||
| yield return new TestCaseData( | ||
| 17, 2, true, "0.0", | ||
| "целая часть + дробная часть ≤ precision, дробная часть ≤ scale, число положительное" | ||
| ).SetName("ValidNumber_ZeroPointZero"); | ||
|
|
||
| yield return new TestCaseData( | ||
| 4, 2, true, "+1.23", | ||
| "целая часть + дробная часть ≤ precision, дробная часть ≤ scale, число положительное" | ||
| ).SetName("ValidNumber_PositiveWithTwoDecimals"); | ||
|
|
||
| yield return new TestCaseData( | ||
| 4, 2, false, "-1.23", | ||
| "целая часть + дробная часть ≤ precision, дробная часть ≤ scale, отрицательные числа разрешены" | ||
| ).SetName("ValidNumber_NegativeWithTwoDecimals"); | ||
|
|
||
| yield return new TestCaseData( | ||
| 5, 0, true, "12345", | ||
| "целая часть + дробная часть ≤ precision, дробная часть ≤ scale, число положительное" | ||
| ).SetName("ValidNumber_Integer"); | ||
| } | ||
|
|
||
| private static IEnumerable<TestCaseData> InvalidArguments_NegativeOrScaleTooBig() | ||
| { | ||
| yield return new TestCaseData(-1, 2, "отрицательный precision недопустим") | ||
| .SetName("Constructor_Invalid_NegativePrecision"); | ||
|
|
||
| yield return new TestCaseData(1, -1, "отрицательный scale недопустим") | ||
| .SetName("Constructor_Invalid_NegativeScale"); | ||
|
|
||
| yield return new TestCaseData(3, 3, "scale должен быть меньше чем precision") | ||
| .SetName("Constructor_Invalid_ScaleEqualsPrecision"); | ||
|
|
||
| yield return new TestCaseData(3, 4, "scale должен быть меньше чем precision") | ||
| .SetName("Constructor_Invalid_ScaleGreaterThanPrecision"); | ||
| } | ||
| } |
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.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Вопрос хороший)
По хорошему нужно было разбить на 2 коммита, но подумал, что нужно одним коммитов, т.к. одна домашка
А так понял, в будущем буду разделять по коммитам
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.
Каждый коммит отражает логически завершённый шаг, проще понять как развивалось решение, что и как менялось.
Легче делать код ревью по каждому коммиту.
Иногда сложно заранее разбить на разные коммиты
Иногда бесмыссленно для мелких задач.
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.
Да, в целом верно
Еще разбивка по коммитам дает тебе возможность удобно откатывать изменения, если они были ошибочны
Помимо этого легче подтягивать изменения в другие ветки через чери-пики и пр.
В общем, преимуществ много, но они не всегда нужны, ты прав
Советую попроходить игру . Там показывается и рассказывается все, что нужно для работы с гитом, думаю будет полезно, если раньше не проходил ее