mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 22:55:42 +00:00
test: bring coverage to 100% for Drawing
This commit is contained in:
parent
8b4fd45e05
commit
9417ee6be1
@ -19,6 +19,22 @@ public class PolygonFTests
|
|||||||
Assert.AreEqual(0, PolygonF.Empty.VertexCount);
|
Assert.AreEqual(0, PolygonF.Empty.VertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerableOfPointF()
|
||||||
|
{
|
||||||
|
var polygon = PolygonF.Empty;
|
||||||
|
IEnumerable<PointF> vertices = null!;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => polygon.AddVertices(vertices));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector2()
|
||||||
|
{
|
||||||
|
var polygon = PolygonF.Empty;
|
||||||
|
IEnumerable<Vector2> vertices = null!;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => polygon.AddVertices(vertices));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ClearVertices_ShouldClearVertices()
|
public void ClearVertices_ShouldClearVertices()
|
||||||
{
|
{
|
||||||
@ -42,6 +58,20 @@ public class PolygonFTests
|
|||||||
Assert.AreEqual(2, pointPolygon.VertexCount);
|
Assert.AreEqual(2, pointPolygon.VertexCount);
|
||||||
Assert.AreEqual(2, vectorPolygon.VertexCount);
|
Assert.AreEqual(2, vectorPolygon.VertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfPointF()
|
||||||
|
{
|
||||||
|
IEnumerable<PointF> vertices = null!;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => new PolygonF(vertices));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector2()
|
||||||
|
{
|
||||||
|
IEnumerable<Vector2> vertices = null!;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => new PolygonF(vertices));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CopyConstructor_ShouldCopyVertices_GivenPolygon()
|
public void CopyConstructor_ShouldCopyVertices_GivenPolygon()
|
||||||
@ -61,6 +91,13 @@ public class PolygonFTests
|
|||||||
Assert.AreEqual(0, PolygonF.Empty.VertexCount);
|
Assert.AreEqual(0, PolygonF.Empty.VertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CopyConstructor_ShouldThrowArgumentNullException_GivenNullPolygonF()
|
||||||
|
{
|
||||||
|
PolygonF polygon = null!;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => new PolygonF(polygon));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Equals_ShouldBeTrue_GivenTwoEmptyPolygons()
|
public void Equals_ShouldBeTrue_GivenTwoEmptyPolygons()
|
||||||
{
|
{
|
||||||
@ -109,6 +146,12 @@ public class PolygonFTests
|
|||||||
Assert.IsTrue(second != first);
|
Assert.IsTrue(second != first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FromPolygon_ShouldThrowArgumentNullException_GivenNullPolygonF()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => PolygonF.FromPolygon(null!));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void IsConvex_ShouldBeFalse_GivenEmptyPolygon()
|
public void IsConvex_ShouldBeFalse_GivenEmptyPolygon()
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Numerics;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using X10D.Drawing;
|
using X10D.Drawing;
|
||||||
|
|
||||||
@ -19,6 +20,14 @@ public class PolygonTests
|
|||||||
Assert.AreEqual(0, Polygon.Empty.VertexCount);
|
Assert.AreEqual(0, Polygon.Empty.VertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerable()
|
||||||
|
{
|
||||||
|
var polygon = Polygon.Empty;
|
||||||
|
IEnumerable<Point> vertices = null!;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => polygon.AddVertices(vertices));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ClearVertices_ShouldClearVertices()
|
public void ClearVertices_ShouldClearVertices()
|
||||||
{
|
{
|
||||||
@ -33,6 +42,21 @@ public class PolygonTests
|
|||||||
Assert.AreEqual(0, polygon.VertexCount);
|
Assert.AreEqual(0, polygon.VertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Constructor_ShouldPopulateVertices_GivenPolygon()
|
||||||
|
{
|
||||||
|
var pointPolygon = new Polygon(new[] {new Point(1, 2), new Point(3, 4)});
|
||||||
|
|
||||||
|
Assert.AreEqual(2, pointPolygon.VertexCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfPoint()
|
||||||
|
{
|
||||||
|
IEnumerable<Point> vertices = null!;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => new Polygon(vertices));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CopyConstructor_ShouldCopyVertices_GivenPolygon()
|
public void CopyConstructor_ShouldCopyVertices_GivenPolygon()
|
||||||
{
|
{
|
||||||
@ -51,6 +75,13 @@ public class PolygonTests
|
|||||||
Assert.AreEqual(0, Polygon.Empty.VertexCount);
|
Assert.AreEqual(0, Polygon.Empty.VertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CopyConstructor_ShouldThrowArgumentNullException_GivenNullPolygon()
|
||||||
|
{
|
||||||
|
Polygon polygon = null!;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => new Polygon(polygon));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Equals_ShouldBeTrue_GivenTwoEmptyPolygons()
|
public void Equals_ShouldBeTrue_GivenTwoEmptyPolygons()
|
||||||
{
|
{
|
||||||
@ -99,6 +130,23 @@ public class PolygonTests
|
|||||||
Assert.IsTrue(second != first);
|
Assert.IsTrue(second != first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FromPolygonF_ShouldReturnEquivalentPolygon_GivenPolygon()
|
||||||
|
{
|
||||||
|
PolygonF hexagon = CreateHexagonF();
|
||||||
|
|
||||||
|
Polygon expected = CreateHexagon();
|
||||||
|
Polygon actual = Polygon.FromPolygonF(hexagon);
|
||||||
|
|
||||||
|
Assert.AreEqual(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FromPolygonF_ShouldThrowArgumentNullException_GivenNullPolygon()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => Polygon.FromPolygonF(null!));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void IsConvex_ShouldBeFalse_GivenEmptyPolygon()
|
public void IsConvex_ShouldBeFalse_GivenEmptyPolygon()
|
||||||
{
|
{
|
||||||
@ -155,6 +203,18 @@ public class PolygonTests
|
|||||||
return hexagon;
|
return hexagon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static PolygonF CreateHexagonF()
|
||||||
|
{
|
||||||
|
var hexagon = new PolygonF();
|
||||||
|
hexagon.AddVertex(new PointF(0, 0));
|
||||||
|
hexagon.AddVertex(new PointF(1, 0));
|
||||||
|
hexagon.AddVertex(new PointF(1, 1));
|
||||||
|
hexagon.AddVertex(new PointF(0, 1));
|
||||||
|
hexagon.AddVertex(new PointF(-1, 1));
|
||||||
|
hexagon.AddVertex(new PointF(-1, 0));
|
||||||
|
return hexagon;
|
||||||
|
}
|
||||||
|
|
||||||
internal static Polygon CreateConcavePolygon()
|
internal static Polygon CreateConcavePolygon()
|
||||||
{
|
{
|
||||||
var hexagon = new Polygon();
|
var hexagon = new Polygon();
|
||||||
|
@ -18,6 +18,14 @@ public class PolyhedronTests
|
|||||||
Assert.AreEqual(0, Polyhedron.Empty.VertexCount);
|
Assert.AreEqual(0, Polyhedron.Empty.VertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AddVertices_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector3()
|
||||||
|
{
|
||||||
|
var polygon = Polyhedron.Empty;
|
||||||
|
IEnumerable<Vector3> vertices = null!;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => polygon.AddVertices(vertices));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ClearVertices_ShouldClearVertices()
|
public void ClearVertices_ShouldClearVertices()
|
||||||
{
|
{
|
||||||
@ -39,6 +47,13 @@ public class PolyhedronTests
|
|||||||
Assert.AreEqual(2, polyhedron.VertexCount);
|
Assert.AreEqual(2, polyhedron.VertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Constructor_ShouldThrowArgumentNullException_GivenNullEnumerableOfVector3()
|
||||||
|
{
|
||||||
|
IEnumerable<Vector3> vertices = null!;
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => new Polyhedron(vertices));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CopyConstructor_ShouldCopyVertices_GivenPolyhedron()
|
public void CopyConstructor_ShouldCopyVertices_GivenPolyhedron()
|
||||||
{
|
{
|
||||||
@ -105,6 +120,18 @@ public class PolyhedronTests
|
|||||||
Assert.IsTrue(second != first);
|
Assert.IsTrue(second != first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FromPolygon_ShouldThrowArgumentNullException_GivenNullPolygonF()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => Polyhedron.FromPolygon(null!));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FromPolygonF_ShouldThrowArgumentNullException_GivenNullPolygonF()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentNullException>(() => Polyhedron.FromPolygonF(null!));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void op_Implicit_ShouldReturnEquivalentPolyhedron_GivenPolyhedron()
|
public void op_Implicit_ShouldReturnEquivalentPolyhedron_GivenPolyhedron()
|
||||||
{
|
{
|
||||||
|
@ -21,8 +21,22 @@ public class Polygon : IEquatable<Polygon>
|
|||||||
/// Initializes a new instance of the <see cref="Polygon" /> class by copying the specified polygon.
|
/// Initializes a new instance of the <see cref="Polygon" /> class by copying the specified polygon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Polygon(Polygon polygon)
|
public Polygon(Polygon polygon)
|
||||||
: this(polygon?._vertices ?? throw new ArgumentNullException(nameof(polygon)))
|
|
||||||
{
|
{
|
||||||
|
#if NET6_0_OR_GREATER
|
||||||
|
ArgumentNullException.ThrowIfNull(polygon);
|
||||||
|
#else
|
||||||
|
if (polygon is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(polygon));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_vertices = new List<Point>();
|
||||||
|
for (var index = 0; index < polygon._vertices.Count; index++)
|
||||||
|
{
|
||||||
|
Point vertex = polygon._vertices[index];
|
||||||
|
_vertices.Add(vertex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -31,6 +45,15 @@ public class Polygon : IEquatable<Polygon>
|
|||||||
/// <param name="vertices">An enumerable collection of vertices from which the polygon should be constructed.</param>
|
/// <param name="vertices">An enumerable collection of vertices from which the polygon should be constructed.</param>
|
||||||
public Polygon(IEnumerable<Point> vertices)
|
public Polygon(IEnumerable<Point> vertices)
|
||||||
{
|
{
|
||||||
|
#if NET6_0_OR_GREATER
|
||||||
|
ArgumentNullException.ThrowIfNull(vertices);
|
||||||
|
#else
|
||||||
|
if (vertices is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(vertices));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
_vertices = new List<Point>(vertices);
|
_vertices = new List<Point>(vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,21 @@ public class PolygonF
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="ArgumentNullException"><paramref name="polygon" /> is <see langword="null" />.</exception>
|
/// <exception cref="ArgumentNullException"><paramref name="polygon" /> is <see langword="null" />.</exception>
|
||||||
public PolygonF(PolygonF polygon)
|
public PolygonF(PolygonF polygon)
|
||||||
: this(polygon?._vertices ?? throw new ArgumentNullException(nameof(polygon)))
|
|
||||||
{
|
{
|
||||||
|
#if NET6_0_OR_GREATER
|
||||||
|
ArgumentNullException.ThrowIfNull(polygon);
|
||||||
|
#else
|
||||||
|
if (polygon is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(polygon));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
_vertices = new List<PointF>();
|
||||||
|
for (var index = 0; index < polygon._vertices.Count; index++)
|
||||||
|
{
|
||||||
|
PointF vertex = polygon._vertices[index];
|
||||||
|
_vertices.Add(vertex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -34,7 +47,6 @@ public class PolygonF
|
|||||||
/// <param name="vertices">An enumerable collection of vertices from which the polygon should be constructed.</param>
|
/// <param name="vertices">An enumerable collection of vertices from which the polygon should be constructed.</param>
|
||||||
/// <exception cref="ArgumentNullException"><paramref name="vertices" /> is <see langword="null" />.</exception>
|
/// <exception cref="ArgumentNullException"><paramref name="vertices" /> is <see langword="null" />.</exception>
|
||||||
public PolygonF(IEnumerable<Vector2> vertices)
|
public PolygonF(IEnumerable<Vector2> vertices)
|
||||||
: this(vertices.Select(p => p.ToPointF()))
|
|
||||||
{
|
{
|
||||||
#if NET6_0_OR_GREATER
|
#if NET6_0_OR_GREATER
|
||||||
ArgumentNullException.ThrowIfNull(vertices);
|
ArgumentNullException.ThrowIfNull(vertices);
|
||||||
@ -44,6 +56,12 @@ public class PolygonF
|
|||||||
throw new ArgumentNullException(nameof(vertices));
|
throw new ArgumentNullException(nameof(vertices));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
_vertices = new List<PointF>();
|
||||||
|
foreach (Vector2 vertex in vertices)
|
||||||
|
{
|
||||||
|
_vertices.Add(vertex.ToPointF());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user