From 27a44a68222bb59c879b81cd5c5c416e1b80f6e0 Mon Sep 17 00:00:00 2001 From: fearppen Date: Sat, 25 Nov 2023 14:51:12 +0500 Subject: [PATCH 1/7] Refactor tests in ObjectComparison.cs and NumberValidatorTests.cs --- cs/HomeExercises/HomeExercises.csproj | 6 +- cs/HomeExercises/NumberValidatorTests.cs | 111 +++++++++++++++++++---- cs/HomeExercises/ObjectComparison.cs | 15 +-- 3 files changed, 99 insertions(+), 33 deletions(-) diff --git a/cs/HomeExercises/HomeExercises.csproj b/cs/HomeExercises/HomeExercises.csproj index ede81aec..f8d97426 100644 --- a/cs/HomeExercises/HomeExercises.csproj +++ b/cs/HomeExercises/HomeExercises.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net7.0 false HomeExercises ObjectComparison @@ -13,8 +13,8 @@ - - + + \ No newline at end of file diff --git a/cs/HomeExercises/NumberValidatorTests.cs b/cs/HomeExercises/NumberValidatorTests.cs index a2878113..a3772e5b 100644 --- a/cs/HomeExercises/NumberValidatorTests.cs +++ b/cs/HomeExercises/NumberValidatorTests.cs @@ -8,27 +8,98 @@ namespace HomeExercises public class NumberValidatorTests { [Test] - public void Test() + public void Throws_WhenPrecisionNotPositive() + { + Action action = () => new NumberValidator(-1, 2, true); + action.Should().Throw(); + } + + [Test] + public void Throws_WhenScaleNegative() { - Assert.Throws(() => new NumberValidator(-1, 2, true)); - Assert.DoesNotThrow(() => new NumberValidator(1, 0, true)); - Assert.Throws(() => new NumberValidator(-1, 2, false)); - Assert.DoesNotThrow(() => new NumberValidator(1, 0, true)); - - Assert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0.0")); - Assert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0")); - Assert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0.0")); - Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("00.00")); - Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("-0.00")); - Assert.IsTrue(new NumberValidator(17, 2, true).IsValidNumber("0.0")); - Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("+0.00")); - Assert.IsTrue(new NumberValidator(4, 2, true).IsValidNumber("+1.23")); - Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("+1.23")); - Assert.IsFalse(new NumberValidator(17, 2, true).IsValidNumber("0.000")); - Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("-1.23")); - Assert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd")); - } - } + Action action = () => new NumberValidator(1, -1, true); + action.Should().Throw(); + } + + [Test] + public void Throws_WhenScaleBiggerPrecision() + { + Action action = () => new NumberValidator(1, 2, true); + action.Should().Throw(); + } + + [Test] + public void Fails_WhenNumberEmpty() + { + var validator = new NumberValidator(17, 2, true); + var result = validator.IsValidNumber(" "); + result.Should().BeFalse(); + } + + [Test] + public void Fails_WhenNumberNotMatch() + { + var validator = new NumberValidator(8, 2, true); + var result = validator.IsValidNumber("1/43"); + result.Should().BeFalse(); + } + + [Test] + public void Success_WhenIntAndFractPartLessWhenPrecision() + { + var validator = new NumberValidator(17, 2, true); + var result = validator.IsValidNumber("0"); + result.Should().BeTrue(); + } + + [Test] + public void Fails_WhenPrecisionLessCountNumbers() + { + var validator = new NumberValidator(3, 2, true); + var result = validator.IsValidNumber("00.00"); + result.Should().BeFalse(); + } + + [Test] + public void Fails_WhenPrecisionLessCountNumbersAndMinus() + { + var validator = new NumberValidator(3, 2, true); + var result = validator.IsValidNumber("-0.00"); + result.Should().BeFalse(); + } + + [Test] + public void Success_WhenPrecisionEqualsCountNumbersAndSign() + { + var validator = new NumberValidator(4, 2, true); + var result = validator.IsValidNumber("+1.23"); + result.Should().BeTrue(); + } + + [Test] + public void Fails_WhenScaleLessFractPartLength() + { + var validator = new NumberValidator(17, 2, true); + var result = validator.IsValidNumber("0.000"); + result.Should().BeFalse(); + } + + [Test] + public void Fails_WhenLetters() + { + var validator = new NumberValidator(3, 2, true); + var result = validator.IsValidNumber("a.sd"); + result.Should().BeFalse(); + } + + [Test] + public void Fails_WhenOnlyPositiveAndNegativeNumber() + { + var validator = new NumberValidator(3, 2, true); + var result = validator.IsValidNumber("-1.2"); + result.Should().BeFalse(); + } + } public class NumberValidator { diff --git a/cs/HomeExercises/ObjectComparison.cs b/cs/HomeExercises/ObjectComparison.cs index 44d9aed4..bb89a711 100644 --- a/cs/HomeExercises/ObjectComparison.cs +++ b/cs/HomeExercises/ObjectComparison.cs @@ -15,18 +15,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. - Assert.AreEqual(actualTsar.Name, expectedTsar.Name); - Assert.AreEqual(actualTsar.Age, expectedTsar.Age); - Assert.AreEqual(actualTsar.Height, expectedTsar.Height); - Assert.AreEqual(actualTsar.Weight, expectedTsar.Weight); - - Assert.AreEqual(expectedTsar.Parent!.Name, actualTsar.Parent!.Name); - Assert.AreEqual(expectedTsar.Parent.Age, actualTsar.Parent.Age); - Assert.AreEqual(expectedTsar.Parent.Height, actualTsar.Parent.Height); - Assert.AreEqual(expectedTsar.Parent.Parent, actualTsar.Parent.Parent); + actualTsar.Should().BeEquivalentTo(expectedTsar, options => + options.Excluding(tsar => tsar.SelectedMemberPath.EndsWith("Id"))); } + // Недостаток в том, что нужно будет переписывать тест при любом исправлении в классе Person. + // Возможно нужно добавить какое-то поле, или изменить название уже существующего, + // придется изменять каждый раз метод AreEqual, так же снижается читаемость теста [Test] [Description("Альтернативное решение. Какие у него недостатки?")] public void CheckCurrentTsar_WithCustomEquality() From 5f9dca3f2f4eb19a2e030aad82a91d2a2b1091c5 Mon Sep 17 00:00:00 2001 From: fearppen Date: Sat, 25 Nov 2023 18:02:06 +0500 Subject: [PATCH 2/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=D1=80=D0=B8=D0=B9=20=D0=B2=20ObjectComparison.cs,=20=D0=BE?= =?UTF-8?q?=D1=82=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D0=BA=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cs/HomeExercises/NumberValidatorTests.cs | 138 +++++++++++------------ cs/HomeExercises/ObjectComparison.cs | 131 ++++++++++----------- 2 files changed, 136 insertions(+), 133 deletions(-) diff --git a/cs/HomeExercises/NumberValidatorTests.cs b/cs/HomeExercises/NumberValidatorTests.cs index a3772e5b..8b8ee6f5 100644 --- a/cs/HomeExercises/NumberValidatorTests.cs +++ b/cs/HomeExercises/NumberValidatorTests.cs @@ -5,20 +5,20 @@ namespace HomeExercises { - public class NumberValidatorTests - { - [Test] + public class NumberValidatorTests + { + [Test] public void Throws_WhenPrecisionNotPositive() { Action action = () => new NumberValidator(-1, 2, true); action.Should().Throw(); } - [Test] - public void Throws_WhenScaleNegative() - { - Action action = () => new NumberValidator(1, -1, true); - action.Should().Throw(); + [Test] + public void Throws_WhenScaleNegative() + { + Action action = () => new NumberValidator(1, -1, true); + action.Should().Throw(); } [Test] @@ -36,7 +36,7 @@ public void Fails_WhenNumberEmpty() result.Should().BeFalse(); } - [Test] + [Test] public void Fails_WhenNumberNotMatch() { var validator = new NumberValidator(8, 2, true); @@ -45,17 +45,17 @@ public void Fails_WhenNumberNotMatch() } [Test] - public void Success_WhenIntAndFractPartLessWhenPrecision() - { - var validator = new NumberValidator(17, 2, true); - var result = validator.IsValidNumber("0"); - result.Should().BeTrue(); + public void Success_WhenIntAndFractPartLessWhenPrecision() + { + var validator = new NumberValidator(17, 2, true); + var result = validator.IsValidNumber("0"); + result.Should().BeTrue(); } [Test] public void Fails_WhenPrecisionLessCountNumbers() { - var validator = new NumberValidator(3, 2, true); + var validator = new NumberValidator(3, 2, true); var result = validator.IsValidNumber("00.00"); result.Should().BeFalse(); } @@ -68,9 +68,9 @@ public void Fails_WhenPrecisionLessCountNumbersAndMinus() result.Should().BeFalse(); } - [Test] - public void Success_WhenPrecisionEqualsCountNumbersAndSign() - { + [Test] + public void Success_WhenPrecisionEqualsCountNumbersAndSign() + { var validator = new NumberValidator(4, 2, true); var result = validator.IsValidNumber("+1.23"); result.Should().BeTrue(); @@ -84,15 +84,15 @@ public void Fails_WhenScaleLessFractPartLength() result.Should().BeFalse(); } - [Test] - public void Fails_WhenLetters() - { + [Test] + public void Fails_WhenLetters() + { var validator = new NumberValidator(3, 2, true); var result = validator.IsValidNumber("a.sd"); result.Should().BeFalse(); } - [Test] + [Test] public void Fails_WhenOnlyPositiveAndNegativeNumber() { var validator = new NumberValidator(3, 2, true); @@ -101,51 +101,51 @@ public void Fails_WhenOnlyPositiveAndNegativeNumber() } } - public class NumberValidator - { - private readonly Regex numberRegex; - private readonly bool onlyPositive; - private readonly int precision; - private readonly int scale; - - 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"); - numberRegex = new Regex(@"^([+-]?)(\d+)([.,](\d+))?$", RegexOptions.IgnoreCase); - } - - public bool IsValidNumber(string value) - { - // Проверяем соответствие входного значения формату N(m,k), в соответствии с правилом, - // описанным в Формате описи документов, направляемых в налоговый орган в электронном виде по телекоммуникационным каналам связи: - // Формат числового значения указывается в виде N(m.к), где m – максимальное количество знаков в числе, включая знак (для отрицательного числа), - // целую и дробную часть числа без разделяющей десятичной точки, k – максимальное число знаков дробной части числа. - // Если число знаков дробной части числа равно 0 (т.е. число целое), то формат числового значения имеет вид N(m). - - if (string.IsNullOrEmpty(value)) - return false; - - var match = numberRegex.Match(value); - if (!match.Success) - return false; - - // Знак и целая часть - var intPart = match.Groups[1].Value.Length + match.Groups[2].Value.Length; - // Дробная часть - var fracPart = match.Groups[4].Value.Length; - - if (intPart + fracPart > precision || fracPart > scale) - return false; - - if (onlyPositive && match.Groups[1].Value == "-") - return false; - return true; - } - } + public class NumberValidator + { + private readonly Regex numberRegex; + private readonly bool onlyPositive; + private readonly int precision; + private readonly int scale; + + 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"); + numberRegex = new Regex(@"^([+-]?)(\d+)([.,](\d+))?$", RegexOptions.IgnoreCase); + } + + public bool IsValidNumber(string value) + { + // Проверяем соответствие входного значения формату N(m,k), в соответствии с правилом, + // описанным в Формате описи документов, направляемых в налоговый орган в электронном виде по телекоммуникационным каналам связи: + // Формат числового значения указывается в виде N(m.к), где m – максимальное количество знаков в числе, включая знак (для отрицательного числа), + // целую и дробную часть числа без разделяющей десятичной точки, k – максимальное число знаков дробной части числа. + // Если число знаков дробной части числа равно 0 (т.е. число целое), то формат числового значения имеет вид N(m). + + if (string.IsNullOrEmpty(value)) + return false; + + var match = numberRegex.Match(value); + if (!match.Success) + return false; + + // Знак и целая часть + var intPart = match.Groups[1].Value.Length + match.Groups[2].Value.Length; + // Дробная часть + var fracPart = match.Groups[4].Value.Length; + + if (intPart + fracPart > precision || fracPart > scale) + return false; + + if (onlyPositive && match.Groups[1].Value == "-") + return false; + return true; + } + } } \ No newline at end of file diff --git a/cs/HomeExercises/ObjectComparison.cs b/cs/HomeExercises/ObjectComparison.cs index bb89a711..da7a7ce3 100644 --- a/cs/HomeExercises/ObjectComparison.cs +++ b/cs/HomeExercises/ObjectComparison.cs @@ -3,76 +3,79 @@ namespace HomeExercises { - public class ObjectComparison - { - [Test] - [Description("Проверка текущего царя")] - [Category("ToRefactor")] - public void CheckCurrentTsar() - { - var actualTsar = TsarRegistry.GetCurrentTsar(); + public class ObjectComparison + { + [Test] + [Description("Проверка текущего царя")] + [Category("ToRefactor")] + public void CheckCurrentTsar() + { + var actualTsar = TsarRegistry.GetCurrentTsar(); - var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, - new Person("Vasili III of Russia", 28, 170, 60, null)); + var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, + new Person("Vasili III of Russia", 28, 170, 60, null)); - actualTsar.Should().BeEquivalentTo(expectedTsar, options => - options.Excluding(tsar => tsar.SelectedMemberPath.EndsWith("Id"))); - } + actualTsar.Should().BeEquivalentTo(expectedTsar, options => + options.Excluding(tsar => tsar.SelectedMemberPath.EndsWith("Id"))); + } - // Недостаток в том, что нужно будет переписывать тест при любом исправлении в классе Person. - // Возможно нужно добавить какое-то поле, или изменить название уже существующего, - // придется изменять каждый раз метод AreEqual, так же снижается читаемость теста - [Test] - [Description("Альтернативное решение. Какие у него недостатки?")] - public void CheckCurrentTsar_WithCustomEquality() - { - var actualTsar = TsarRegistry.GetCurrentTsar(); - var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, - new Person("Vasili III of Russia", 28, 170, 60, null)); + // Недостаток в том, что нужно будет переписывать тест при любом исправлении в классе Person. + // Возможно нужно добавить какое-то поле, или изменить название уже существующего, + // придется изменять каждый раз метод AreEqual, так же снижается читаемость теста, + // так как приходится разбираться еще в методе AreEqual + // Мое решение же лучше, потому что при добавлении новых полей нужно добавлять только те, + // которые необходимо игнорировать при сравнении классов, плюс гораздо локаничнее и читаемее + [Test] + [Description("Альтернативное решение. Какие у него недостатки?")] + public void CheckCurrentTsar_WithCustomEquality() + { + var actualTsar = TsarRegistry.GetCurrentTsar(); + var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, + new Person("Vasili III of Russia", 28, 170, 60, null)); - // Какие недостатки у такого подхода? - Assert.True(AreEqual(actualTsar, expectedTsar)); - } + // Какие недостатки у такого подхода? + Assert.True(AreEqual(actualTsar, expectedTsar)); + } - private bool AreEqual(Person? actual, Person? expected) - { - if (actual == expected) return true; - if (actual == null || expected == null) return false; - return - actual.Name == expected.Name - && actual.Age == expected.Age - && actual.Height == expected.Height - && actual.Weight == expected.Weight - && AreEqual(actual.Parent, expected.Parent); - } - } + private bool AreEqual(Person? actual, Person? expected) + { + if (actual == expected) return true; + if (actual == null || expected == null) return false; + return + actual.Name == expected.Name + && actual.Age == expected.Age + && actual.Height == expected.Height + && actual.Weight == expected.Weight + && AreEqual(actual.Parent, expected.Parent); + } + } - public class TsarRegistry - { - public static Person GetCurrentTsar() - { - return new Person( - "Ivan IV The Terrible", 54, 170, 70, - new Person("Vasili III of Russia", 28, 170, 60, null)); - } - } + public class TsarRegistry + { + public static Person GetCurrentTsar() + { + return new Person( + "Ivan IV The Terrible", 54, 170, 70, + new Person("Vasili III of Russia", 28, 170, 60, null)); + } + } - public class Person - { - public static int IdCounter = 0; - public int Age, Height, Weight; - public string Name; - public Person? Parent; - public int Id; + public class Person + { + public static int IdCounter = 0; + public int Age, Height, Weight; + public string Name; + public Person? Parent; + public int Id; - public Person(string name, int age, int height, int weight, Person? parent) - { - Id = IdCounter++; - Name = name; - Age = age; - Height = height; - Weight = weight; - Parent = parent; - } - } + public Person(string name, int age, int height, int weight, Person? parent) + { + Id = IdCounter++; + Name = name; + Age = age; + Height = height; + Weight = weight; + Parent = parent; + } + } } \ No newline at end of file From bae77d761c003853623778e9939f41d29c7308af Mon Sep 17 00:00:00 2001 From: fearppen Date: Mon, 27 Nov 2023 22:20:26 +0500 Subject: [PATCH 3/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=BF=D0=B5=D1=87=D0=B0=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B2=20NumberValidatorTests.cs,=20=D0=B8=D1=81=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=20=D0=B2=20ObjectComparison.cs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cs/HomeExercises/NumberValidatorTests.cs | 2 +- cs/HomeExercises/ObjectComparison.cs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cs/HomeExercises/NumberValidatorTests.cs b/cs/HomeExercises/NumberValidatorTests.cs index 8b8ee6f5..99fbc673 100644 --- a/cs/HomeExercises/NumberValidatorTests.cs +++ b/cs/HomeExercises/NumberValidatorTests.cs @@ -116,7 +116,7 @@ public NumberValidator(int precision, int scale = 0, bool onlyPositive = false) 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"); + throw new ArgumentException("precision must be a non-negative number, scale must be less or equal than precision"); numberRegex = new Regex(@"^([+-]?)(\d+)([.,](\d+))?$", RegexOptions.IgnoreCase); } diff --git a/cs/HomeExercises/ObjectComparison.cs b/cs/HomeExercises/ObjectComparison.cs index da7a7ce3..5221f6bb 100644 --- a/cs/HomeExercises/ObjectComparison.cs +++ b/cs/HomeExercises/ObjectComparison.cs @@ -11,12 +11,13 @@ public class ObjectComparison public void CheckCurrentTsar() { var actualTsar = TsarRegistry.GetCurrentTsar(); - var expectedTsar = new Person("Ivan IV The Terrible", 54, 170, 70, new Person("Vasili III of Russia", 28, 170, 60, null)); actualTsar.Should().BeEquivalentTo(expectedTsar, options => - options.Excluding(tsar => tsar.SelectedMemberPath.EndsWith("Id"))); + options + .Excluding(tsar => tsar.SelectedMemberInfo.Name == nameof(Person.Id)) + .AllowingInfiniteRecursion()); } // Недостаток в том, что нужно будет переписывать тест при любом исправлении в классе Person. @@ -25,6 +26,13 @@ public void CheckCurrentTsar() // так как приходится разбираться еще в методе AreEqual // Мое решение же лучше, потому что при добавлении новых полей нужно добавлять только те, // которые необходимо игнорировать при сравнении классов, плюс гораздо локаничнее и читаемее + // Если передать в тест царя, который ссылается сам на себя, то его выполнение будет прервано из-за + // Stack overflow, то есть переполнения стека рекурсии. + // FluentAssertions видит возможную циклическую ссылку объекта на самого себя и выдает ошибку + // Cyclic reference to type HomeExercises.Person detected + // При разных царях тест не показывает, в чем отличие и поэтому тяжело отловить ошибку, если же упадет тест + // с FluentAssertions, он показывает, где именно была ошибка и в чем она заключается + // например Expected member Age to be 53, but found 54. [Test] [Description("Альтернативное решение. Какие у него недостатки?")] public void CheckCurrentTsar_WithCustomEquality() @@ -54,8 +62,7 @@ public class TsarRegistry { public static Person GetCurrentTsar() { - return new Person( - "Ivan IV The Terrible", 54, 170, 70, + return new Person("Ivan IV The Terrible", 54, 170, 70, new Person("Vasili III of Russia", 28, 170, 60, null)); } } From 5bceaf944265c53eefda070a8675d4d96f00e584 Mon Sep 17 00:00:00 2001 From: fearppen Date: Tue, 28 Nov 2023 16:08:04 +0500 Subject: [PATCH 4/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=20=D0=B2=20Number?= =?UTF-8?q?ValidatorTests.cs,=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=8A=D0=B5=D0=B4=D0=B8=D0=BD=D0=B5=D0=BD=D1=8B=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B0=D0=BC.=20Regex-=D0=B2?= =?UTF-8?q?=D1=8B=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=20Num?= =?UTF-8?q?berValidator.cs=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B2=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=87=D0=B5?= =?UTF-8?q?=D1=81=D0=BA=D0=BE=D0=B5=20=D0=BF=D0=BE=D0=BB=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cs/HomeExercises/NumberValidatorTests.cs | 105 +++++------------------ cs/testing.sln | 13 +-- 2 files changed, 31 insertions(+), 87 deletions(-) diff --git a/cs/HomeExercises/NumberValidatorTests.cs b/cs/HomeExercises/NumberValidatorTests.cs index 99fbc673..0f498e89 100644 --- a/cs/HomeExercises/NumberValidatorTests.cs +++ b/cs/HomeExercises/NumberValidatorTests.cs @@ -7,103 +7,45 @@ namespace HomeExercises { public class NumberValidatorTests { - [Test] - public void Throws_WhenPrecisionNotPositive() + [TestCase(-1, 2, true, TestName = "CreateNumberValidator_PrecisionNotPositive_ThrowsArgumentException")] + [TestCase(1, -1, true, TestName = "CreateNumberValidator_ScaleNegative_ThrowsArgumentException")] + [TestCase(1, 2, true, TestName = "CreateNumberValidator_SacleBiggerPrecision_ThrowsArgumentException")] + public void Throws(int precision, int scale, bool onlyPostive) { - Action action = () => new NumberValidator(-1, 2, true); + Action action = () => new NumberValidator(precision, scale, onlyPostive); action.Should().Throw(); } - [Test] - public void Throws_WhenScaleNegative() + [TestCase(17, 2, true, " ", TestName = "IsValidNumber_NumberEmpty_Fails")] + [TestCase(8, 2, true, "1/43", TestName = "IsValidNumber_ValueNotMatch_Fails")] + [TestCase(3, 2, true, "00.00", TestName = "IsValidNumber_PrecisionLessCountNumbers_Fails")] + [TestCase(3, 2, false, "-0.00", TestName = "IsValidNumber_PrecisionLessCountNumbersAndSign_Fails")] + [TestCase(17, 2, true, "0.000", TestName = "IsValidNumber_ScaleLessFractPartLength_Fails")] + [TestCase(3, 2, true, "a.sd", TestName = "IsValidNumber_LettersInValue_Fails")] + [TestCase(3, 2, true, "-1.2", TestName = "IsValidNumber_OnlyPositiveTrueAndNegativeNumber_Fails")] + public void Fails(int precision, int scale, bool onlyPostive, string value) { - Action action = () => new NumberValidator(1, -1, true); - action.Should().Throw(); - } - - [Test] - public void Throws_WhenScaleBiggerPrecision() - { - Action action = () => new NumberValidator(1, 2, true); - action.Should().Throw(); - } - - [Test] - public void Fails_WhenNumberEmpty() - { - var validator = new NumberValidator(17, 2, true); - var result = validator.IsValidNumber(" "); + var validator = new NumberValidator(precision, scale, onlyPostive); + var result = validator.IsValidNumber(value); result.Should().BeFalse(); } - [Test] - public void Fails_WhenNumberNotMatch() - { - var validator = new NumberValidator(8, 2, true); - var result = validator.IsValidNumber("1/43"); - result.Should().BeFalse(); - } + [TestCase(17, 2, true, "0", TestName = "IsValidNumber_IntAndFractPartLessWhenPrecision_Success")] + [TestCase(4, 2, true, "+1.23", TestName = "IsValidNumber_PrecisionEqualsCountNumbersAndSign_Success")] + [TestCase(3, 2, true, "5,13", TestName = "IsValidNumber_PrecisionEqualsCountNumbers_Success")] + [TestCase(4, 2, true, "2.25", TestName = "IsValidNumber_PrecisionBiggerCountNumbers_Success")] - [Test] - public void Success_WhenIntAndFractPartLessWhenPrecision() + public void Success(int precision, int scale, bool onlyPostive, string value) { - var validator = new NumberValidator(17, 2, true); - var result = validator.IsValidNumber("0"); + var validator = new NumberValidator(precision, scale, onlyPostive); + var result = validator.IsValidNumber(value); result.Should().BeTrue(); } - - [Test] - public void Fails_WhenPrecisionLessCountNumbers() - { - var validator = new NumberValidator(3, 2, true); - var result = validator.IsValidNumber("00.00"); - result.Should().BeFalse(); - } - - [Test] - public void Fails_WhenPrecisionLessCountNumbersAndMinus() - { - var validator = new NumberValidator(3, 2, true); - var result = validator.IsValidNumber("-0.00"); - result.Should().BeFalse(); - } - - [Test] - public void Success_WhenPrecisionEqualsCountNumbersAndSign() - { - var validator = new NumberValidator(4, 2, true); - var result = validator.IsValidNumber("+1.23"); - result.Should().BeTrue(); - } - - [Test] - public void Fails_WhenScaleLessFractPartLength() - { - var validator = new NumberValidator(17, 2, true); - var result = validator.IsValidNumber("0.000"); - result.Should().BeFalse(); - } - - [Test] - public void Fails_WhenLetters() - { - var validator = new NumberValidator(3, 2, true); - var result = validator.IsValidNumber("a.sd"); - result.Should().BeFalse(); - } - - [Test] - public void Fails_WhenOnlyPositiveAndNegativeNumber() - { - var validator = new NumberValidator(3, 2, true); - var result = validator.IsValidNumber("-1.2"); - result.Should().BeFalse(); - } } public class NumberValidator { - private readonly Regex numberRegex; + private readonly static Regex numberRegex = new Regex(@"^([+-]?)(\d+)([.,](\d+))?$", RegexOptions.Compiled); private readonly bool onlyPositive; private readonly int precision; private readonly int scale; @@ -117,7 +59,6 @@ public NumberValidator(int precision, int scale = 0, bool onlyPositive = false) throw new ArgumentException("precision must be a positive number"); if (scale < 0 || scale >= precision) throw new ArgumentException("precision must be a non-negative number, scale must be less or equal than precision"); - numberRegex = new Regex(@"^([+-]?)(\d+)([.,](\d+))?$", RegexOptions.IgnoreCase); } public bool IsValidNumber(string value) diff --git a/cs/testing.sln b/cs/testing.sln index 4642966f..5d27b0c4 100644 --- a/cs/testing.sln +++ b/cs/testing.sln @@ -1,13 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26430.13 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34024.191 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples", "Samples\Samples.csproj", "{E7A56C48-8E36-465B-9F8E-67BC8525CFE5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples", "Samples\Samples.csproj", "{E7A56C48-8E36-465B-9F8E-67BC8525CFE5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HomeExercises", "HomeExercises\HomeExercises.csproj", "{4F9FBCCA-43E0-431B-944D-834D16AD18F9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HomeExercises", "HomeExercises\HomeExercises.csproj", "{4F9FBCCA-43E0-431B-944D-834D16AD18F9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Challenge", "Challenge\Challenge.csproj", "{BB8C2EFB-6AE9-45BD-8468-829D5AB79DCB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Challenge", "Challenge\Challenge.csproj", "{BB8C2EFB-6AE9-45BD-8468-829D5AB79DCB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -31,4 +31,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E4A3E5B6-B75B-4770-81B7-1EA62A1DF3F0} + EndGlobalSection EndGlobal From fe610a91a3f0cfa31944dfe6df73ca769e1668b2 Mon Sep 17 00:00:00 2001 From: fearppen Date: Wed, 29 Nov 2023 01:45:56 +0500 Subject: [PATCH 5/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B2=20ObjectCompar?= =?UTF-8?q?ison.cs.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=8B=20=D0=B2=20NumberValidatorTests.cs.=20=D0=92=D1=81?= =?UTF-8?q?=D0=B5=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B2=D1=8B=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=B5=D0=BD=D1=8B=20=D0=B2=20=D0=BE=D1=82=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cs/HomeExercises/NumberValidator.cs | 52 +++++++++++++++ cs/HomeExercises/NumberValidatorTests.cs | 83 +++++++----------------- cs/HomeExercises/ObjectComparison.cs | 31 +-------- cs/HomeExercises/Person.cs | 30 +++++++++ 4 files changed, 109 insertions(+), 87 deletions(-) create mode 100644 cs/HomeExercises/NumberValidator.cs create mode 100644 cs/HomeExercises/Person.cs diff --git a/cs/HomeExercises/NumberValidator.cs b/cs/HomeExercises/NumberValidator.cs new file mode 100644 index 00000000..655e2318 --- /dev/null +++ b/cs/HomeExercises/NumberValidator.cs @@ -0,0 +1,52 @@ +using System; +using System.Text.RegularExpressions; + +namespace HomeExercises +{ + public class NumberValidator + { + private readonly static Regex numberRegex = new Regex(@"^([+-]?)(\d+)([.,](\d+))?$", RegexOptions.Compiled); + private readonly bool onlyPositive; + private readonly int precision; + private readonly int scale; + + 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("scale must be a non-negative number, scale must be less or equal than precision"); + } + + public bool IsValidNumber(string value) + { + // Проверяем соответствие входного значения формату N(m,k), в соответствии с правилом, + // описанным в Формате описи документов, направляемых в налоговый орган в электронном виде по телекоммуникационным каналам связи: + // Формат числового значения указывается в виде N(m.к), где m – максимальное количество знаков в числе, включая знак (для отрицательного числа), + // целую и дробную часть числа без разделяющей десятичной точки, k – максимальное число знаков дробной части числа. + // Если число знаков дробной части числа равно 0 (т.е. число целое), то формат числового значения имеет вид N(m). + + if (string.IsNullOrEmpty(value)) + return false; + + var match = numberRegex.Match(value); + if (!match.Success) + return false; + + // Знак и целая часть + var intPart = match.Groups[1].Value.Length + match.Groups[2].Value.Length; + // Дробная часть + var fracPart = match.Groups[4].Value.Length; + + if (intPart + fracPart > precision || fracPart > scale) + return false; + + if (onlyPositive && match.Groups[1].Value == "-") + return false; + return true; + } + } +} diff --git a/cs/HomeExercises/NumberValidatorTests.cs b/cs/HomeExercises/NumberValidatorTests.cs index 0f498e89..bd3e0f79 100644 --- a/cs/HomeExercises/NumberValidatorTests.cs +++ b/cs/HomeExercises/NumberValidatorTests.cs @@ -1,28 +1,39 @@ -using System; -using System.Text.RegularExpressions; -using FluentAssertions; +using FluentAssertions; using NUnit.Framework; +using System; namespace HomeExercises { public class NumberValidatorTests { - [TestCase(-1, 2, true, TestName = "CreateNumberValidator_PrecisionNotPositive_ThrowsArgumentException")] - [TestCase(1, -1, true, TestName = "CreateNumberValidator_ScaleNegative_ThrowsArgumentException")] - [TestCase(1, 2, true, TestName = "CreateNumberValidator_SacleBiggerPrecision_ThrowsArgumentException")] + [TestCase(-1, 2, true, TestName = "Constructor_PrecisionNotPositive_ThrowsArgumentException")] + [TestCase(0, 1, true, TestName = "Constructor_PrecisionIsZero_ThrowsArgumentException")] + [TestCase(1, -1, true, TestName = "Constructor_ScaleNegative_ThrowsArgumentException")] + [TestCase(1, 2, true, TestName = "Constructor_SacleBiggerPrecision_ThrowsArgumentException")] + [TestCase(1, 1, true, TestName = "Constructor_ScaleEqualsPrecision_ThrowsArgumentException")] public void Throws(int precision, int scale, bool onlyPostive) { Action action = () => new NumberValidator(precision, scale, onlyPostive); action.Should().Throw(); } + [TestCase(2, 1, true, TestName = "Constructor_PrecisionBiggerScale_NotTrow")] + [TestCase(17, 2, false, TestName = "Constructor_OnlyPositiveFalse_NotTrow")] + public void NotTrow(int precision, int scale, bool onlyPostive) + { + Action action = () => new NumberValidator(precision, scale, onlyPostive); + action.Should().NotThrow(); + } + [TestCase(17, 2, true, " ", TestName = "IsValidNumber_NumberEmpty_Fails")] [TestCase(8, 2, true, "1/43", TestName = "IsValidNumber_ValueNotMatch_Fails")] [TestCase(3, 2, true, "00.00", TestName = "IsValidNumber_PrecisionLessCountNumbers_Fails")] [TestCase(3, 2, false, "-0.00", TestName = "IsValidNumber_PrecisionLessCountNumbersAndSign_Fails")] - [TestCase(17, 2, true, "0.000", TestName = "IsValidNumber_ScaleLessFractPartLength_Fails")] - [TestCase(3, 2, true, "a.sd", TestName = "IsValidNumber_LettersInValue_Fails")] + [TestCase(17, 2, true, "0.001", TestName = "IsValidNumber_ScaleLessFractPartLength_Fails")] + [TestCase(5, 4, true, "a.12", TestName = "IsValidNumber_LettersInValue_Fails")] + [TestCase(3, 2, true, ".12", TestName = "IsValidNumber_WithoutIntPart_Fails")] [TestCase(3, 2, true, "-1.2", TestName = "IsValidNumber_OnlyPositiveTrueAndNegativeNumber_Fails")] + [TestCase(3, 2, true, null, TestName = "IsValidNumber_ValueIsNull_Fails")] public void Fails(int precision, int scale, bool onlyPostive, string value) { var validator = new NumberValidator(precision, scale, onlyPostive); @@ -30,11 +41,14 @@ public void Fails(int precision, int scale, bool onlyPostive, string value) result.Should().BeFalse(); } - [TestCase(17, 2, true, "0", TestName = "IsValidNumber_IntAndFractPartLessWhenPrecision_Success")] [TestCase(4, 2, true, "+1.23", TestName = "IsValidNumber_PrecisionEqualsCountNumbersAndSign_Success")] - [TestCase(3, 2, true, "5,13", TestName = "IsValidNumber_PrecisionEqualsCountNumbers_Success")] + [TestCase(3, 2, true, "5.13", TestName = "IsValidNumber_PrecisionEqualsCountNumbers_Success")] [TestCase(4, 2, true, "2.25", TestName = "IsValidNumber_PrecisionBiggerCountNumbers_Success")] - + [TestCase(4, 2, true, "9999", TestName = "IsValidNumber_PrecisionEqualsIntPart_Success")] + [TestCase(17, 2, true, "0.23", TestName = "IsValidNumber_ScaleEqualsFractPart_Success")] + [TestCase(17, 3, true, "0.12", TestName = "IsValidNumber_ScaleBiggerFractPart_Success")] + [TestCase(4, 3, true, "1,1", TestName = "IsValidNumber_SeparatorIsComma_Success")] + [TestCase(5, 4, false, "-1.5", TestName = "IsValidNumber_NumberIsNegativeAndOnlyPositiveIsFalse_Fails")] public void Success(int precision, int scale, bool onlyPostive, string value) { var validator = new NumberValidator(precision, scale, onlyPostive); @@ -42,51 +56,4 @@ public void Success(int precision, int scale, bool onlyPostive, string value) result.Should().BeTrue(); } } - - public class NumberValidator - { - private readonly static Regex numberRegex = new Regex(@"^([+-]?)(\d+)([.,](\d+))?$", RegexOptions.Compiled); - private readonly bool onlyPositive; - private readonly int precision; - private readonly int scale; - - 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, scale must be less or equal than precision"); - } - - public bool IsValidNumber(string value) - { - // Проверяем соответствие входного значения формату N(m,k), в соответствии с правилом, - // описанным в Формате описи документов, направляемых в налоговый орган в электронном виде по телекоммуникационным каналам связи: - // Формат числового значения указывается в виде N(m.к), где m – максимальное количество знаков в числе, включая знак (для отрицательного числа), - // целую и дробную часть числа без разделяющей десятичной точки, k – максимальное число знаков дробной части числа. - // Если число знаков дробной части числа равно 0 (т.е. число целое), то формат числового значения имеет вид N(m). - - if (string.IsNullOrEmpty(value)) - return false; - - var match = numberRegex.Match(value); - if (!match.Success) - return false; - - // Знак и целая часть - var intPart = match.Groups[1].Value.Length + match.Groups[2].Value.Length; - // Дробная часть - var fracPart = match.Groups[4].Value.Length; - - if (intPart + fracPart > precision || fracPart > scale) - return false; - - if (onlyPositive && match.Groups[1].Value == "-") - return false; - return true; - } - } } \ No newline at end of file diff --git a/cs/HomeExercises/ObjectComparison.cs b/cs/HomeExercises/ObjectComparison.cs index 5221f6bb..618dd550 100644 --- a/cs/HomeExercises/ObjectComparison.cs +++ b/cs/HomeExercises/ObjectComparison.cs @@ -16,7 +16,8 @@ public void CheckCurrentTsar() actualTsar.Should().BeEquivalentTo(expectedTsar, options => options - .Excluding(tsar => tsar.SelectedMemberInfo.Name == nameof(Person.Id)) + .Excluding(tsar => tsar.SelectedMemberInfo.Name == nameof(Person.Id) && + tsar.SelectedMemberInfo.DeclaringType == typeof(Person)) .AllowingInfiniteRecursion()); } @@ -57,32 +58,4 @@ private bool AreEqual(Person? actual, Person? expected) && AreEqual(actual.Parent, expected.Parent); } } - - public class TsarRegistry - { - public static Person GetCurrentTsar() - { - return new Person("Ivan IV The Terrible", 54, 170, 70, - new Person("Vasili III of Russia", 28, 170, 60, null)); - } - } - - public class Person - { - public static int IdCounter = 0; - public int Age, Height, Weight; - public string Name; - public Person? Parent; - public int Id; - - public Person(string name, int age, int height, int weight, Person? parent) - { - Id = IdCounter++; - Name = name; - Age = age; - Height = height; - Weight = weight; - Parent = parent; - } - } } \ No newline at end of file diff --git a/cs/HomeExercises/Person.cs b/cs/HomeExercises/Person.cs new file mode 100644 index 00000000..48064234 --- /dev/null +++ b/cs/HomeExercises/Person.cs @@ -0,0 +1,30 @@ +namespace HomeExercises +{ + public class TsarRegistry + { + public static Person GetCurrentTsar() + { + return new Person("Ivan IV The Terrible", 54, 170, 70, + new Person("Vasili III of Russia", 28, 170, 60, null)); + } + } + + public class Person + { + public static int IdCounter = 0; + public int Age, Height, Weight; + public string Name; + public Person? Parent; + public int Id; + + public Person(string name, int age, int height, int weight, Person? parent) + { + Id = IdCounter++; + Name = name; + Age = age; + Height = height; + Weight = weight; + Parent = parent; + } + } +} From f1dd7f20743d93fc80df60cc7dc07aea58c477ca Mon Sep 17 00:00:00 2001 From: fearppen Date: Thu, 30 Nov 2023 00:19:02 +0500 Subject: [PATCH 6/7] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D1=8B=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=8B=20=D0=B2=20=D0=BE?= =?UTF-8?q?=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BA=D1=82.=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=BF=D0=B5=D1=87=D0=B0?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=B2=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B8=20=D1=82=D0=B5=D1=81=D1=82=D0=B0.=20=D0=98?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=20=D0=B2=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B5=20Person?= =?UTF-8?q?Tests.cs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HomeExercisesTests.csproj | 23 +++++++++++++++++++ .../NumberValidatorTests.cs | 6 ++--- .../PersonTests.cs} | 6 +++-- cs/testing.sln | 6 +++++ 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 cs/HomeExercisesTests/HomeExercisesTests.csproj rename cs/{HomeExercises => HomeExercisesTests}/NumberValidatorTests.cs (97%) rename cs/{HomeExercises/ObjectComparison.cs => HomeExercisesTests/PersonTests.cs} (96%) diff --git a/cs/HomeExercisesTests/HomeExercisesTests.csproj b/cs/HomeExercisesTests/HomeExercisesTests.csproj new file mode 100644 index 00000000..0b13cd33 --- /dev/null +++ b/cs/HomeExercisesTests/HomeExercisesTests.csproj @@ -0,0 +1,23 @@ + + + + net7.0 + enable + enable + + false + true + + + + + + + + + + + + + + diff --git a/cs/HomeExercises/NumberValidatorTests.cs b/cs/HomeExercisesTests/NumberValidatorTests.cs similarity index 97% rename from cs/HomeExercises/NumberValidatorTests.cs rename to cs/HomeExercisesTests/NumberValidatorTests.cs index bd3e0f79..a2072fd6 100644 --- a/cs/HomeExercises/NumberValidatorTests.cs +++ b/cs/HomeExercisesTests/NumberValidatorTests.cs @@ -1,8 +1,8 @@ using FluentAssertions; +using HomeExercises; using NUnit.Framework; -using System; -namespace HomeExercises +namespace HomeExercisesTests { public class NumberValidatorTests { @@ -48,7 +48,7 @@ public void Fails(int precision, int scale, bool onlyPostive, string value) [TestCase(17, 2, true, "0.23", TestName = "IsValidNumber_ScaleEqualsFractPart_Success")] [TestCase(17, 3, true, "0.12", TestName = "IsValidNumber_ScaleBiggerFractPart_Success")] [TestCase(4, 3, true, "1,1", TestName = "IsValidNumber_SeparatorIsComma_Success")] - [TestCase(5, 4, false, "-1.5", TestName = "IsValidNumber_NumberIsNegativeAndOnlyPositiveIsFalse_Fails")] + [TestCase(5, 4, false, "-1.5", TestName = "IsValidNumber_NumberIsNegativeAndOnlyPositiveIsFalse_Success")] public void Success(int precision, int scale, bool onlyPostive, string value) { var validator = new NumberValidator(precision, scale, onlyPostive); diff --git a/cs/HomeExercises/ObjectComparison.cs b/cs/HomeExercisesTests/PersonTests.cs similarity index 96% rename from cs/HomeExercises/ObjectComparison.cs rename to cs/HomeExercisesTests/PersonTests.cs index 618dd550..35aacb78 100644 --- a/cs/HomeExercises/ObjectComparison.cs +++ b/cs/HomeExercisesTests/PersonTests.cs @@ -1,7 +1,8 @@ using FluentAssertions; +using HomeExercises; using NUnit.Framework; -namespace HomeExercises +namespace HomeExercisesTests { public class ObjectComparison { @@ -18,7 +19,8 @@ public void CheckCurrentTsar() options .Excluding(tsar => tsar.SelectedMemberInfo.Name == nameof(Person.Id) && tsar.SelectedMemberInfo.DeclaringType == typeof(Person)) - .AllowingInfiniteRecursion()); + .AllowingInfiniteRecursion() + .IgnoringCyclicReferences()); } // Недостаток в том, что нужно будет переписывать тест при любом исправлении в классе Person. diff --git a/cs/testing.sln b/cs/testing.sln index 5d27b0c4..b283f126 100644 --- a/cs/testing.sln +++ b/cs/testing.sln @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HomeExercises", "HomeExerci EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Challenge", "Challenge\Challenge.csproj", "{BB8C2EFB-6AE9-45BD-8468-829D5AB79DCB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HomeExercisesTests", "HomeExercisesTests\HomeExercisesTests.csproj", "{9E01D71B-DDF5-45D3-8FE6-909C5BF92666}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {BB8C2EFB-6AE9-45BD-8468-829D5AB79DCB}.Debug|Any CPU.Build.0 = Debug|Any CPU {BB8C2EFB-6AE9-45BD-8468-829D5AB79DCB}.Release|Any CPU.ActiveCfg = Release|Any CPU {BB8C2EFB-6AE9-45BD-8468-829D5AB79DCB}.Release|Any CPU.Build.0 = Release|Any CPU + {9E01D71B-DDF5-45D3-8FE6-909C5BF92666}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9E01D71B-DDF5-45D3-8FE6-909C5BF92666}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9E01D71B-DDF5-45D3-8FE6-909C5BF92666}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9E01D71B-DDF5-45D3-8FE6-909C5BF92666}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 8ee02fbe06d6729cfc46b4c4d2bc3820da516bda Mon Sep 17 00:00:00 2001 From: fearppen Date: Thu, 30 Nov 2023 13:33:44 +0500 Subject: [PATCH 7/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=20HomeExercises.csproj,=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cs/HomeExercises/HomeExercises.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/cs/HomeExercises/HomeExercises.csproj b/cs/HomeExercises/HomeExercises.csproj index f8d97426..ba445b4c 100644 --- a/cs/HomeExercises/HomeExercises.csproj +++ b/cs/HomeExercises/HomeExercises.csproj @@ -10,11 +10,8 @@ - - - \ No newline at end of file