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

Степан Заколюкин #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Testing/Basic/Folder.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=2b7b12c0_002D2f29_002D4d2f_002D802a_002Dd2a2536dcec5/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from 1. ObjectComparison" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Or&gt;&#xD;
&lt;ProjectFolder&gt;DA962CAA-00CF-51C4-EF46-5F6115A45A20/d:Homework/d:1. ObjectComparison&lt;/ProjectFolder&gt;&#xD;
&lt;ProjectFolder&gt;DA962CAA-00CF-51C4-EF46-5F6115A45A20/d:Homework/d:2. NumberValidator&lt;/ProjectFolder&gt;&#xD;
&lt;/Or&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
17 changes: 6 additions & 11 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,10 @@ 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
.Excluding(tsar => tsar.Id)
.Excluding(tsar => tsar.Parent.Id));
}

[Test]
Expand Down
108 changes: 88 additions & 20 deletions Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,99 @@

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

namespace HomeExercise.Tasks.NumberValidator;

[TestFixture]
public class NumberValidatorTests
{
[TestCase(false)]
[TestCase(true)]
public void NumberValidator_IncorrectPrecision_Exception(bool onlyPositive)
{
var createAConstructor = () => new NumberValidator(-1, 2, onlyPositive);
createAConstructor
.Should()
.Throw<ArgumentException>("precision должен быть положительным числом");
}

[TestCase(true)]
[TestCase(false)]
public void NumberValidator_CorrectInitialization_NoExceptions(bool onlyPositive)
{
var createAConstructor = () => new NumberValidator(3, 2, onlyPositive);
createAConstructor
.Should()
.NotThrow();
}

[TestCase(1, -1)]
[TestCase(1, 2)]
[TestCase(1, 1)]
public void NumberValidator_IncorrectScale_Exception(int precision, int scale)
{
var createAConstructor = () => new NumberValidator(precision, scale, true);
createAConstructor
.Should()
.Throw<ArgumentException>("scale должно быть меньше precision, но больше или равно 0");
}

[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"));
public void IsValidNumber_InvalidCharacters_False()
{
new NumberValidator(3, 2, true)
.IsValidNumber("a.sd")
.Should()
.BeFalse("В записи числа не должны содержаться буквы");
}

[TestCase("00.00", 3, 2)]
[TestCase("+1.23", 3, 2)]
public void Should_ReturnFalse_WhenUnappropriateLength(string value, int precision, int scale)
{
new NumberValidator(precision, scale, true)
.IsValidNumber(value)
.Should()
.BeFalse("Длина числа не соответствует шаблону");
}

[TestCase("+1.23", 4, 2)]
[TestCase("0", 17, 2)]
[TestCase("0.0", 17, 2)]
public void IsValidNumber_CorrectValue_True(string value, int precision, int scale)
{
new NumberValidator(precision, scale, true)
.IsValidNumber(value)
.Should()
.BeTrue();
}

[TestCase("-0.00", 3, 2)]
[TestCase("+0.00", 3, 2, false)]
public void IsValidNumber_TheWrongSign_False(string value, int precision, int scale = 0, bool onlyPositive = true)
{
new NumberValidator(precision, scale, onlyPositive)
.IsValidNumber(value)
.Should()
.BeFalse("Знаки value и NumberValidator отличаются");
}

[TestCase("")]
[TestCase(null)]
public void IsValidNumber_NullOrEmpty_False(string value, int precision = 1, int scale = 0, bool onlyPositive = true)
{
new NumberValidator(precision, scale, onlyPositive)
.IsValidNumber(value)
.Should()
.BeFalse("Проверяемое значение не должно равняться null или пустой строке");
}

[Test]
public void IsValidNumber_InappropriateAccuracy_False()
{
new NumberValidator(17, 2, true)
.IsValidNumber("0.000")
.Should()
.BeFalse("значение не может иметь точность выше указанной в NumberValidator");
}
}