Ejemplo n.º 1
0
        public void HeightAndWidthZero_AreaZero()
        {
            RectangleAreaCalculator rectangleAreaCalculator = new RectangleAreaCalculator();
            int rectangleArea = rectangleAreaCalculator.RectangleArea(0, 0);

            Assert.Equal(0, rectangleArea);
        }
Ejemplo n.º 2
0
        public void HeightAndWidthPositive_Works()
        {
            RectangleAreaCalculator rectangleAreaCalculator = new RectangleAreaCalculator();
            int rectangleArea = rectangleAreaCalculator.RectangleArea(10, 5);

            Assert.Equal(10 * 5, rectangleArea);
        }
Ejemplo n.º 3
0
        public FigureAreaResult CalculateArea(FormData formData)
        {
            FigureAreaResult resultOfCalculation = new FigureAreaResult();

            resultOfCalculation.Successful = true;
            string sizes = formData.Sizes;

            try
            {
                if (formData.Sizes.Contains(","))
                {
                    sizes = formData.Sizes.Replace(',', '.');
                }

                string[] sizesFromUser = sizes.Split(new Char[] { ';' });
                switch (formData.ChosenFigure)
                {
                case FiguresEN.Square:
                    Square square = new Square()
                    {
                        Name  = FiguresPL.Kwadrat.ToString(),
                        SizeA = Convert.ToDouble(sizesFromUser[0])
                    };
                    SquareAreaCalculator squareAreaCalculator = new SquareAreaCalculator();
                    resultOfCalculation.Figure = square;
                    resultOfCalculation.Result = squareAreaCalculator.AreaCalculator(square);
                    break;

                case FiguresEN.Rectangle:
                    Rectangle rectangle = new Rectangle()
                    {
                        Name  = FiguresPL.Prostokąt.ToString(),
                        SizeA = Convert.ToDouble(sizesFromUser[0]),
                        SizeB = Convert.ToDouble(sizesFromUser[1])
                    };
                    RectangleAreaCalculator rectangleAreaCalculator = new RectangleAreaCalculator();
                    resultOfCalculation.Figure = rectangle;
                    resultOfCalculation.Result = rectangleAreaCalculator.AreaCalculator(rectangle);
                    break;

                case FiguresEN.Parallelogram:
                    Parallelogram parallelogram = new Parallelogram()
                    {
                        Name  = FiguresPL.Równoległobok.ToString(),
                        SizeA = Convert.ToDouble(sizesFromUser[0]),
                        SizeH = Convert.ToDouble(sizesFromUser[1])
                    };
                    ParallelogramAreaCalculator parallelogramAreaCalculator = new ParallelogramAreaCalculator();
                    resultOfCalculation.Figure = parallelogram;
                    resultOfCalculation.Result = parallelogramAreaCalculator.AreaCalculator(parallelogram);
                    break;

                case FiguresEN.Rhombus:
                    Rhombus rhombus = new Rhombus()
                    {
                        Name  = FiguresPL.Romb.ToString(),
                        SizeA = Convert.ToDouble(sizesFromUser[0]),
                        SizeH = Convert.ToDouble(sizesFromUser[1])
                    };
                    RhombusAreaCalculator rhombusAreaCalculator = new RhombusAreaCalculator();
                    resultOfCalculation.Figure = rhombus;
                    resultOfCalculation.Result = rhombusAreaCalculator.AreaCalculator(rhombus);
                    break;

                case FiguresEN.Trapeze:
                    Trapeze trapeze = new Trapeze()
                    {
                        Name  = FiguresPL.Trapez.ToString(),
                        SizeA = Convert.ToDouble(sizesFromUser[0]),
                        SizeB = Convert.ToDouble(sizesFromUser[1]),
                        SizeH = Convert.ToDouble(sizesFromUser[2])
                    };
                    TrapezeAreaCalculator trapezeAreaCalculator = new TrapezeAreaCalculator();
                    resultOfCalculation.Figure = trapeze;
                    resultOfCalculation.Result = trapezeAreaCalculator.AreaCalculator(trapeze);
                    break;

                case FiguresEN.Triangle:
                    Triangle triangle = new Triangle()
                    {
                        Name  = FiguresPL.Trójkąt.ToString(),
                        SizeA = Convert.ToDouble(sizesFromUser[0]),
                        SizeH = Convert.ToDouble(sizesFromUser[1])
                    };
                    TriangleAreaCalculator triangleAreaCalculator = new TriangleAreaCalculator();
                    resultOfCalculation.Figure = triangle;
                    resultOfCalculation.Result = triangleAreaCalculator.AreaCalculator(triangle);
                    break;

                case FiguresEN.Circle:
                    Circle circle = new Circle()
                    {
                        Name   = FiguresPL.Koło.ToString(),
                        Radius = Convert.ToDouble(sizesFromUser[0])
                    };
                    CircleAreaCalculator circleAreaCalculator = new CircleAreaCalculator();
                    resultOfCalculation.Figure = circle;
                    resultOfCalculation.Result = circleAreaCalculator.AreaCalculator(circle);
                    break;
                }
            }
            catch (FormatException)
            {
                resultOfCalculation.Exception  = new FormatException();
                resultOfCalculation.Successful = false;
            }
            catch (IndexOutOfRangeException)
            {
                resultOfCalculation.Exception  = new IndexOutOfRangeException();
                resultOfCalculation.Successful = false;
            }
            catch (NullReferenceException)
            {
                resultOfCalculation.Exception  = new NullReferenceException();
                resultOfCalculation.Successful = false;
            }

            return(resultOfCalculation);
        }
Ejemplo n.º 4
0
        public void HeightNegative_ArgumentExceptionIsThrown()
        {
            RectangleAreaCalculator rectangleAreaCalculator = new RectangleAreaCalculator();

            Assert.Throws <ArgumentException>(() => rectangleAreaCalculator.RectangleArea(-5, 5));
        }