aboutsummaryrefslogtreecommitdiff
path: root/MindBox.Tests
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2023-11-13 22:40:23 +0300
committerSerghei Cebotari <serghei@cebotari.ru>2023-11-13 22:40:23 +0300
commit61a4fe90b89cc127444405597a2590f8537474e5 (patch)
tree44bfa66169cba2a7f2b79d959bf762b5e9bdeaa2 /MindBox.Tests
Initial commit
Diffstat (limited to 'MindBox.Tests')
-rw-r--r--MindBox.Tests/CircleAreaCases.cs12
-rw-r--r--MindBox.Tests/CircleCreateTests.cs16
-rw-r--r--MindBox.Tests/FlatShapeAreaTests.cs11
-rw-r--r--MindBox.Tests/MindBox.Tests.csproj23
-rw-r--r--MindBox.Tests/TriangleAreaCases.cs12
-rw-r--r--MindBox.Tests/TriangleCreateTests.cs42
-rw-r--r--MindBox.Tests/Usings.cs2
7 files changed, 118 insertions, 0 deletions
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<ArgumentException>(() => new Circle { Radius = 0.0 });
+ }
+
+ [Test]
+ public void NegativeRadius()
+ {
+ Assert.Throws<ArgumentException>(() => 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 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net7.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+
+ <IsPackable>false</IsPackable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
+ <PackageReference Include="NUnit" Version="3.13.3" />
+ <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
+ <PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
+ <PackageReference Include="coverlet.collector" Version="3.1.2" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\MindBox.Lib\MindBox.Lib.csproj" />
+ </ItemGroup>
+
+</Project>
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<ArgumentException>(() => 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<ArgumentException>(() => new Triangle(a, b, c));
+ }
+
+ [TestCase(4, 5, 9)]
+ [TestCase(4, 5, 10)]
+ public void WrongSides(double a, double b, double c)
+ {
+ Assert.Throws<ArgumentException>(() => 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