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

Конина Анастасия #247

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 35 additions & 18 deletions cs/HomeExercises/NumberValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,44 @@ namespace HomeExercises
{
public class NumberValidatorTests
{
[Test]
public void Test()
[TestCase(-1, 2, true)]
[TestCase(10, -2, true)]
[TestCase(10, 10, true)]
[TestCase(10, 11, true)]
public void ThrowsIfNotValid(int prescision, int scale, bool onlyPositive)
{
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));
Assert.Throws<ArgumentException>(() => new NumberValidator(prescision, scale, onlyPositive));
}

[TestCase(1, 0, true)]
public void DoesNotThrows(int prescision, int scale, bool onlyPositive)
{
Assert.DoesNotThrow(() => new NumberValidator(prescision, scale, onlyPositive));
}

[TestCase(3, 2, true, "00.00")]
[TestCase(3, 2, true, "-0.00")]
[TestCase(3, 2, true, "+1.23")]
[TestCase(17, 2, true, "0.000")]
[TestCase(3, 2, true, "a.sd")]
[TestCase(10, 2, true, "-0.00")]
[TestCase(10, 2, true, "")]
public void NotValidNumber(int prescision, int scale, bool onlyPositive, string value)
{
Assert.IsFalse(new NumberValidator(prescision, scale, onlyPositive).IsValidNumber(value));
}

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"));
[TestCase(17, 2, true, "0.0")]
[TestCase(17, 2, true, "0")]
[TestCase(4, 2, true, "+1.23")]
[TestCase(10, 2, false, "-0.00")]
[TestCase(10, 2, false, "0.00")]
[TestCase(10, 2, false, "0,00")]
public void ValidNumber(int prescision, int scale, bool onlyPositive, string value)
{
Assert.IsTrue(new NumberValidator(prescision, scale, onlyPositive).IsValidNumber(value));
}

}

public class NumberValidator
Expand Down
16 changes: 8 additions & 8 deletions cs/HomeExercises/ObjectComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ public void CheckCurrentTsar()
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);
expectedTsar.Should().BeEquivalentTo(actualTsar, options =>
options.Excluding(o => o.Parent!.Id)
.Excluding(o => o.Id));

actualTsar.Parent.Should().BeEquivalentTo(expectedTsar.Parent, options =>
options.Excluding(o => o!.Parent!.Id)
.Excluding(o => o!.Id));
}

[Test]
Expand All @@ -36,6 +35,7 @@ public void CheckCurrentTsar_WithCustomEquality()
new Person("Vasili III of Russia", 28, 170, 60, null));

// Какие недостатки у такого подхода?
//Код нерасширяем, потому что если в классе Person появятся новые поля, они не будут учитываться в этом методе
Assert.True(AreEqual(actualTsar, expectedTsar));
}

Expand Down