102 lines
2.9 KiB
C#
102 lines
2.9 KiB
C#
using SampleApplication.Entities;
|
|
|
|
namespace SampleApplication.Tests
|
|
{
|
|
public class ShapeProcessTest
|
|
{
|
|
[Fact]
|
|
public void Rectangle_Calculation_IsCorrect()
|
|
{
|
|
var processor = new SampleApplication.ShapeProcessor();
|
|
|
|
var rectangle = new ShapeInput
|
|
{
|
|
Id = 1,
|
|
Type = ShapeType.Rectangle,
|
|
Dimensions = new[] { 10.0, 5.0 }
|
|
};
|
|
|
|
processor.AddShapes(new[] { rectangle });
|
|
|
|
var (area, perimeter) = processor.GetResult(rectangle.Id);
|
|
|
|
Assert.Equal(50.0, area, 2);
|
|
Assert.Equal(30.0, perimeter, 2);
|
|
}
|
|
|
|
[Fact]
|
|
public void Circle_Calculation_IsCorrect()
|
|
{
|
|
var processor = new SampleApplication.ShapeProcessor();
|
|
|
|
var circle = new ShapeInput
|
|
{
|
|
Id = 1,
|
|
Type = ShapeType.Circle,
|
|
Dimensions = new[] { 7.0 }
|
|
};
|
|
|
|
processor.AddShapes(new[] { circle });
|
|
|
|
var (area, perimeter) = processor.GetResult(circle.Id);
|
|
|
|
Assert.Equal(153.94, area, 2);
|
|
Assert.Equal(43.98, perimeter, 2);
|
|
}
|
|
|
|
[Fact]
|
|
public void Triangle_Calculation_IsCorrect()
|
|
{
|
|
var processor = new SampleApplication.ShapeProcessor();
|
|
|
|
var triangle = new ShapeInput
|
|
{
|
|
Id = 1,
|
|
Type = ShapeType.Triangle,
|
|
Dimensions = new[] { 3.0, 4.0 }
|
|
};
|
|
|
|
processor.AddShapes(new[] { triangle });
|
|
|
|
var (area, perimeter) = processor.GetResult(triangle.Id);
|
|
|
|
Assert.Equal(6.00, area, 2);
|
|
Assert.Equal(12.00, perimeter, 2);
|
|
}
|
|
|
|
[Fact]
|
|
public void Invalid_Dimensions_Throws()
|
|
{
|
|
var processor = new SampleApplication.ShapeProcessor();
|
|
|
|
Assert.Throws<ArgumentException>(() =>
|
|
processor.AddShapes(new[]
|
|
{
|
|
new ShapeInput
|
|
{
|
|
Id = 1,
|
|
Type = ShapeType.Rectangle,
|
|
Dimensions = new[] { -1.0, 2.0 }
|
|
}
|
|
})
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public void Statistics_AreCorrect()
|
|
{
|
|
var processor = new SampleApplication.ShapeProcessor();
|
|
var shapes = new[]
|
|
{
|
|
new ShapeInput { Id = 1, Type = ShapeType.Rectangle, Dimensions = new[] { 2.0, 3.0 } },
|
|
new ShapeInput { Id = 2, Type = ShapeType.Circle, Dimensions = new[] { 3.0 } }
|
|
};
|
|
processor.AddShapes(shapes);
|
|
var (totalShapes, totalArea, maxPerimeterId) = processor.GetStatistics();
|
|
Assert.Equal(2, totalShapes);
|
|
Assert.Equal(34.27,totalArea, 2);
|
|
Assert.Equal(2, maxPerimeterId);
|
|
}
|
|
}
|
|
}
|