-
Notifications
You must be signed in to change notification settings - Fork 57
Шагов Владислав #53
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
ShagovVladislav
wants to merge
5
commits into
kontur-courses:master
Choose a base branch
from
ShagovVladislav: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
Шагов Владислав #53
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
51f3817
Add solution of 1 homework
ShagovVladislav fd8905c
Add solution of 2 homework task
ShagovVladislav d6cb8ad
Change CheckCurrentTsar() for older parents
ShagovVladislav 1885afe
Change exception message for invalid scale
ShagovVladislav 809428d
Change structure and other mistakes
ShagovVladislav 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
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
211 changes: 190 additions & 21 deletions
211
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,200 @@ | ||
| | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Legacy; | ||
|
|
||
| namespace HomeExercise.Tasks.NumberValidator; | ||
|
|
||
| [TestFixture] | ||
| public class NumberValidatorTests | ||
| { | ||
| private const string PrecisionExceptionMessage = "precision must be a positive number"; | ||
| private const string ScaleExceptionMessage = "scale must be a non-negative number less than precision"; | ||
|
|
||
| [Test] | ||
| public void Test() | ||
| { | ||
| 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")); | ||
| [TestCase(-1)] | ||
| [TestCase(0)] | ||
| public void Should_ThrowException_WhenNotPositivePrecision(int precision) | ||
| { | ||
|
|
||
| var action = () => new NumberValidator(precision, 2, true); | ||
|
|
||
| action.Should().Throw<ArgumentException>() | ||
| .WithMessage(PrecisionExceptionMessage); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(1, 2)] | ||
| [TestCase(1, 1)] | ||
| public void Should_ThrowException_WhenPositivePrecisionLessOrEqualScale(int precision, int scale) | ||
| { | ||
|
|
||
| var action = () => new NumberValidator(precision, scale, true); | ||
|
|
||
| action.Should().Throw<ArgumentException>() | ||
| .WithMessage(ScaleExceptionMessage); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Should_ThrowException_WhenNegativeScale() | ||
| { | ||
| var action = () => new NumberValidator(1, -1, true); | ||
|
|
||
| action.Should().Throw<ArgumentException>() | ||
| .WithMessage(ScaleExceptionMessage); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(1, 0, true)] | ||
| [TestCase(5, 2, false)] | ||
| [TestCase(4, 3, true)] | ||
| public void ShouldNot_ThrowException_WhenValidParameters(int precision, int scale, bool onlyPositive) | ||
| { | ||
| var action = () => new NumberValidator(precision, scale, onlyPositive); | ||
|
|
||
| action.Should().NotThrow(); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(4, 2, true, "12.34")] | ||
| [TestCase(4, 3, true, "+2.34")] | ||
| [TestCase(4, 3, true, "1.345")] | ||
| public void Should_BeTrue_WhenValidNumber(int precision, int scale, bool onlyPositive, string testNumber) | ||
| { | ||
| var testNum = new NumberValidator(4, 2, true); | ||
|
|
||
| var res = testNum.IsValidNumber("12.34"); | ||
|
|
||
| res.Should().BeTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Should_BeFalse_WhenNegativeNumberWithOnlyPositiveTrue() | ||
| { | ||
| var testNum = new NumberValidator(4, 2, true); | ||
|
|
||
| var res = testNum.IsValidNumber("-2.34"); | ||
|
|
||
| res.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Should_BeTrue_WhenNegativeNumberWithOnlyPositiveFalse() | ||
| { | ||
| var testNum = new NumberValidator(4, 2, false); | ||
|
|
||
| var res = testNum.IsValidNumber("-2.34"); | ||
|
|
||
| res.Should().BeTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(4, 2, true, "512.34")] | ||
| [TestCase(4, 3, true, "12.345")] | ||
| public void Should_BeFalse_WhenNumberLongerThanPrecision(int precision, int scale, bool onlyPositive, string testNumber) | ||
| { | ||
| var testNum = new NumberValidator(precision, scale, onlyPositive); | ||
|
|
||
| var res = testNum.IsValidNumber(testNumber); | ||
|
|
||
| res.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Should_BeFalse_WhenNumberWithFracLongerThanScaleButValidPrecision() | ||
| { | ||
| var testNum = new NumberValidator(5, 2, true); | ||
|
|
||
| var res = testNum.IsValidNumber("12.345"); | ||
|
|
||
| res.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Should_BeFalse_WhenString() | ||
| { | ||
| var testNum = new NumberValidator(4, 2, true); | ||
|
|
||
| var res = testNum.IsValidNumber("ab.cd"); | ||
|
|
||
| res.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Should_BeTrue_WhenInt() | ||
| { | ||
| var testNum = new NumberValidator(4, 2, true); | ||
|
|
||
| var res = testNum.IsValidNumber("52"); | ||
|
|
||
| res.Should().BeTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("")] | ||
| [TestCase(null)] | ||
| public void Should_BeFalse_WhenNullOrEmpty(string testNumber) | ||
| { | ||
| var testNum = new NumberValidator(4, 2, true); | ||
|
|
||
| var res = testNum.IsValidNumber(testNumber); | ||
|
|
||
| res.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("12.43")] | ||
| [TestCase("12,43")] | ||
| public void Should_BeTrue_WhenDifferentSeparator(string testNumber) | ||
| { | ||
| var testNum = new NumberValidator(4, 2, true); | ||
|
|
||
| var res = testNum.IsValidNumber(testNumber); | ||
|
|
||
| res.Should().BeTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Should_BeFalse_WhenNumberWithinInt() | ||
| { | ||
| var testNum1 = new NumberValidator(4, 2, true).IsValidNumber(".5"); | ||
| var testNum2 = new NumberValidator(4, 2, true).IsValidNumber(",5"); | ||
|
|
||
| testNum1.Should().BeFalse(); | ||
| testNum2.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("1.")] | ||
| [TestCase("1,")] | ||
| public void Should_BeFalse_WhenNumberWithSeparatorButWithinFrac(string testNumber) | ||
| { | ||
| var testNum = new NumberValidator(4, 2, true); | ||
|
|
||
| var res = testNum.IsValidNumber(testNumber); | ||
|
|
||
| res.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("1.2.3")] | ||
| [TestCase("1,,3")] | ||
| public void Should_BeFalse_WhenIncorrectNum(string testNumber) | ||
| { | ||
| var testNum = new NumberValidator(4, 2, true); | ||
|
|
||
| var res = testNum.IsValidNumber(testNumber); | ||
|
|
||
| res.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase(" 12")] | ||
| [TestCase("12 ")] | ||
| [TestCase("1 2")] | ||
| public void Should_BeFalse_WhenNumWithWhitespaces(string testNumber) | ||
| { | ||
| var testNum = new NumberValidator(4, 2, true); | ||
| var res = testNum.IsValidNumber(testNumber); | ||
| res.Should().BeFalse(); | ||
|
|
||
| } | ||
| } |
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.
using NUnit.Framework.Legacy;не используется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.
если убрать - альтернативное решение не сможет использовать ClassicAssert
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.
Не в том классе пометил - это к
NumberValidatorTests.csотносилось, сорри.