-
Notifications
You must be signed in to change notification settings - Fork 282
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
Волков Кирилл #236
Open
caimanchik
wants to merge
6
commits into
kontur-courses:master
Choose a base branch
from
caimanchik: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.
+201
−79
Open
Волков Кирилл #236
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ee66ab
switched tests in ObjectComparsion to FluentAssertions and refactored…
caimanchik 995aded
refactored tests for NumberValidator.cs
caimanchik 1cd3701
specified error message for constructor fails
caimanchik 3f84a0c
added testcase to failing constructor tests
caimanchik 36fe5aa
refactored to nameof in case of renaming the field
caimanchik 75bbb8f
added checking if the object is typeof Person
caimanchik 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
refactored tests for NumberValidator.cs
commit 995aded4cba7a1d97debc2eca184207d70f85fa7
There are no files selected for viewing
27 changes: 1 addition & 26 deletions
27
cs/HomeExercises/NumberValidatorTests.cs → cs/HomeExercises/NumberValidator.cs
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using System; | ||
using System.Collections; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace HomeExercises.Tests | ||
{ | ||
public class NumberValidator_Should | ||
{ | ||
#region ConstructorTestsSources | ||
|
||
private static IEnumerable IncorrectConstructorParamsTests() | ||
{ | ||
yield return new TestCaseData(-1, 2, true) | ||
.SetName("Constructor_ThrowsArgumentExceptionOnNegativePrecision"); | ||
yield return new TestCaseData(1, 2, true) | ||
.SetName("Constructor_ThrowsArgumentExceptionOnPrecisionLessThanScale"); | ||
yield return new TestCaseData(1, 1, true) | ||
.SetName("Constructor_ThrowsArgumentExceptionSamePrecisionAndScale"); | ||
yield return new TestCaseData(1, -1, true) | ||
.SetName("Constructor_ThrowsArgumentExceptionOnNegativeScale"); | ||
} | ||
|
||
private static IEnumerable CorrectConstructorParamsTests() | ||
{ | ||
yield return new TestCaseData(2, 1, true) | ||
.SetName("Constructor_WorksWhenPrecisionIsNonNegativeAndGreaterThanScale"); | ||
yield return new TestCaseData(2, 1, false) | ||
.SetName("Constructor_WorksWhenPrecisionIsNonNegativeAndGreaterThanScale"); | ||
} | ||
|
||
#endregion | ||
|
||
#region IsValidNumberTestsSources | ||
|
||
private static IEnumerable IsValidNumberPrecisionTests() | ||
{ | ||
yield return new TestCaseData(3, 2, true, "00.00") | ||
.SetName("IsValidNumber_ReturnsFalse_WhenSumOfIntPartAndFracPartIsGreaterThanPrecision") | ||
.Returns(false); | ||
yield return new TestCaseData(3, 2, true, "-0.00") | ||
.SetName("IsValidNumber_ReturnsFalse_WhenSignWithFracAndIntPartsIsGreaterThanPrecision") | ||
.Returns(false); | ||
yield return new TestCaseData(3, 2, true, "+0.00") | ||
.SetName("IsValidNumber_ReturnsFalse_WhenSignWithFracAndIntPartsIsGreaterThanPrecision") | ||
.Returns(false); | ||
|
||
yield return new TestCaseData(17, 2, true, "0.0") | ||
.SetName("IsValidNumber_ReturnsTrue_WhenSumOfIntPartAndFracPartIsNotGreaterThanPrecision") | ||
.Returns(true); | ||
yield return new TestCaseData(17, 2, true, "0") | ||
.SetName("IsValidNumber_ReturnsTrue_WhenIntPartIsNotGreaterThanPrecision") | ||
.Returns(true); | ||
yield return new TestCaseData(17, 2, true, "+0.0") | ||
.SetName("IsValidNumber_ReturnsTrue_WhenSumOfIntPartAndFracPartIsNotGreaterThanPrecision") | ||
.Returns(true); | ||
} | ||
|
||
private static IEnumerable IsValidNumberScaleTests() | ||
{ | ||
yield return new TestCaseData(17, 2, true, "0.111") | ||
.SetName("IsValidNumber_ReturnsFalse_WhenFracPartIsGreaterThanScale") | ||
.Returns(false); | ||
|
||
yield return new TestCaseData(17, 2, true, "0.11") | ||
.SetName("IsValidNumber_ReturnsTrue_WhenFracPartIsNotGreaterThanScale") | ||
.Returns(true); | ||
} | ||
|
||
private static IEnumerable IsValidNumberSignTests() | ||
{ | ||
yield return new TestCaseData(17, 2, true, "-0.11") | ||
.SetName("IsValidNumber_ReturnsFalse_WhenSignIsNegativeWithOnlyPositive") | ||
.Returns(false); | ||
|
||
yield return new TestCaseData(17, 2, true, "+0.11") | ||
.SetName("IsValidNumber_ReturnsTrue_WhenSignIsPositiveWithOnlyPositive") | ||
.Returns(true); | ||
yield return new TestCaseData(17, 2, false, "+0.11") | ||
.SetName("IsValidNumber_ReturnsTrue_WhenSignIsPositiveWithoutOnlyPositive") | ||
.Returns(true); | ||
yield return new TestCaseData(17, 2, false, "-0.11") | ||
.SetName("IsValidNumber_ReturnsTrue_WhenSignIsNegativeWithoutOnlyPositive") | ||
.Returns(true); | ||
} | ||
|
||
private static IEnumerable IsValidNumberValueTests() | ||
{ | ||
yield return new TestCaseData(17, 2, true, null) | ||
.SetName("IsValidNumber_ReturnsFalse_WhenNullIsGiven") | ||
.Returns(false); | ||
yield return new TestCaseData(17, 2, true, "") | ||
.SetName("IsValidNumber_ReturnsFalse_WhenEmptyStringIsGiven") | ||
.Returns(false); | ||
yield return new TestCaseData(17, 2, true, "a.a") | ||
.SetName("IsValidNumber_ReturnsFalse_WhenNonDigitStringIsGiven") | ||
.Returns(false); | ||
} | ||
|
||
#endregion | ||
|
||
[TestCaseSource(nameof(IncorrectConstructorParamsTests))] | ||
public void FailsWithIncorrectConstructorArguments(int precision, int scale, bool onlyPositive) | ||
{ | ||
new Func<NumberValidator>(() => new NumberValidator(precision, scale, onlyPositive)) | ||
.Should() | ||
.ThrowExactly<ArgumentException>(); | ||
} | ||
|
||
[TestCaseSource(nameof(CorrectConstructorParamsTests))] | ||
public void InitsWithCorrectConstructorArguments(int precision, int scale, bool onlyPositive) | ||
{ | ||
new Func<NumberValidator>(() => new NumberValidator(precision, scale, onlyPositive)) | ||
.Should() | ||
.NotThrow(); | ||
} | ||
|
||
[ | ||
TestCaseSource(nameof(IsValidNumberPrecisionTests)), | ||
TestCaseSource(nameof(IsValidNumberScaleTests)), | ||
TestCaseSource(nameof(IsValidNumberSignTests)), | ||
TestCaseSource(nameof(IsValidNumberValueTests)), | ||
] | ||
public bool IsValidNumber(int precision, int scale, bool onlyPositive, string value) | ||
{ | ||
return new Func<NumberValidator>(() => new NumberValidator(precision, scale, onlyPositive))() | ||
.IsValidNumber(value); | ||
} | ||
} | ||
} |
This file contains 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
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.
Бывают случаи когда тебе важна не факт ошибки в тесте, но и текст этой ошибки, допустим когда этот текст выводиться клиенту