-
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
Степан Заколюкин #32
base: master
Are you sure you want to change the base?
Степан Заколюкин #32
Changes from 4 commits
7930a0d
ef79dff
63aeed4
2a67289
260031f
cee3d86
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 |
---|---|---|
|
@@ -8,24 +8,74 @@ namespace HomeExercise.Tasks.NumberValidator; | |
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)); | ||
|
||
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")); | ||
public void NumberValidator_IncorrectPrecision_Exception() | ||
{ | ||
Assert.Throws<ArgumentException>(() => new NumberValidator(-1, 2, true), | ||
"precision должен быть положительным числом"); | ||
} | ||
|
||
[Test] | ||
public void NumberValidator_CorrectInitialization_NoExceptions() | ||
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. В этих тестах потеряны кейсы когда onlyPositive == false (в старом коде дублирование, ты можешь воткнуть TestCase(true) и TestCase(false)) И ещё если мы конструктор валидируем, то надо докинуть проверку scale: должен быть не меньше нуля и не больше precision 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.
у меня это проверяется в методе NumberValidator_IncorrectScale_Exception 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. А, пон, не увидел |
||
{ | ||
Assert.DoesNotThrow(() => new NumberValidator(1, 0, true), | ||
"При создании экземпляра класса не должно было возникнуть ошибок"); | ||
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. Если мы тут за fluent assertions, то есть func.Should().Throw(exception) и func.Should().NotThrow(exception) |
||
} | ||
|
||
[TestCase(1, -1)] | ||
[TestCase(1, 2)] | ||
[TestCase(1, 1)] | ||
public void NumberValidator_IncorrectScale_Exception(int precision, int scale = 0, bool onlyPositive = true) | ||
{ | ||
Assert.Throws<ArgumentException>(() => new NumberValidator(precision, scale, onlyPositive), | ||
"scale должно быть меньше precision, но больше или равно 0"); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_InvalidCharacters_False() | ||
{ | ||
ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd"), | ||
"В записи числа не должны содержаться буквы"); | ||
} | ||
|
||
[TestCase("00.00", 3, 2)] | ||
[TestCase("+1.23", 3, 2)] | ||
public void IsValidNumber_NotTheAppropriateLength_False(string value, | ||
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. Тут ещё по общим правилам нейминга должно быть типа "Should_ReturnFalse_WhenUnappropriateLength" или как-то так, но видимо вы не это проходили, так что можно не править |
||
int precision, | ||
int scale = 0, | ||
bool onlyPositive = true) | ||
{ | ||
ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value), | ||
"Длина числа не соответствует шаблону"); | ||
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.23", 4, 2)] | ||
[TestCase("0", 17, 2)] | ||
[TestCase("0.0", 17, 2)] | ||
public void IsValidNumber_CorrectValue_True(string value, int precision, int scale = 0, bool onlyPositive = true) | ||
{ | ||
ClassicAssert.IsTrue(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value)); | ||
} | ||
|
||
[TestCase("-0.00", 3, 2)] | ||
[TestCase("+0.00", 3, 2, false)] | ||
public void IsValidNumber_TheWrongSign_False(string value, int precision, int scale = 0, bool onlyPositive = true) | ||
{ | ||
ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value), | ||
"Знаки value и NumberValidator отличаются"); | ||
} | ||
|
||
[TestCase("", 1)] | ||
[TestCase(null, 1)] | ||
public void IsValidNumber_NullOrEmpty_False(string value, int precision, int scale = 0, bool onlyPositive = true) | ||
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. Тут и в IsValidNumber_CorrectValue_True стоит onlyPositive, но в кейсах не указывается |
||
{ | ||
ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value), | ||
"Проверяемое значение не должно равняться null или пустой строке"); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_InappropriateAccuracy_False() | ||
{ | ||
ClassicAssert.IsFalse(new NumberValidator(17, 2, true).IsValidNumber("0.000"), | ||
"значение не может иметь точность выше указанной в NumberValidator"); | ||
} | ||
} |
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.
проверки нужны