-
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
Брозовский Максим #12
Open
BMV989
wants to merge
16
commits into
kontur-courses:master
Choose a base branch
from
BMV989:hw
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
16 commits
Select commit
Hold shift + click to select a range
1c6f559
Homework is done
BMV989 e0e6f80
Refactor: NumberValidatorTests
BMV989 232b0cb
Remove duplicate tests
BMV989 3440c65
small change in one test
BMV989 bb6c13c
dealing with exclude all persons' ids
BMV989 d942723
another refactoring of NumberValidatorTests
BMV989 f85a528
small mistake in case's TestName
BMV989 0b113c5
small refactoring of NumberValidatorTests
BMV989 ff9fdc5
another small mistake in one of testcases
BMV989 46d831d
Fixing testcases' naming
BMV989 cdf2d70
small mistake in testcase
BMV989 ef2b03f
another pack of mistakes have been fixed
BMV989 4f1f011
add some remark in one of the tests
BMV989 537ba36
yet another pack of mistakes
BMV989 8f4d1f4
small mistake
BMV989 4d634a9
still some mistakes
BMV989 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 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
112 changes: 92 additions & 20 deletions
112
Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,103 @@ | ||
| ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
using FluentAssertions; | ||
|
||
namespace HomeExercise.Tasks.NumberValidator; | ||
|
||
[TestFixture] | ||
public class NumberValidatorTests | ||
{ | ||
[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)); | ||
private const string PrecisionErrorMessage = "precision must be a positive number"; | ||
private const string ScaleErrorMessage = "precision must be a non-negative number less or equal than precision"; | ||
|
||
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, 0, PrecisionErrorMessage, TestName = "precision < 0")] | ||
[TestCase(-10, 1, PrecisionErrorMessage, TestName = "precision < 0")] | ||
[TestCase(0, 0, PrecisionErrorMessage, TestName = "precision == 0")] | ||
[TestCase(0, 2, PrecisionErrorMessage, TestName = "precision == 0")] | ||
[TestCase(5, -1, ScaleErrorMessage, TestName = "scale < 0")] | ||
[TestCase(5, -6, ScaleErrorMessage, TestName = "scale < 0")] | ||
[TestCase(1, 2, ScaleErrorMessage, TestName = "scale > precision")] | ||
[TestCase(1, 10, ScaleErrorMessage, TestName = "scale > precision")] | ||
[TestCase(1, 1, ScaleErrorMessage, TestName = "scale == precision")] | ||
[TestCase(2, 2, ScaleErrorMessage, TestName = "scale == precision")] | ||
public void NumberValidator_ThrowsArgumentException_WithInvalidParams(int precision, int scale, string msg) | ||
{ | ||
Action act = () => new NumberValidator(precision, scale); | ||
act.Should().Throw<ArgumentException>().WithMessage(msg); | ||
} | ||
|
||
[TestCase("2", 1, 0, true, TestName = "When value is one digit integer")] | ||
[TestCase("52", 2, 1, true, TestName = "When value is two digit integer")] | ||
[TestCase("-300", 4, 0, false, TestName = "When value is integer with negative sign")] | ||
[TestCase("+300", 4, 0, true, TestName = "When value is integer with positive sign")] | ||
[TestCase("-99", 3, 2, false, TestName = "When value is integer with negative sign and non zero scale")] | ||
[TestCase("9999999", 7, 1, false, TestName = "When value is integer and has 7 digits and non zero scale")] | ||
[TestCase("2147483649", 10, 1, false, TestName = "When value is Int overflow")] | ||
[TestCase("-1234567890", 11, 8, false, TestName = "When value is integer with negative sign 10 digits and non zero scale")] | ||
[TestCase("0101010", 20, 12, false, TestName = "When value with leading zero")] | ||
[TestCase("01110.01010", 10, 5, true, TestName = "When value is fraction with leading zero in integer part and leading zero in fraction part and separator is dot")] | ||
[TestCase("01110,01010", 10, 5, true, TestName = "When value is fraction with leading zero in integer part and leading zero in fraction part and separator is comma")] | ||
[TestCase("+01110,01010", 11, 5, true, TestName = "When value is fraction with leading zero in integer part and leading zero in fraction part and separator is comma with positive sign")] | ||
[TestCase("-1234567890.1234567890", 21, 10, false, TestName = "When value is fraction with negative sign")] | ||
[TestCase("+0.0", 3, 1, false, TestName = "When value is zero with zero fraction with sign and separator is dot")] | ||
[TestCase("0.000", 4, 3, true, TestName = "When value is zero with zero fraction and separator is dot")] | ||
[TestCase("300.52", 5, 2, true, TestName = "When value is fraction and separator is dot")] | ||
[TestCase("+3.52", 15, 10, false, TestName = "When value is fraction with sign and separator is dot")] | ||
[TestCase("+300,52", 17, 10, false, TestName = "When value is fraction and has sign and separator is comma")] | ||
[TestCase("1,23", 17, 10, false, TestName = "When value is fraction and separator is comma")] | ||
[TestCase("+100", 4, 1, true, TestName = "When value is integer with sign")] | ||
[TestCase("100\n", 4, 2, true, TestName = "When \n at the end of a value")] | ||
public void IsValidNumber_ShouldBeTrue_WithValidParams(string value, int precision, int scale, bool onlyPositive) => | ||
new NumberValidator(precision, scale, onlyPositive) | ||
.IsValidNumber(value) | ||
.Should().BeTrue(); | ||
|
||
[TestCase("", 17, 10, false, TestName = "When value is empty string")] | ||
[TestCase(null, 17, 10, false, TestName = "When value is null")] | ||
[TestCase("II", 17, 10, false, TestName = "When value is II in roman numeric system")] | ||
[TestCase("III", 17, 10, false, TestName = "When value is III in roman numeric system")] | ||
[TestCase("VI", 17, 10, false, TestName = "When value is IV in roman numeric system")] | ||
[TestCase("X", 17, 10, false, TestName = "When value is X in roman numeric system")] | ||
[TestCase("ఎనమద", 4, 0 , true, TestName = "When value is ఎనమద in telugu numeric system")] | ||
[TestCase("తమమద", 4, 0 , true, TestName = "When value is తమమద in telugu numeric system")] | ||
[TestCase("0xFF", 4, 0, true, TestName = "When value is FF and is hexadecimal number")] | ||
[TestCase("0x1A", 4, 0, true, TestName = "When value is 1A and is hexadecimal number")] | ||
[TestCase("0o75", 4, 0, true, TestName = "When value is 75 and is octal number")] | ||
[TestCase("0o44", 4, 0, true, TestName = "When value is 44 and is octal number")] | ||
[TestCase("0b1010", 6, 0, true, TestName = "When value is 1010 and is binary number")] | ||
[TestCase("0b01110.01010", 10, 5, true, TestName = "When value is binary number with fraction")] | ||
[TestCase("seven.eleven", 17, 10, false, TestName = "When value is two english words separated by dot")] | ||
[TestCase("five/two", 17, 10, false, TestName = "When value is two english words separated by /")] | ||
[TestCase("11.11.11", 17, 10, false, TestName = "When value has two dots")] | ||
[TestCase("+127.000.001", 17, 10, false, TestName = "When value has two dots and sign")] | ||
[TestCase("11.22,33", 17, 10, false, TestName = "When value has one dot and one comma")] | ||
[TestCase("55,22,33", 17, 10, false, TestName = "When value has two commas")] | ||
[TestCase("+1\\2", 17, 10, false, TestName = "When value has sign and \\ separator")] | ||
[TestCase("X,Y", 3, 2, true, TestName = "When value is two capital letters with comma separator")] | ||
[TestCase("a.sd", 17, 10, false, TestName = "When value have letters with dot separator")] | ||
[TestCase("1\n.5", 3, 2, true, TestName = "When \n in the middle of a value")] | ||
[TestCase("\n2.4", 3, 2, true, TestName = "When \n is in front of a value")] | ||
[TestCase("+-15", 3, 2, false, TestName = "When value has two different signs")] | ||
[TestCase("--10", 4, 2, false, TestName = "When value has two negative signs")] | ||
[TestCase("++1", 3, 0, true, TestName = "When value has two positive signs")] | ||
[TestCase("300_000", 17, 10, false, TestName = "When value has underscore separator")] | ||
[TestCase("52 000", 17, 10, false, TestName = "When value has space separator")] | ||
[TestCase("1/2", 17, 10, false, TestName = "When value has / separator")] | ||
[TestCase("12 . 22", 17, 10, false, TestName = "When value has `space dot space` separator")] | ||
[TestCase("12 , 22", 17, 10, false, TestName = "When value has `space comma space` separator")] | ||
[TestCase("-100", 4, 0, true, TestName = "When value is negative and onlyPositive is true")] | ||
[TestCase("+1,23", 3, 2, true, TestName = "When value is 3 digit fraction with sign and precision is 3 (Not 4)")] | ||
[TestCase("1.123", 4, 2, true, TestName = "When value is fraction with 3 digit in fraction part and scale is 2 (Not 3)")] | ||
[TestCase("0.00", 5, 1, true, TestName = "When value is fraction with 2 digit in fraction part and scale is 1 (Not 2)")] | ||
[TestCase("52", 1, 0, true, TestName = "When value is 2 digit integer and precision is 1 (Not 2)")] | ||
[TestCase("-300", 3, 0, false, TestName = "When value is 3 digit integer with negative sign and precision is 3 (Not 4)")] | ||
[TestCase("300", 2, 0, false, TestName = "When value is 3 digit integer and precision is 2 (Not 3)")] | ||
[TestCase("+100", 3, 0, false, TestName = "When value is 3 digit integer with positive sign and precision is 3 (Not 4)")] | ||
[TestCase("-1.23", 3, 2, false, TestName = "When value is 3 digit fraction with negative sign and precision is 3 (Not 4)")] | ||
[TestCase("-1234567890.1234567890", 20, 10, false, TestName = "When value is 20 digit fraction with negative sign and precision is 20 (Not 21)")] | ||
public void IsValidNumber_ShouldBeFalse_WithInvalidParams(string value, int precision, int scale, | ||
bool onlyPositive) => | ||
new NumberValidator(precision, scale, onlyPositive) | ||
.IsValidNumber(value) | ||
.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.
Рассмотри еще кейс, когда у царя поле parent будет указывать на уже встречающегося царя в родословной. Нам же ничего не мешает так сделать :)
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.
Случай несколько вырожден, но формально возможен.
В таком случае возникнет бесконечная рекурсия.
Рассмотрим простой случай: есть actualTsar и пусть actualTsar.Parent.Parent = actualTsar.
Тогда при сравнении AreEqual(actualTsar, actualTsar) мы будем сравнивать их Parent, но у них тоже есть Parent, а значит их мы тоже будем сравнивать и т. д.
Таким образом мы получим бесконечную последовательность вызовов AreEqual для каждого Parent.
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.
Окей согласен