Alexander Anronov @raccoon6996#237
Open
batyadmx wants to merge 4 commits intokontur-courses:masterfrom
Open
Conversation
69raccoon96
suggested changes
Nov 28, 2023
Comment on lines
15
to
31
| [Test] | ||
| public void NumberValidator_WithNegativePrecision_ThrowsArgumentException() | ||
| { | ||
| Assert.Throws<ArgumentException>(() => new NumberValidator(-1, 2, true)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void NumberValidator_WithNegativeScale_ThrowsArgumentException() | ||
| { | ||
| Assert.Throws<ArgumentException>(() => new NumberValidator(2, -2, true)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void NumberValidator_WithScaleGreaterThanPrecision_ThrowsArgumentException() | ||
| { | ||
| Assert.Throws<ArgumentException>(() => new NumberValidator(2, 4, true)); | ||
| } |
There was a problem hiding this comment.
Лучше использовать TestCase, кстати, каждому кейсу можно задать свое имя с помощью TestName
| [TestCase("1.0.1")] | ||
| public void IsValidNumber_WithIncorrectValue_ReturnFalse(string value) | ||
| { | ||
| Assert.False(new NumberValidator(10, 5).IsValidNumber(value)); |
There was a problem hiding this comment.
Читается тяжело, можно разделить на инициализацию, вызов метода и проверку значения
|
|
||
| Assert.False(validator.IsValidNumber(value)); | ||
| } | ||
|
|
Comment on lines
33
to
77
| [TestCase(17, 2, true, "0.0")] | ||
| [TestCase(17, 2, true, "0")] | ||
| [TestCase(17, 2, true, "+0.0")] | ||
| [TestCase(3, 1, true, "+1.2")] | ||
| [TestCase(3, 1, false, "-1.2")] | ||
| public void IsValidNumber_WithProperValue_Success | ||
| (int precision, int scale, bool positive, string value) | ||
| { | ||
| var validator = new NumberValidator(precision, scale, positive); | ||
|
|
||
| Assert.True(validator.IsValidNumber(value)); | ||
| } | ||
|
|
||
| [TestCase(" ")] | ||
| [TestCase("")] | ||
| [TestCase(null)] | ||
| [TestCase("+-1")] | ||
| [TestCase("abc")] | ||
| [TestCase("a.bc")] | ||
| [TestCase("1.0.1")] | ||
| public void IsValidNumber_WithIncorrectValue_ReturnFalse(string value) | ||
| { | ||
| Assert.False(new NumberValidator(10, 5).IsValidNumber(value)); | ||
| } | ||
|
|
||
|
|
||
| [TestCase("-1.0")] | ||
| [TestCase("+1.0")] | ||
| [TestCase("10.0")] | ||
| [TestCase("1.00")] | ||
| public void IsValidNumber_WithValueGreaterThanPrecision_ReturnFalse(string value) | ||
| { | ||
| var validator = new NumberValidator(2, 1); | ||
|
|
||
| Assert.False(validator.IsValidNumber(value)); | ||
| } | ||
|
|
||
| [TestCase(true, "1.00")] | ||
| [TestCase(false, "-1.00")] | ||
| public void IsValidNumber_WithFracPartGreaterThanScale_ReturnFalse(bool positive, string value) | ||
| { | ||
| var validator = new NumberValidator(10, 1, positive); | ||
|
|
||
| Assert.False(validator.IsValidNumber(value)); | ||
| } |
There was a problem hiding this comment.
Честно говоря тут тоже ничего не мешает переделать все на тест кейсы
| } | ||
| } | ||
|
|
||
| public class NumberValidator |
There was a problem hiding this comment.
Вынести в отдельный файл. На шпоре, имхо, важно не только смотреть на то место, куда ты вносишь изменения но и на весь проект в целом, если видишь что где-то сделано не очень хорошо - исправляй. Так работает и в промышленной разработке (за исключением случаев, когда код написан настолько плохо, что трогать его страшно)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.