Skip to content

Conversation

@batyadmx
Copy link

No description provided.

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));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше использовать TestCase, кстати, каждому кейсу можно задать свое имя с помощью TestName

[TestCase("1.0.1")]
public void IsValidNumber_WithIncorrectValue_ReturnFalse(string value)
{
Assert.False(new NumberValidator(10, 5).IsValidNumber(value));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Читается тяжело, можно разделить на инициализацию, вызов метода и проверку значения


Assert.False(validator.IsValidNumber(value));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Потерялся атрибут

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));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Честно говоря тут тоже ничего не мешает переделать все на тест кейсы

}
}

public class NumberValidator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вынести в отдельный файл. На шпоре, имхо, важно не только смотреть на то место, куда ты вносишь изменения но и на весь проект в целом, если видишь что где-то сделано не очень хорошо - исправляй. Так работает и в промышленной разработке (за исключением случаев, когда код написан настолько плохо, что трогать его страшно)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants