-
Notifications
You must be signed in to change notification settings - Fork 282
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
Трофимов Никита #239
base: master
Are you sure you want to change the base?
Трофимов Никита #239
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,9 @@ | ||
using System; | ||
using System.Diagnostics.SymbolStore; | ||
using System.Text.RegularExpressions; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Internal; | ||
|
||
|
||
namespace HomeExercises | ||
{ | ||
public class NumberValidatorTests | ||
{ | ||
[Test] | ||
[TestCase(-1, 2, true, TestName = "Creation_ShouldThrowArgumentException_WhenNegativePrecision")] | ||
[TestCase(0,0,true, TestName = "Creation_ShouldThrowArgumentException_WhenPrecisionIsZero")] | ||
[TestCase(3,-1,true, TestName = "Creation_ShouldThrowArgumentException_WhenNegativeScale")] | ||
[TestCase(1,2,true, TestName = "Creation_ShouldThrowArgumentException_WhenScaleIsGreaterThanPrecision")] | ||
public void Creation_ShouldThrowArgumentException(int precision, int scale, bool onlyPositive) | ||
{ | ||
Action creation = () => new NumberValidator(precision, scale, onlyPositive); | ||
creation.Should().Throw<ArgumentException>(); | ||
} | ||
|
||
[Test] | ||
[TestCase(1, 0, true, TestName = "Creation_ShouldDoesNotThrow_WhenCorrectValue")] | ||
public void Creation_ShouldDoesNotThrow(int precision, int scale, bool onlyPositive) | ||
{ | ||
Action creation = () => new NumberValidator(precision, scale, onlyPositive); | ||
creation.Should().NotThrow<ArgumentException>(); | ||
} | ||
|
||
[Test] | ||
[TestCase(3,2,true, "-+0.0", TestName = "IsValidNumber_ReturnsFalseWhenTwoSigns")] | ||
[TestCase(3,2,true, " -0.0", TestName = "IsValidNumber_ReturnsFalseWhenSpaceFirstDigitInNumber")] | ||
[TestCase(3,2,true, "0,", TestName ="IsValidNumber_ReturnsFalseWhenAren'tDigitsAfterCommas")] | ||
[TestCase(3,2,true, "0.0.0", TestName = "IsValidNumber_ReturnsFalseWhenThreeDigitsInNumberByTwoDots")] | ||
[TestCase(3,2,true, "0,0,0", TestName = "IsValidNumber_ReturnsFalseWhenThreeDigitsInNumberByTwoCommas")] | ||
[TestCase(3, 2, true, "00.00", TestName = "IsValidNumber_ReturnsFalseWhenNumberPrecisionGreaterThanValidatorPrecision")] | ||
[TestCase(3, 2, true, null, TestName = "IsValidNumber_ReturnsFalseWhenNumberNull")] | ||
[TestCase(3, 2, true, "", TestName = "IsValidNumber_ReturnsFalseWhenNumberEmpty")] | ||
[TestCase(3, 2, true, "+1.23", TestName = "IsValidNumber_ReturnsFalseWhenNumberPrecisionGreaterThanValidatorPrecision")] | ||
[TestCase(3, 2, true, "-1.23", TestName = "IsValidNumber_ReturnsFalseWhenNumberNegativeInNumberOnlyPositive")] | ||
[TestCase(17, 2, true, "0.000", TestName = "IsValidNumber_ReturnsFalseWhenNumberScaleGreaterThanValidatorScale")] | ||
[TestCase(17, 2, true, "a.sd", TestName = "IsValidNumber_ReturnsFalseWhenIncorrectNumberFormatBecauseLettersArePresent")] | ||
public void IsValidNumber_False(int precision, int scale, bool onlyPositive, string number) | ||
{ | ||
NumberValidator validator = new NumberValidator(precision, scale, onlyPositive); | ||
validator.IsValidNumber(number).Should().BeFalse(); | ||
} | ||
[Test] | ||
[TestCase(17, 2, true, "0.0", TestName = "IsValidNumber_ReturnTrueWhenNumberWithFractionalPart")] | ||
[TestCase(17, 2, true, "0", TestName = "IsValidNumber_ReturnTrueWhenOnlyInteger")] | ||
[TestCase(4, 2, true, "+1.23", TestName = "IsValidNumber_ReturnTrueWhenNumberWithSign")] | ||
public void IsValidNumber_True(int precision, int scale, bool onlyPositive, string number) | ||
{ | ||
NumberValidator validator = new NumberValidator(precision, scale, onlyPositive); | ||
validator.IsValidNumber(number).Should().BeTrue(); | ||
} | ||
} | ||
|
||
public class NumberValidator | ||
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. Файл все ещё называется |
||
{ | ||
private readonly Regex numberRegex; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,5 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace HomeExercises | ||
namespace HomeExercises | ||
{ | ||
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)); | ||
|
||
actualTsar.Should().BeEquivalentTo(expectedTsar, options => options | ||
.Excluding(tsar => tsar.Parent) | ||
.Excluding(tsar => tsar.Id)); | ||
} | ||
|
||
[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)); | ||
|
||
//Какие недостатки у такого подхода? | ||
//Нужно будет переписывать AreEqual в случае изменения полей Person | ||
//Возможна ошибка при написании метода | ||
//Если тест упадет, сообщение об ошибке будет малоинформативным | ||
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); | ||
} | ||
} | ||
|
||
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 | ||
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. И тут название файла не совпадает с названием класса |
||
{ | ||
public static int IdCounter = 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace HomeExercises.tests | ||
{ | ||
public class NumberValidator_Should | ||
{ | ||
[TestCase(-1, 2, TestName = "NegativePrecision")] | ||
[TestCase(0, 0, TestName = "PrecisionIsZero")] | ||
[TestCase(3, -1, TestName = "NegativeScale")] | ||
[TestCase(1, 2, TestName = "ScaleIsGreaterThanPrecision")] | ||
[TestCase(1, 1, TestName = "PrecisionEqualsScale")] | ||
public void Creation_ShouldThrowArgumentException(int precision, int scale) | ||
{ | ||
Action creation = () => new NumberValidator(precision, scale); | ||
creation.Should().Throw<ArgumentException>(); | ||
} | ||
|
||
[Test] | ||
public void Creation_ShouldNotThrow() | ||
{ | ||
Action creation = () => new NumberValidator(1, 0); | ||
creation | ||
.Should() | ||
.NotThrow<Exception>(); | ||
|
||
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. Лишняя строка пустая |
||
} | ||
|
||
[TestCase(3, 2,"-+0.0", TestName = "TwoSigns")] | ||
[TestCase(3, 2," -0.0", TestName = "SpaceFirstDigitInNumber")] | ||
[TestCase(3, 2,"0,", TestName ="Aren'tDigitsAfterCommas")] | ||
[TestCase(3, 2,"0.0.0", TestName = "ThreeDigitsInNumberByTwoDots")] | ||
[TestCase(3, 2,"0,0,0", TestName = "ThreeDigitsInNumberByTwoCommas")] | ||
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. Снова форматирование уехало |
||
[TestCase(3, 2, "00.00", TestName = "NumberPrecisionGreaterThanValidatorPrecision")] | ||
[TestCase(3, 2, null, TestName = "NumberNull")] | ||
[TestCase(3, 2, "", TestName = "NumberEmpty")] | ||
[TestCase(3, 2, "+1.23", TestName = "NumberPrecisionGreaterThanValidatorPrecision")] | ||
[TestCase(3, 2, "-1.23", TestName = "NumberNegativeInNumberOnlyPositive")] | ||
[TestCase(17, 2, "0.000", TestName = "NumberScaleGreaterThanValidatorScale")] | ||
[TestCase(17, 2, "a.sd", TestName = "IncorrectNumberFormatBecauseLettersArePresent")] | ||
public void IsValidNumber_False(int precision, int scale, string number) | ||
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. Все ещё нет глагола перед False и True тут и ниже, вспомни про порядок именований в тестах
|
||
{ | ||
var validator = new NumberValidator(precision, scale); | ||
validator.IsValidNumber(number).Should().BeFalse(); | ||
} | ||
|
||
[TestCase(17, 2, "0.0", TestName = "NumberWithFractionalPart")] | ||
[TestCase(17, 2, "0", TestName = "OnlyInteger")] | ||
[TestCase(4, 2, "+1.23", TestName = "NumberWithSign")] | ||
public void IsValidNumber_True(int precision, int scale, string number) | ||
{ | ||
var validator = new NumberValidator(precision, scale); | ||
validator.IsValidNumber(number).Should().BeTrue(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
|
||
namespace HomeExercises.tests | ||
{ | ||
public class ObjectComparsion_Should | ||
{ | ||
[Test] | ||
[Description("Проверка текущего царя")] | ||
[Category("ToRefactor")] | ||
public void CheckValuesOfTheCurrentTsar() | ||
{ | ||
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.SelectedMemberInfo.Name == nameof(Person.Id) | ||
&& tsar.SelectedMemberInfo.DeclaringType == typeof(Person))); | ||
} | ||
|
||
[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)); | ||
|
||
//Какие недостатки у такого подхода? | ||
//Нужно будет переписывать AreEqual в случае изменения полей Person | ||
//Возможна ошибка при написании метода | ||
//Если тест упадет, сообщение об ошибке будет малоинформативным | ||
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); | ||
} | ||
} | ||
|
||
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)); | ||
} | ||
} | ||
} |
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.
Тоже лишняя пустая строка