Skip to content

homework#40

Open
Balashov2004 wants to merge 2 commits into
kontur-courses:masterfrom
Balashov2004:homework
Open

homework#40
Balashov2004 wants to merge 2 commits into
kontur-courses:masterfrom
Balashov2004:homework

Conversation

@Balashov2004

Copy link
Copy Markdown

No description provided.

@PeterMotorniy PeterMotorniy left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ревью

new Person("Vasili III of Russia", 28, 170, 60, null));

// Какие недостатки у такого подхода?
// Какие недостатки у такого подхода?

This comment was marked as resolved.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Будет рекурсия до бесконечности нужно добавить проверку что родитель не ссылается на царя
Сейчас у нас проверка, что мы сравниваем и с чем, что это два разных объекта if (actual == expected);

нужно добавить что то по типу if (actual != actual.Parent) ; что ссылки разные
хотя тут будет проблема с A на B и B на A тогда проверка не сработает
Можно сохранять что мы проверили и если снова попадется то стопать

ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd"));
public void IsValidNumber_Tests(int precision, int scale, bool onlyPositive, string input, bool expectedResult)
{
NumberValidator validator = new NumberValidator(precision, scale, onlyPositive);

This comment was marked as resolved.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Исправил


actualTsar.Should().BeEquivalentTo(expectedTsar, options => options
.Excluding(tsar => tsar.Id)
.Excluding(tsar => tsar.Parent!.Id));

This comment was marked as resolved.

TestName = "scale не может быть равен precision")]
[TestCase(1, -1, "precision must be a non-negative number less or equal than precision",
TestName = "scale не может быть отрицательным")]
public void ConstructorWhenParametersInvalid(int precision, int scale, string expectedMessage)

This comment was marked as resolved.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

исправил

Assert.DoesNotThrow(() => new NumberValidator(1, 0, true));
Assert.Throws<ArgumentException>(() => new NumberValidator(-1, 2, false));
Assert.DoesNotThrow(() => new NumberValidator(1, 0, true));
Assert.That(

This comment was marked as resolved.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Исправил

ClassicAssert.AreEqual(expectedTsar.Parent.Parent, actualTsar.Parent.Parent);

actualTsar.Should().BeEquivalentTo(expectedTsar, options => options
.Excluding(tsar => tsar.Id)

This comment was marked as resolved.

[TestCase(3, 2, true, "-0.00", false, TestName = "Ошибка: отрицательное число при onlyPositive=true")]
[TestCase(3, 2, true, "+0.00", false, TestName = "Ошибка: превышена точность из-за знака")]
[TestCase(6, 2, true, "0.000", false, TestName = "Ошибка: дробная часть превышает scale")]
[TestCase(3, 2, true, "-1.23", false, TestName = "Ошибка: отрицательное число при onlyPositive=true")]

This comment was marked as resolved.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

не заметил, исправил

}

[TestCase(1, 0, TestName = "scale может быть равен 0")]
[TestCase(7, 5, TestName = "общий тест")]

This comment was marked as resolved.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Переименовал

TestName = "precision не может быть отрицательным")]
[TestCase(0, 2, "precision must be a positive number",
TestName = "precision не может быть равен 0")]
[TestCase(1, 2, "precision must be a non-negative number less or equal than precision",

This comment was marked as resolved.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Тут не понял, вроде везде на русском ток поля там на английском, а тут
[TestCase(0, 2, "precision must be a positive number"
с каким сообщением должна прийти ошибка

ClassicAssert.AreEqual(expectedTsar.Parent.Height, actualTsar.Parent.Height);
ClassicAssert.AreEqual(expectedTsar.Parent.Parent, actualTsar.Parent.Parent);

actualTsar.Should().BeEquivalentTo(expectedTsar, options => options

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Есть ли какие-то проблемы у нового подхода? Может какие-то случаи когда тест будет работать неправильно?

actualTsar
.Should()
.BeEquivalentTo(expectedTsar, options => options
.Excluding(info => info.Path.EndsWith(".Id") || info.Path == "Id")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А можно ли как-то учитывать только поле Id?
И можно ли написать этот тест так, чтобы при переименовании Id на например Identificator тест все-равно работал правильно?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Через .Including можно выбрать поля которые мы хоти сравнивать и сравнивать только их
На второй вопрос не знаю как сделать, чтобы при переименовании тест все равно понимал, что исключать, но к id обращаться через аксессор get, и тогда сразу должна выпасть ошибка и мы поймем что он не нашел поле id, но вообще если именование правильное зачем его менять в будущем?

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