Ejemplo n.º 1
0
 public void CalculatePolygonArea_Should_Return_CorrectArea()
 {
     Assert.Equal(0, AreasCalculator.CalculatePolygonArea(Array.Empty <Point>()));
     Assert.Equal(0, AreasCalculator.CalculatePolygonArea(new Point(0, 0), new Point(3, 3)));
     Assert.Equal(4.5, AreasCalculator.CalculatePolygonArea(new Point(0, 0), new Point(0, 3), new Point(3, 3)));
     Assert.Equal(9, AreasCalculator.CalculatePolygonArea(new Point(0, 0), new Point(0, 3), new Point(3, 3), new Point(3, 0)));
     Assert.Equal(18, AreasCalculator.CalculatePolygonArea(new Point(-3, -3), new Point(-3, 3), new Point(3, 3)));
 }
Ejemplo n.º 2
0
        public async Task <ActionResult <Figure> > CreateTriangleAsync(
            [FromBody] CreateTriangleRequest request,
            CancellationToken cancellationToken)
        {
            var entity = new Db.Entities.Figure
            {
                FigureType = "triangle",
                Object     = JsonSerializer.Serialize(request),
                Area       = AreasCalculator.CalculatePolygonArea(
                    new Point(request.Vertex1.X, request.Vertex1.Y),
                    new Point(request.Vertex2.X, request.Vertex2.Y),
                    new Point(request.Vertex3.X, request.Vertex3.Y))
            };

            await _dbContext.Figures.AddAsync(entity, cancellationToken);

            await _dbContext.SaveChangesAsync(cancellationToken);

            return(await GetFigureAsync(entity.FigureId, cancellationToken));
        }
Ejemplo n.º 3
0
 public void CalculatePolygonArea_Should_Handle_NullParameter()
 {
     Assert.Throws <ArgumentNullException>(() => AreasCalculator.CalculatePolygonArea(Array.Empty <Point>()));
     Assert.Throws <ArgumentNullException>(() => AreasCalculator.CalculatePolygonArea(null));
 }