From 7930a0ddd5fb3b40df5164cef48aabd7593f1ca4 Mon Sep 17 00:00:00 2001 From: stepan Date: Wed, 6 Nov 2024 13:46:34 +0500 Subject: [PATCH 1/6] =?UTF-8?q?=D0=9C=D0=BE=D0=B5=20=D1=80=D0=B5=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D1=83=D1=87=D1=88=D0=B5=20Che?= =?UTF-8?q?ckCurrentTsar=5FWithCustomEquality=20=D0=B2=20=D1=81=D0=BB?= =?UTF-8?q?=D0=B5=D0=B4=D1=83=D1=8E=D1=89=D0=B8=D1=85=20=D0=B0=D1=81=D0=BF?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B0=D1=85:=20=D0=BF=D1=80=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D1=8B=D1=85=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20Person=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D0=B4=D0=B5=D1=82=D1=81=D1=8F=20=D0=B2?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D0=B8=D1=82=D1=8C=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B2=20=D0=BA=D0=BE=D0=B4=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=B8=D1=80=D1=83=D1=8E=D1=89=D0=B5?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0;=20=D0=BA?= =?UTF-8?q?=D1=80=D0=BE=D0=BC=D0=B5=20=D1=82=D0=BE=D0=B3=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2=20Per?= =?UTF-8?q?son=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D1=87?= =?UTF-8?q?=D0=B8=D1=82=D0=B0=D0=B5=D0=BC=D1=8B=D0=B9=20=D1=81=D0=B8=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=D0=BA=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1. ObjectComparison/ObjectComparison.cs | 14 +++----------- .../Homework/1. ObjectComparison/Person.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Testing/Basic/Homework/1. ObjectComparison/ObjectComparison.cs b/Testing/Basic/Homework/1. ObjectComparison/ObjectComparison.cs index d544c47..81245d5 100644 --- a/Testing/Basic/Homework/1. ObjectComparison/ObjectComparison.cs +++ b/Testing/Basic/Homework/1. ObjectComparison/ObjectComparison.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +using FluentAssertions; +using NUnit.Framework; using NUnit.Framework.Legacy; namespace HomeExercise.Tasks.ObjectComparison; @@ -14,16 +15,7 @@ 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().Be(expectedTsar); } [Test] diff --git a/Testing/Basic/Homework/1. ObjectComparison/Person.cs b/Testing/Basic/Homework/1. ObjectComparison/Person.cs index 4846867..a4e45f1 100644 --- a/Testing/Basic/Homework/1. ObjectComparison/Person.cs +++ b/Testing/Basic/Homework/1. ObjectComparison/Person.cs @@ -18,4 +18,23 @@ public Person(string name, int age, int height, int weight, Person parent) Weight = weight; Parent = parent; } + + public override bool Equals(object obj) + { + if (obj is Person person) return this.GetHashCode() == person.GetHashCode(); + return false; + } + + public int GetHashCode() + { + var result = 0; + var degree = 0; + foreach (var field in GetType().GetFields()) + { + if (field.IsStatic || field.Name == "Id") continue; + result += (int)Math.Pow(field.GetValue(this).GetHashCode(), ++degree); + } + + return result; + } } \ No newline at end of file From ef79dff5d3f3ebf695fd4e7c633e2723c74faf57 Mon Sep 17 00:00:00 2001 From: stepan Date: Wed, 6 Nov 2024 14:51:11 +0500 Subject: [PATCH 2/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=81=D0=B2=D0=BE=D0=B8=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20?= =?UTF-8?q?=D0=B8=20=D0=BE=D1=82=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BB=20=D0=B8=D0=BC=D0=B5=D1=8E=D1=89=D0=B8=D0=B5?= =?UTF-8?q?=D1=81=D1=8F=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=8A=D0=B5=D0=BA=D1=82=D0=B0=20NumberValidator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NumberValidatorTests.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs b/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs index 950c9bc..205d120 100644 --- a/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs +++ b/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs @@ -8,13 +8,28 @@ namespace HomeExercise.Tasks.NumberValidator; public class NumberValidatorTests { [Test] - public void Test() + public void NumberValidator_IncorrectPrecision_Exception() { Assert.Throws(() => new NumberValidator(-1, 2, true)); + } + + [Test] + public void NumberValidator_CorrectInitialization_NoExceptions() + { Assert.DoesNotThrow(() => new NumberValidator(1, 0, true)); - Assert.Throws(() => new NumberValidator(-1, 2, false)); - Assert.DoesNotThrow(() => new NumberValidator(1, 0, true)); + } + [Test] + public void NumberValidator_IncorrectScale_Exception() + { + Assert.Throws(() => new NumberValidator(1, -1, true)); + Assert.Throws(() => new NumberValidator(1, 2, true)); + Assert.Throws(() => new NumberValidator(1, 1, true)); + } + + [Test] + public void Test() + { 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")); From 63aeed48b3408166243a855e090c58524150b7ca Mon Sep 17 00:00:00 2001 From: stepan Date: Wed, 6 Nov 2024 15:54:07 +0500 Subject: [PATCH 3/6] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D0=B1=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=BE=D1=82=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=8F=D1=89=D0=B8=D0=B5=D1=81=D1=8F=20=D0=BA=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20IsValidNumber=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=B0=D1=82=D0=B5=D0=B3=D0=BE=D1=80=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA,=20=D0=BA=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D1=8B=D0=B5=20=D0=BE=D0=BD=D0=B8=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D1=8F=D1=8E=D1=82,=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=BB=20=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D1=8F=D1=8E=D1=89=D0=B8=D0=B5=D1=81=D1=8F=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=8B,=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=20=D1=81=D0=B2=D0=BE=D0=B8=D0=BC=D0=B8?= =?UTF-8?q?=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NumberValidatorTests.cs | 53 ++++++++++++++----- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs b/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs index 205d120..7fe602c 100644 --- a/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs +++ b/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs @@ -26,21 +26,46 @@ public void NumberValidator_IncorrectScale_Exception() Assert.Throws(() => new NumberValidator(1, 2, true)); Assert.Throws(() => new NumberValidator(1, 1, true)); } - + [Test] - public void Test() - { - 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")); + public void IsValidNumber_InvalidCharacters_False() + { ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd")); } + + [TestCase("00.00", 3, 2)] + [TestCase("+1.23", 3, 2)] + [TestCase("0.000", 17, 2)] + public void IsValidNumber_NotTheAppropriateLength_False(string value, int precision, int scale = 0, bool onlyPositive = true) + { + ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value)); + } + + [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 = 0, bool onlyPositive = true) + { + ClassicAssert.IsTrue(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value)); + } + + [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) + { + ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value)); + } + + [TestCase("", 1)] + [TestCase(null, 1)] + public void IsValidNumber_NullOrEmpty_False(string value, int precision, int scale = 0, bool onlyPositive = true) + { + ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value)); + } + + [Test] + public void IsValidNumber_InappropriateAccuracy_False() + { + ClassicAssert.IsFalse(new NumberValidator(4, 2, true).IsValidNumber("0.000")); + } } \ No newline at end of file From 2a6728973aab60a2e052e849a862fef81088b574 Mon Sep 17 00:00:00 2001 From: stepan Date: Wed, 6 Nov 2024 17:47:50 +0500 Subject: [PATCH 4/6] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=20=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=81=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2. NumberValidator/NumberValidator.cs | 8 ++-- .../NumberValidatorTests.cs | 40 ++++++++++++------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Testing/Basic/Homework/2. NumberValidator/NumberValidator.cs b/Testing/Basic/Homework/2. NumberValidator/NumberValidator.cs index 327ce9c..d4eeb01 100644 --- a/Testing/Basic/Homework/2. NumberValidator/NumberValidator.cs +++ b/Testing/Basic/Homework/2. NumberValidator/NumberValidator.cs @@ -14,10 +14,10 @@ public NumberValidator(int precision, int scale = 0, bool onlyPositive = false) this.precision = precision; this.scale = scale; this.onlyPositive = onlyPositive; - if (precision <= 0) - throw new ArgumentException("precision must be a positive number"); - if (scale < 0 || scale >= precision) - throw new ArgumentException("precision must be a non-negative number less or equal than precision"); + // if (precision <= 0) + // throw new ArgumentException("precision must be a positive number"); + // if (scale < 0 || scale >= precision) + // throw new ArgumentException("precision must be a non-negative number less or equal than precision"); numberRegex = new Regex(@"^([+-]?)(\d+)([.,](\d+))?$", RegexOptions.IgnoreCase); } diff --git a/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs b/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs index 7fe602c..212cce1 100644 --- a/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs +++ b/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs @@ -10,35 +10,42 @@ public class NumberValidatorTests [Test] public void NumberValidator_IncorrectPrecision_Exception() { - Assert.Throws(() => new NumberValidator(-1, 2, true)); + Assert.Throws(() => new NumberValidator(-1, 2, true), + "precision должен быть положительным числом"); } [Test] public void NumberValidator_CorrectInitialization_NoExceptions() { - Assert.DoesNotThrow(() => new NumberValidator(1, 0, true)); + Assert.DoesNotThrow(() => new NumberValidator(1, 0, true), + "При создании экземпляра класса не должно было возникнуть ошибок"); } - [Test] - public void NumberValidator_IncorrectScale_Exception() + [TestCase(1, -1)] + [TestCase(1, 2)] + [TestCase(1, 1)] + public void NumberValidator_IncorrectScale_Exception(int precision, int scale = 0, bool onlyPositive = true) { - Assert.Throws(() => new NumberValidator(1, -1, true)); - Assert.Throws(() => new NumberValidator(1, 2, true)); - Assert.Throws(() => new NumberValidator(1, 1, true)); + Assert.Throws(() => new NumberValidator(precision, scale, onlyPositive), + "scale должно быть меньше precision, но больше или равно 0"); } [Test] public void IsValidNumber_InvalidCharacters_False() { - ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd")); + ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd"), + "В записи числа не должны содержаться буквы"); } [TestCase("00.00", 3, 2)] [TestCase("+1.23", 3, 2)] - [TestCase("0.000", 17, 2)] - public void IsValidNumber_NotTheAppropriateLength_False(string value, int precision, int scale = 0, bool onlyPositive = true) + public void IsValidNumber_NotTheAppropriateLength_False(string value, + int precision, + int scale = 0, + bool onlyPositive = true) { - ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value)); + ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value), + "Длина числа не соответствует шаблону"); } [TestCase("+1.23", 4, 2)] @@ -53,19 +60,22 @@ public void IsValidNumber_CorrectValue_True(string value, int precision, int sca [TestCase("+0.00", 3, 2, false)] public void IsValidNumber_TheWrongSign_False(string value, int precision, int scale = 0, bool onlyPositive = true) { - ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value)); + ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value), + "Знаки value и NumberValidator отличаются"); } [TestCase("", 1)] [TestCase(null, 1)] public void IsValidNumber_NullOrEmpty_False(string value, int precision, int scale = 0, bool onlyPositive = true) { - ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value)); + ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value), + "Проверяемое значение не должно равняться null или пустой строке"); } - + [Test] public void IsValidNumber_InappropriateAccuracy_False() { - ClassicAssert.IsFalse(new NumberValidator(4, 2, true).IsValidNumber("0.000")); + ClassicAssert.IsFalse(new NumberValidator(17, 2, true).IsValidNumber("0.000"), + "значение не может иметь точность выше указанной в NumberValidator"); } } \ No newline at end of file From 260031fa464db9c90f7eae250d8d30fa00adea10 Mon Sep 17 00:00:00 2001 From: stepan Date: Thu, 7 Nov 2024 14:57:23 +0500 Subject: [PATCH 5/6] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B8=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.idea.shpora-testing.dir/.idea/.gitignore | 13 +++++++++++++ .../.idea.shpora-testing.dir/.idea/.name | 1 + .../.idea/encodings.xml | 6 ++++++ .../.idea/indexLayout.xml | 8 ++++++++ .../.idea.shpora-testing.dir/.idea/vcs.xml | 6 ++++++ Testing/Basic/Folder.DotSettings.user | 4 ++++ .../1. ObjectComparison/ObjectComparison.cs | 5 ++++- .../Homework/1. ObjectComparison/Person.cs | 19 ------------------- .../2. NumberValidator/NumberValidator.cs | 8 ++++---- 9 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/.gitignore create mode 100644 Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/.name create mode 100644 Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/encodings.xml create mode 100644 Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/indexLayout.xml create mode 100644 Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/vcs.xml create mode 100644 Testing/Basic/Folder.DotSettings.user diff --git a/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/.gitignore b/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/.gitignore new file mode 100644 index 0000000..3eb429f --- /dev/null +++ b/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/.idea.shpora-testing.iml +/projectSettingsUpdater.xml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/.name b/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/.name new file mode 100644 index 0000000..fbc9581 --- /dev/null +++ b/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/.name @@ -0,0 +1 @@ +shpora-testing \ No newline at end of file diff --git a/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/encodings.xml b/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/encodings.xml new file mode 100644 index 0000000..f39da2b --- /dev/null +++ b/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/indexLayout.xml b/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/vcs.xml b/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/Testing/Basic/.idea/.idea.shpora-testing.dir/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Testing/Basic/Folder.DotSettings.user b/Testing/Basic/Folder.DotSettings.user new file mode 100644 index 0000000..729fdd0 --- /dev/null +++ b/Testing/Basic/Folder.DotSettings.user @@ -0,0 +1,4 @@ + + <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from 1. ObjectComparison" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <ProjectFolder>DA962CAA-00CF-51C4-EF46-5F6115A45A20/d:Homework/d:1. ObjectComparison</ProjectFolder> +</SessionState> \ No newline at end of file diff --git a/Testing/Basic/Homework/1. ObjectComparison/ObjectComparison.cs b/Testing/Basic/Homework/1. ObjectComparison/ObjectComparison.cs index 81245d5..5e46b10 100644 --- a/Testing/Basic/Homework/1. ObjectComparison/ObjectComparison.cs +++ b/Testing/Basic/Homework/1. ObjectComparison/ObjectComparison.cs @@ -15,7 +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)); - actualTsar.Should().Be(expectedTsar); + actualTsar.Should().BeEquivalentTo(expectedTsar, + options => options + .Excluding(tsar => tsar.Id) + .Excluding(tsar => tsar.Parent.Id)); } [Test] diff --git a/Testing/Basic/Homework/1. ObjectComparison/Person.cs b/Testing/Basic/Homework/1. ObjectComparison/Person.cs index a4e45f1..4846867 100644 --- a/Testing/Basic/Homework/1. ObjectComparison/Person.cs +++ b/Testing/Basic/Homework/1. ObjectComparison/Person.cs @@ -18,23 +18,4 @@ public Person(string name, int age, int height, int weight, Person parent) Weight = weight; Parent = parent; } - - public override bool Equals(object obj) - { - if (obj is Person person) return this.GetHashCode() == person.GetHashCode(); - return false; - } - - public int GetHashCode() - { - var result = 0; - var degree = 0; - foreach (var field in GetType().GetFields()) - { - if (field.IsStatic || field.Name == "Id") continue; - result += (int)Math.Pow(field.GetValue(this).GetHashCode(), ++degree); - } - - return result; - } } \ No newline at end of file diff --git a/Testing/Basic/Homework/2. NumberValidator/NumberValidator.cs b/Testing/Basic/Homework/2. NumberValidator/NumberValidator.cs index d4eeb01..327ce9c 100644 --- a/Testing/Basic/Homework/2. NumberValidator/NumberValidator.cs +++ b/Testing/Basic/Homework/2. NumberValidator/NumberValidator.cs @@ -14,10 +14,10 @@ public NumberValidator(int precision, int scale = 0, bool onlyPositive = false) this.precision = precision; this.scale = scale; this.onlyPositive = onlyPositive; - // if (precision <= 0) - // throw new ArgumentException("precision must be a positive number"); - // if (scale < 0 || scale >= precision) - // throw new ArgumentException("precision must be a non-negative number less or equal than precision"); + if (precision <= 0) + throw new ArgumentException("precision must be a positive number"); + if (scale < 0 || scale >= precision) + throw new ArgumentException("precision must be a non-negative number less or equal than precision"); numberRegex = new Regex(@"^([+-]?)(\d+)([.,](\d+))?$", RegexOptions.IgnoreCase); } From cee3d86f1dfb0bb5ba76e85f19b3c05c8522c4d5 Mon Sep 17 00:00:00 2001 From: stepan Date: Thu, 7 Nov 2024 16:19:05 +0500 Subject: [PATCH 6/6] =?UTF-8?q?=D0=9E=D1=82=D1=80=D0=B5=D1=84=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=BB=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Testing/Basic/Folder.DotSettings.user | 5 +- .../NumberValidatorTests.cs | 80 ++++++++++++------- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/Testing/Basic/Folder.DotSettings.user b/Testing/Basic/Folder.DotSettings.user index 729fdd0..a24078a 100644 --- a/Testing/Basic/Folder.DotSettings.user +++ b/Testing/Basic/Folder.DotSettings.user @@ -1,4 +1,7 @@  <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from 1. ObjectComparison" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <ProjectFolder>DA962CAA-00CF-51C4-EF46-5F6115A45A20/d:Homework/d:1. ObjectComparison</ProjectFolder> + <Or> + <ProjectFolder>DA962CAA-00CF-51C4-EF46-5F6115A45A20/d:Homework/d:1. ObjectComparison</ProjectFolder> + <ProjectFolder>DA962CAA-00CF-51C4-EF46-5F6115A45A20/d:Homework/d:2. NumberValidator</ProjectFolder> + </Or> </SessionState> \ No newline at end of file diff --git a/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs b/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs index 212cce1..5ba4f11 100644 --- a/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs +++ b/Testing/Basic/Homework/2. NumberValidator/NumberValidatorTests.cs @@ -1,81 +1,99 @@  +using FluentAssertions; using NUnit.Framework; -using NUnit.Framework.Legacy; namespace HomeExercise.Tasks.NumberValidator; [TestFixture] public class NumberValidatorTests { - [Test] - public void NumberValidator_IncorrectPrecision_Exception() + [TestCase(false)] + [TestCase(true)] + public void NumberValidator_IncorrectPrecision_Exception(bool onlyPositive) { - Assert.Throws(() => new NumberValidator(-1, 2, true), - "precision должен быть положительным числом"); + var createAConstructor = () => new NumberValidator(-1, 2, onlyPositive); + createAConstructor + .Should() + .Throw("precision должен быть положительным числом"); } - [Test] - public void NumberValidator_CorrectInitialization_NoExceptions() + [TestCase(true)] + [TestCase(false)] + public void NumberValidator_CorrectInitialization_NoExceptions(bool onlyPositive) { - Assert.DoesNotThrow(() => new NumberValidator(1, 0, true), - "При создании экземпляра класса не должно было возникнуть ошибок"); + 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 = 0, bool onlyPositive = true) + public void NumberValidator_IncorrectScale_Exception(int precision, int scale) { - Assert.Throws(() => new NumberValidator(precision, scale, onlyPositive), - "scale должно быть меньше precision, но больше или равно 0"); + var createAConstructor = () => new NumberValidator(precision, scale, true); + createAConstructor + .Should() + .Throw("scale должно быть меньше precision, но больше или равно 0"); } [Test] public void IsValidNumber_InvalidCharacters_False() { - ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd"), - "В записи числа не должны содержаться буквы"); + new NumberValidator(3, 2, true) + .IsValidNumber("a.sd") + .Should() + .BeFalse("В записи числа не должны содержаться буквы"); } [TestCase("00.00", 3, 2)] [TestCase("+1.23", 3, 2)] - public void IsValidNumber_NotTheAppropriateLength_False(string value, - int precision, - int scale = 0, - bool onlyPositive = true) + public void Should_ReturnFalse_WhenUnappropriateLength(string value, int precision, int scale) { - ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value), - "Длина числа не соответствует шаблону"); + 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 = 0, bool onlyPositive = true) + public void IsValidNumber_CorrectValue_True(string value, int precision, int scale) { - ClassicAssert.IsTrue(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value)); + 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) { - ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value), - "Знаки value и NumberValidator отличаются"); + new NumberValidator(precision, scale, onlyPositive) + .IsValidNumber(value) + .Should() + .BeFalse("Знаки value и NumberValidator отличаются"); } - [TestCase("", 1)] - [TestCase(null, 1)] - public void IsValidNumber_NullOrEmpty_False(string value, int precision, int scale = 0, bool onlyPositive = true) + [TestCase("")] + [TestCase(null)] + public void IsValidNumber_NullOrEmpty_False(string value, int precision = 1, int scale = 0, bool onlyPositive = true) { - ClassicAssert.IsFalse(new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value), - "Проверяемое значение не должно равняться null или пустой строке"); + new NumberValidator(precision, scale, onlyPositive) + .IsValidNumber(value) + .Should() + .BeFalse("Проверяемое значение не должно равняться null или пустой строке"); } [Test] public void IsValidNumber_InappropriateAccuracy_False() { - ClassicAssert.IsFalse(new NumberValidator(17, 2, true).IsValidNumber("0.000"), - "значение не может иметь точность выше указанной в NumberValidator"); + new NumberValidator(17, 2, true) + .IsValidNumber("0.000") + .Should() + .BeFalse("значение не может иметь точность выше указанной в NumberValidator"); } } \ No newline at end of file