-
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
Зиновьева Милана @xsitin #24
Open
crycrash
wants to merge
3
commits into
kontur-courses:master
Choose a base branch
from
crycrash:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
bin/ | ||
obj/ | ||
.vs/ | ||
.DS_Store |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
using FluentAssertions; | ||
|
||
namespace HomeExercise.Tasks.ObjectComparison; | ||
public class ObjectComparison | ||
|
@@ -13,17 +14,13 @@ public void CheckCurrentTsar() | |
|
||
var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, | ||
new Person("Vasili III of Russia", 28, 170, 60, null)); | ||
|
||
// Перепишите код на использование Fluent Assertions. | ||
ClassicAssert.AreEqual(actualTsar.Name, expectedTsar.Name); | ||
ClassicAssert.AreEqual(actualTsar.Age, expectedTsar.Age); | ||
ClassicAssert.AreEqual(actualTsar.Height, expectedTsar.Height); | ||
ClassicAssert.AreEqual(actualTsar.Weight, expectedTsar.Weight); | ||
|
||
ClassicAssert.AreEqual(expectedTsar.Parent!.Name, actualTsar.Parent!.Name); | ||
ClassicAssert.AreEqual(expectedTsar.Parent.Age, actualTsar.Parent.Age); | ||
ClassicAssert.AreEqual(expectedTsar.Parent.Height, actualTsar.Parent.Height); | ||
ClassicAssert.AreEqual(expectedTsar.Parent.Parent, actualTsar.Parent.Parent); | ||
actualTsar.Should().BeEquivalentTo(expectedTsar, options => options | ||
.IncludingNestedObjects() | ||
.Excluding(p => p.Path.Contains("Id"))); | ||
//+Проверяет все поля класса на эквивалентность | ||
//+При добавлении нового поля в класс проверка будет автоматически включена | ||
//+Уменьшено количество кода | ||
//+Удобный вывод при непрохождении теста(показаны несовпадающие поля) | ||
} | ||
|
||
[Test] | ||
|
@@ -36,6 +33,13 @@ public void CheckCurrentTsar_WithCustomEquality() | |
|
||
// Какие недостатки у такого подхода? | ||
ClassicAssert.True(AreEqual(actualTsar, expectedTsar)); | ||
|
||
//-При появлении новых полей придется переписывать тест | ||
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. Есть ещё |
||
//-Функция возвращает bool, что не информативно | ||
//-Для того чтобы узнать различия между царями придется дебажить и проверять каждое условие | ||
//-Используется рекурсивный подход без явно заданного ограничения на рекурсию | ||
//-В IncludingNestedObjects макс глубина рекурсии по умолчанию 10 | ||
//-Что не даст уйти сильно в дебри | ||
} | ||
|
||
private bool AreEqual(Person? actual, Person? expected) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
| ||
using NUnit.Framework; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
|
||
namespace HomeExercise.Tasks.NumberValidator; | ||
|
||
|
@@ -10,22 +11,53 @@ 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")); | ||
using (new AssertionScope()) //Позволяет выполнить все проверки даже если какая-то упала | ||
//Информация об ошибках выдастся по заверщению всех тестов | ||
{ | ||
Action act = () => new NumberValidator(5, 2, true); | ||
act.Should().NotThrow(because: "Целая и дробная часть больше нуля, цифры целой части больше чем в дробной"); | ||
|
||
act = () => new NumberValidator(-1, 2, true); | ||
act.Should().Throw<ArgumentException>(because: "Целая часть меньше нуля"); | ||
|
||
act = () => new NumberValidator(1, -1, true); | ||
act.Should().Throw<ArgumentException>(because: "Дробная часть меньше нуля"); | ||
|
||
act = () => new NumberValidator(1, 1, false); | ||
act.Should().Throw<ArgumentException>(because: "Дробная часть равна целой части"); | ||
//Тесты для проверки корректности инициализации | ||
|
||
NumberValidator numberForCheck = new NumberValidator(4, 2, true); | ||
|
||
numberForCheck.IsValidNumber("").Should().BeFalse(because: "Ввод пуст"); | ||
numberForCheck.IsValidNumber(null).Should().BeFalse(because: "Ввод пуст"); | ||
|
||
numberForCheck.IsValidNumber("a.sd").Should().BeFalse(because: "Используются не арабские цифры"); | ||
numberForCheck.IsValidNumber("సున్న.నాలుగు").Should().BeFalse(because: "Используются не арабские цифры"); | ||
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. Это словва, а не числа, для телугу можно посмотреть табличку тут, числа то, что в скобках. Можно поискать ещё различные варианты |
||
numberForCheck.IsValidNumber("IV.III").Should().BeFalse(because: "Используются не арабские цифры"); | ||
numberForCheck.IsValidNumber("девять.ноль").Should().BeFalse(because: "Используются не арабские цифры"); | ||
|
||
numberForCheck.IsValidNumber("9dot8").Should().BeFalse(because: "Некорректный разделитель"); | ||
numberForCheck.IsValidNumber("3..2").Should().BeFalse(because: "Некорректный разделитель"); | ||
numberForCheck.IsValidNumber("1/2").Should().BeFalse(because: "Некорректный разделитель"); | ||
|
||
numberForCheck.IsValidNumber("plus9").Should().BeFalse(because: "Некорректный знак"); | ||
numberForCheck.IsValidNumber("++1").Should().BeFalse(because: "Некорректный знак"); | ||
//Тесты для проверки данных не подходящих под регулярку | ||
|
||
numberForCheck.IsValidNumber("0.0").Should().BeTrue(); | ||
numberForCheck.IsValidNumber("0").Should().BeTrue(); | ||
numberForCheck.IsValidNumber("+1.23").Should().BeTrue(); | ||
numberForCheck.IsValidNumber("+1,23").Should().BeTrue(because: "Знак запятой допустим"); | ||
numberForCheck = new NumberValidator(4, 2, false); | ||
numberForCheck.IsValidNumber("-1.23").Should().BeTrue(); | ||
//Тесты для проверки "нормальных" и пороговых значений | ||
|
||
numberForCheck = new NumberValidator(3, 2, true); | ||
numberForCheck.IsValidNumber("00.00").Should().BeFalse(because: "Используется больше символов чем положено"); | ||
numberForCheck.IsValidNumber("-0.0").Should().BeFalse(because: "Число отрицательное, хотя флаг не выставлен"); | ||
numberForCheck.IsValidNumber("+0.00").Should().BeFalse(because: "Используется больше символов чем положено"); | ||
//Тесты для проверки неподходящих по условию значений | ||
} | ||
} | ||
} |
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.
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.
При такой проверке, будут игнорироваться все поля в пути которых есть
Id
. Так мы можем пропустить что-то важно, если в классе появяться новые поля