-
Notifications
You must be signed in to change notification settings - Fork 32
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
Рыбин Леонид #17
base: master
Are you sure you want to change the base?
Рыбин Леонид #17
Changes from 2 commits
d00183c
475de0f
6ff61fe
26c0d7d
afcbbf5
b385885
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
bin/ | ||
obj/ | ||
.vs/ | ||
Basic.sln | ||
Basic.sln.DotSettings.user | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,52 @@ | ||
| ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
|
||
namespace HomeExercise.Tasks.NumberValidator; | ||
|
||
[TestFixture] | ||
public class NumberValidatorTests | ||
{ | ||
[Test] | ||
public void Test() | ||
[TestCase(-1, 2, true, TestName = "negative precision")] | ||
[TestCase(0, 2, false, TestName = "precision == 0")] | ||
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. Всё конечно ситуативно, но лучше прям словами такие кейсы прописывать. |
||
[TestCase(1, -2, true, TestName = "negative scale")] | ||
[TestCase(1, 2, false, TestName = "scale > precision")] | ||
[TestCase(1, 1, true, TestName = "scale == precision")] | ||
public void NumberValidation_ConstructorHasArgumentException(int precision, int scale, bool onlyPositive) | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
{ | ||
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)); | ||
var action = () => new NumberValidator(precision, scale, onlyPositive); | ||
action.Should().Throw<ArgumentException>(); | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
} | ||
|
||
[TestCase(1, 0, true, TestName = "default")] | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
public void NumberValidation_ConstructorDoesNotHaveArgumentException(int precision, int scale, bool onlyPositive) | ||
{ | ||
var action = () => new NumberValidator(precision, scale, onlyPositive); | ||
action.Should().NotThrow(); | ||
} | ||
|
||
[TestCase(1, 0, true, "0",ExpectedResult = true)] | ||
[TestCase(2, 1, true, "0.0", ExpectedResult = true)] | ||
[TestCase(2, 1, true, "0.1", ExpectedResult = true)] | ||
[TestCase(2, 1, true, "0,1", ExpectedResult = true)] | ||
[TestCase(2, 0, true, "+1", ExpectedResult = true)] | ||
[TestCase(3, 1, true, "+1.1", ExpectedResult = true)] | ||
[TestCase(3, 1, true, "+1,1", ExpectedResult = true)] | ||
[TestCase(2, 0, false, "-1", ExpectedResult = true)] | ||
[TestCase(3, 1, false, "-1.1", ExpectedResult = true)] | ||
[TestCase(3, 1, false, "-1,1", ExpectedResult = true)] | ||
[TestCase(7, 2, true, "671,23", ExpectedResult = 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(2, 0, true, "", ExpectedResult = false)] | ||
[TestCase(2, 1, true, ".0", ExpectedResult = false)] | ||
[TestCase(2, 0, true, "0.", ExpectedResult = false)] | ||
[TestCase(2, 0, true, "-1", ExpectedResult = false)] | ||
[TestCase(10, 2, true, "abcde.f", ExpectedResult = false)] | ||
[TestCase(10, 9, true, "127.0.0.1", ExpectedResult = false)] | ||
[TestCase(3, 2, true, "4321.5", ExpectedResult = false)] | ||
[TestCase(3, 0, true, "+145", ExpectedResult = false)] | ||
[TestCase(3, 0, false, "-124", ExpectedResult = false)] | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
public bool IsValidNumber(int precision, int scale, bool onlyPositive, string value) | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
{ | ||
return new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value); | ||
} | ||
} |
This comment was marked as resolved.
Sorry, something went wrong.