From 61a4fe90b89cc127444405597a2590f8537474e5 Mon Sep 17 00:00:00 2001 From: Serghei Cebotari Date: Mon, 13 Nov 2023 22:40:23 +0300 Subject: Initial commit --- MindBox.Tests/CircleAreaCases.cs | 12 +++++++++++ MindBox.Tests/CircleCreateTests.cs | 16 ++++++++++++++ MindBox.Tests/FlatShapeAreaTests.cs | 11 ++++++++++ MindBox.Tests/MindBox.Tests.csproj | 23 ++++++++++++++++++++ MindBox.Tests/TriangleAreaCases.cs | 12 +++++++++++ MindBox.Tests/TriangleCreateTests.cs | 42 ++++++++++++++++++++++++++++++++++++ MindBox.Tests/Usings.cs | 2 ++ 7 files changed, 118 insertions(+) create mode 100644 MindBox.Tests/CircleAreaCases.cs create mode 100644 MindBox.Tests/CircleCreateTests.cs create mode 100644 MindBox.Tests/FlatShapeAreaTests.cs create mode 100644 MindBox.Tests/MindBox.Tests.csproj create mode 100644 MindBox.Tests/TriangleAreaCases.cs create mode 100644 MindBox.Tests/TriangleCreateTests.cs create mode 100644 MindBox.Tests/Usings.cs (limited to 'MindBox.Tests') diff --git a/MindBox.Tests/CircleAreaCases.cs b/MindBox.Tests/CircleAreaCases.cs new file mode 100644 index 0000000..ce4a8d3 --- /dev/null +++ b/MindBox.Tests/CircleAreaCases.cs @@ -0,0 +1,12 @@ +using System.Collections; + +namespace MindBox.Tests; + +public class CircleAreaCases : IEnumerable +{ + public IEnumerator GetEnumerator() + { + yield return new object[] { new Circle { Radius = 7.0 }, 153.93804 }; + yield return new object[] { new Circle { Radius = 15.0 }, 706.858347 }; + } +} diff --git a/MindBox.Tests/CircleCreateTests.cs b/MindBox.Tests/CircleCreateTests.cs new file mode 100644 index 0000000..b9cfd96 --- /dev/null +++ b/MindBox.Tests/CircleCreateTests.cs @@ -0,0 +1,16 @@ +namespace MindBox.Tests; + +public class CircleCreateTests +{ + [Test] + public void ZeroRadius() + { + Assert.Throws(() => new Circle { Radius = 0.0 }); + } + + [Test] + public void NegativeRadius() + { + Assert.Throws(() => new Circle { Radius = -1.0 }); + } +} diff --git a/MindBox.Tests/FlatShapeAreaTests.cs b/MindBox.Tests/FlatShapeAreaTests.cs new file mode 100644 index 0000000..9c4b5ca --- /dev/null +++ b/MindBox.Tests/FlatShapeAreaTests.cs @@ -0,0 +1,11 @@ +namespace MindBox.Tests; + +public class FlatShapeAreaTests +{ + [TestCaseSource(typeof(CircleAreaCases))] + [TestCaseSource(typeof(TriangleAreaCases))] + public void AreaTest(FlatShape shape, double area) + { + Assert.That(shape.GetArea(), Is.EqualTo(area).Within(1e-6)); + } +} diff --git a/MindBox.Tests/MindBox.Tests.csproj b/MindBox.Tests/MindBox.Tests.csproj new file mode 100644 index 0000000..ff54498 --- /dev/null +++ b/MindBox.Tests/MindBox.Tests.csproj @@ -0,0 +1,23 @@ + + + + net7.0 + enable + enable + + false + + + + + + + + + + + + + + + diff --git a/MindBox.Tests/TriangleAreaCases.cs b/MindBox.Tests/TriangleAreaCases.cs new file mode 100644 index 0000000..7a80fc0 --- /dev/null +++ b/MindBox.Tests/TriangleAreaCases.cs @@ -0,0 +1,12 @@ +using System.Collections; + +namespace MindBox.Tests; + +public class TriangleAreaCases : IEnumerable +{ + public IEnumerator GetEnumerator() + { + yield return new object[] { new Triangle(3.0, 4.0, 5.0), 6.0 }; + yield return new object[] { new Triangle(2.0, 2.0, 2.0), 1.732051 }; + } +} \ No newline at end of file diff --git a/MindBox.Tests/TriangleCreateTests.cs b/MindBox.Tests/TriangleCreateTests.cs new file mode 100644 index 0000000..1e498cc --- /dev/null +++ b/MindBox.Tests/TriangleCreateTests.cs @@ -0,0 +1,42 @@ +namespace MindBox.Tests; + +public class TriangleCreateTests +{ + [TestCase(-1.0, 1.0, 1.0)] + [TestCase(1.0, -1.0, 1.0)] + [TestCase(1.0, 1.0, -1.0)] + public void NegativeSide(double a, double b, double c) + { + Assert.Throws(() => new Triangle(a, b, c)); + } + + [TestCase(0.0, 1.0, 1.0)] + [TestCase(1.0, 0.0, 1.0)] + [TestCase(1.0, 1.0, 0.0)] + public void ZeroSide(double a, double b, double c) + { + Assert.Throws(() => new Triangle(a, b, c)); + } + + [TestCase(4, 5, 9)] + [TestCase(4, 5, 10)] + public void WrongSides(double a, double b, double c) + { + Assert.Throws(() => new Triangle(a, b, c)); + } +} + +public class TriangleRightTests +{ + [Test] + public void IsRight() + { + Assert.IsTrue(new Triangle(3.0, 4.0, 5.0).IsRight()); + } + + [Test] + public void IsNotRight() + { + Assert.IsFalse(new Triangle(1.0, 1.0, 1.0).IsRight()); + } +} \ No newline at end of file diff --git a/MindBox.Tests/Usings.cs b/MindBox.Tests/Usings.cs new file mode 100644 index 0000000..8534c8d --- /dev/null +++ b/MindBox.Tests/Usings.cs @@ -0,0 +1,2 @@ +global using NUnit.Framework; +global using MindBox.Lib; \ No newline at end of file -- cgit v1.2.3