-
Notifications
You must be signed in to change notification settings - Fork 281
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
Овечкин Илья #238
base: master
Are you sure you want to change the base?
Овечкин Илья #238
Changes from 3 commits
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 |
---|---|---|
|
@@ -7,28 +7,47 @@ namespace HomeExercises | |
{ | ||
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)); | ||
[Test] | ||
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] атрибут [Test] не нужен, вроде как. |
||
[TestCase(17, 2, true, "0.0", true)] | ||
[TestCase(17, 2, true, "0", true)] | ||
[TestCase(3, 2, true, "00.00", false)] | ||
[TestCase(3, 2, true, "-0.0", false)] | ||
[TestCase(3, 2, true, "+0.00", false)] | ||
[TestCase(4, 2, true, "+1.23", true)] | ||
[TestCase(3, 2, true, "+1.23", false)] | ||
[TestCase(17, 2, true, "0.000", false)] | ||
[TestCase(3, 2, true, "-1.23", false)] | ||
[TestCase(3, 2, true, "a.sd", false)] | ||
[TestCase(3, 2, true, "", false)] | ||
[TestCase(3, 2, true, null, false)] | ||
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. Все кейсы тут не учитывают один из параметров, он всегда одинакового значения. Давай напишем ещё кейсов, где этот параметр тоже будет изменен? 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. Давай ещё всем кейсам добавим понятные названия, чтобы можно было понять, что именно конкретный кейс означает с точки зрения логики? |
||
public void ValidateNumberCorrect_When_DaraCorrect(int precision, int scale, bool onlyPositive, string value, bool expectedResult) | ||
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. Data, а не Dara. |
||
{ | ||
var validator = new NumberValidator(precision, scale, onlyPositive); | ||
var result = validator.IsValidNumber(value); | ||
result.Should().Be(expectedResult); | ||
} | ||
|
||
Assert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0.0")); | ||
Assert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0")); | ||
Assert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0.0")); | ||
Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("00.00")); | ||
Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("-0.00")); | ||
Assert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0.0")); | ||
Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("+0.00")); | ||
Assert.IsTrue(new NumberValidator(4, 2, true).IsValidNumber("+1.23")); | ||
Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("+1.23")); | ||
Assert.IsFalse(new NumberValidator(17, 2, true).IsValidNumber("0.000")); | ||
Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("-1.23")); | ||
Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd")); | ||
} | ||
} | ||
[Test] | ||
[TestCase(-1, 2, true)] | ||
[TestCase(1, -2, false)] | ||
[TestCase(1, 2, true)] | ||
[TestCase(1, 1, false)] | ||
public void Should_ThrowArgumentException_When_InitIncorrectData(int precision, int scale, bool onlyPositive) | ||
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. Не совсем понятно "InitIncorrectData", можно без init. |
||
{ | ||
Action action = () => new NumberValidator(precision, scale, onlyPositive); | ||
action.Should().Throw<ArgumentException>(); | ||
} | ||
|
||
[Test] | ||
[TestCase(1, 0, true)] | ||
[TestCase(2, 1, true)] | ||
public void Should_DoesNotThrowArgumentException_When_InitCorrectData(int precision, int scale, bool onlyPositive) | ||
{ | ||
Action action = () => new NumberValidator(precision, scale, onlyPositive); | ||
action.Should().NotThrow(); | ||
|
||
} | ||
} | ||
|
||
public class NumberValidator | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,41 +5,46 @@ namespace HomeExercises | |
{ | ||
public class ObjectComparison | ||
{ | ||
[Test] | ||
[Description("Проверка текущего царя")] | ||
[Category("ToRefactor")] | ||
public void CheckCurrentTsar() | ||
{ | ||
var actualTsar = TsarRegistry.GetCurrentTsar(); | ||
[Test] | ||
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. Тут тоже слетело форматирование - не хватает табуляции. |
||
[Description("Проверка текущего царя")] | ||
[Category("ToRefactor")] | ||
public void CheckCurrentTsar() | ||
{ | ||
var actualTsar = TsarRegistry.GetCurrentTsar(); | ||
|
||
var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, | ||
new Person("Vasili III of Russia", 28, 170, 60, null)); | ||
var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, | ||
new Person("Vasili III of Russia", 28, 170, 60, null)); | ||
|
||
// Перепишите код на использование Fluent Assertions. | ||
Assert.AreEqual(actualTsar.Name, expectedTsar.Name); | ||
Assert.AreEqual(actualTsar.Age, expectedTsar.Age); | ||
Assert.AreEqual(actualTsar.Height, expectedTsar.Height); | ||
Assert.AreEqual(actualTsar.Weight, expectedTsar.Weight); | ||
actualTsar.Should().BeEquivalentTo(expectedTsar, options => | ||
options.Excluding(option => option.Id) | ||
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. Тут option не совсем корректно, как мне кажется. Здесь мы поля выбираем у объекта, все таки, а не у options. |
||
.Excluding(option => option.Parent.Id)); | ||
} | ||
/* Преимущества подхода: | ||
1. Хорошая информативность. При непрохождении теста ясно показывается, какие поля не совпали. | ||
2. Хорошая расширяемость. При добавлении или удалении полей в классе, нужно внести минимум изменений в тесте. | ||
3. Хорошая читаемость. Из-за меньшего объема кода и понятного названия методов улучшается читаемость кода. | ||
*/ | ||
|
||
Assert.AreEqual(expectedTsar.Parent!.Name, actualTsar.Parent!.Name); | ||
Assert.AreEqual(expectedTsar.Parent.Age, actualTsar.Parent.Age); | ||
Assert.AreEqual(expectedTsar.Parent.Height, actualTsar.Parent.Height); | ||
Assert.AreEqual(expectedTsar.Parent.Parent, actualTsar.Parent.Parent); | ||
} | ||
[Test] | ||
[Description("Альтернативное решение. Какие у него недостатки?")] | ||
public void CheckCurrentTsar_WithCustomEquality() | ||
{ | ||
var actualTsar = TsarRegistry.GetCurrentTsar(); | ||
var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, | ||
new Person("Vasili III of Russia", 28, 170, 60, null)); | ||
|
||
[Test] | ||
[Description("Альтернативное решение. Какие у него недостатки?")] | ||
public void CheckCurrentTsar_WithCustomEquality() | ||
{ | ||
var actualTsar = TsarRegistry.GetCurrentTsar(); | ||
var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, | ||
new Person("Vasili III of Russia", 28, 170, 60, null)); | ||
|
||
// Какие недостатки у такого подхода? | ||
Assert.True(AreEqual(actualTsar, expectedTsar)); | ||
} | ||
Assert.True(AreEqual(actualTsar, expectedTsar)); | ||
} | ||
/* Недостаки подхода: | ||
1. Плохая информативность. При непрохождении теста выводится "Ожидалось True, но было False", из-за | ||
чего непонятно, какие поля не совпадают. | ||
2. Плохая расширяемость. При добавлении или удалении поля, придется изменять метод AreEqual, что можно | ||
забыть сделать. | ||
3. Функция сравнения не должна быть определена в классе тестов. Лучше, что бы она была определена в классе | ||
Person или специальном классе для сравнения. | ||
*/ | ||
|
||
private bool AreEqual(Person? actual, Person? expected) | ||
private bool AreEqual(Person? actual, Person? expected) | ||
{ | ||
if (actual == expected) return true; | ||
if (actual == null || expected == null) return false; | ||
|
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.
Поехало форматирование - нет табуляции после "{" у класса.