Skip to content
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

Домашка Зайцев ДА #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Testing/Basic/Basic.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35303.130
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Basic", "Basic.csproj", "{61D6F679-81DC-4D99-89CE-C3CEE18F9D83}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{61D6F679-81DC-4D99-89CE-C3CEE18F9D83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61D6F679-81DC-4D99-89CE-C3CEE18F9D83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61D6F679-81DC-4D99-89CE-C3CEE18F9D83}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61D6F679-81DC-4D99-89CE-C3CEE18F9D83}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C6BF16E1-4A74-40D0-9D06-39C39FFA1D6F}
EndGlobalSection
EndGlobal
22 changes: 12 additions & 10 deletions Testing/Basic/Homework/1. ObjectComparison/ObjectComparison.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using FluentAssertions;
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace HomeExercise.Tasks.ObjectComparison;
Expand All @@ -14,16 +15,17 @@ 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);
actualTsar.Should()
.BeEquivalentTo(expectedTsar,
options => options
.Excluding(x => x.Id)
.Excluding(x => x.Parent!.Id));

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);
//1. ипользование метода CheckCurrentTsar_WithCustomEquality сложнее в понимании
//использование FluentAssertions повышает простоту и читаемость кода;
//2. после создания каждого нового поля, нужно добавлять его в метод
//в моем методе добавлять нужно только поля, которые нужно исключить из сравнения
//таких полей намного меньше, поэтому количество изменений метода меньше;
}

[Test]
Expand Down
60 changes: 42 additions & 18 deletions Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using FluentAssertions;
using NUnit.Framework;
using NUnit.Framework.Legacy;

Expand All @@ -7,25 +8,48 @@ namespace HomeExercise.Tasks.NumberValidator;
[TestFixture]
public class NumberValidatorTests
{
[Test]
public void Test()
[TestCase(17, 2, true, "0.0")]
[TestCase(17, 2, true, "0")]
[TestCase(4, 2, true, "+1.23")]
[TestCase(4, 2, false, "-1.23")]
public void IsValidNumber_True_When_CorrectValues(int precision, int scale, bool onlyPositive, string value)
{
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));
var validator = new NumberValidator(precision, scale, onlyPositive);
validator.IsValidNumber(value).Should().BeTrue();
}

[TestCase(3, 2, true, "00.00")]
[TestCase(3, 2, true, "-0.00")]
[TestCase(3, 2, true, "+0.00")]
[TestCase(3, 2, true, "+1.23")]
[TestCase(17, 2, true, "0.000")]
[TestCase(3, 2, true, "-1.23")]
[TestCase(3, 2, true, "a.sd")]
[TestCase(3, 2, true, "")]
[TestCase(3, 2, true, null)]
public void IsValidNumber_False_When_InCorrectValues(int precision, int scale, bool onlyPositive, string value)
{
var validator = new NumberValidator(precision, scale, onlyPositive);
validator.IsValidNumber(value).Should().BeFalse();
}


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"));
[TestCase(-1, 2, true)]
[TestCase(1, 2, false)]
[TestCase(5, -2, false)]
public void NumberValidator_ThrowException_When_InCorrectValue(int precision, int scale, bool onlyPositive)
{
var action = () => new NumberValidator(precision, scale, onlyPositive);
action.Should().Throw<ArgumentException>();
}

[TestCase(1, 0, true)]
[TestCase(3, 2, true)]
[TestCase(10, 9, false)]
[TestCase(3, 2, false)]
public void NumberValidator_NotThrowException_When_CorrectValue(int precision, int scale, bool onlyPositive)
{
var action = () => new NumberValidator(precision, scale, onlyPositive);
action.Should().NotThrow();
}
}