Exemple #1
0
        public void CalculateTriangleSurface()
        {
            var shapeService = new ShapeService(new TriangleStrategy());
            var result       = shapeService.Calculate();

            Assert.AreEqual(15, result);
        }
Exemple #2
0
        public void CalculateCirckleSurface()
        {
            var shapeService = new ShapeService(new CirckleStrategy());
            var result       = shapeService.Calculate();

            Assert.AreEqual(20, result);
        }
Exemple #3
0
        private void CreateInitializationList(object sender, RoutedEventArgs e)
        {
            //Validate Inputs
            if (!IsValidInputs())
            {
                return;
            }

            //Reset
            InitializationList.Clear();
            InitializationPanel.Children.Clear();

            //Add vertical Line for start day
            Grid verticalLine = ShapeService.GetVerticalLineWithNumber(0);

            InitializationPanel.Children.Add(verticalLine);

            //Set DefaultType
            DefaultType = DefaultHouseTypeIsActive.IsChecked == true
                ? HouseType.Аctive
                : HouseType.Inactive;

            //Set DefaultUrlPicture
            DefaultUrlPicture = DefaultType == HouseType.Аctive
                ? UrlPicture.ACTIVE_HOUSE
                : UrlPicture.INACTIVE_HOUSE;

            //Set NumberOfElements
            NumberOfElements = int.Parse(NumberOfHouses.Text);

            for (int i = 0; i < NumberOfElements; i++)
            {
                InitializationList.Add(new House
                {
                    Number     = i + 1,
                    UrlPicture = DefaultUrlPicture,
                    HouseType  = DefaultType,
                });

                StackPanel wrapper = new StackPanel();

                Grid    horizontalLine = ShapeService.GetHorizontalLineWithNumber(i + 1);
                Image   image          = ShapeService.GetImage();
                Binding binding        = new Binding();
                binding.Source = InitializationList;
                binding.Path   = new PropertyPath($"[{i}].UrlPicture");
                image.SetBinding(Image.SourceProperty, binding);
                Button button = ShapeService.GetButton();
                button.Click           += ReverseImage;
                button.CommandParameter = i;

                wrapper.Children.Add(horizontalLine);
                wrapper.Children.Add(image);
                wrapper.Children.Add(button);

                InitializationPanel.Children.Add(wrapper);
            }
        }
Exemple #4
0
        public void TEST_CreateShapeService_GIVEN_NullFactory_THEN_ItReturnsException()
        {
            // Arrange

            // Act
            var target = new ShapeService(null, null, null);

            // Assert
        }
Exemple #5
0
        public string GetWhatShapeIsThis(int a, int b, int c)
        {
            var properties = new Dictionary <string, string> {
                { "Argument 'a'", a.ToString() }, { "Argument 'b'", b.ToString() }, { "Argument 'c'", c.ToString() }
            };

            telemetry.TrackEvent("WhatShapeIsThis", properties);

            TriangleType result = TriangleType.Error;

            result = new ShapeService().ClassifyTriangleType(a, b, c);
            return(result.ToString());
        }
Exemple #6
0
        public void TEST_GetConcreteTypeName_GIVEN_UnsupportedShape_THEN_ItReturnsUnknownShape()
        {
            // Arrange
            var unSupportedShapeName = "Unsupported";
            var unknownshpae         = new UnknownShape(ErrorConst.UNKNOWN_SHAPE);

            mockUnknownShapeFactory.Setup(f => f.CreateShapeConcreteType(lengths)).Returns(unknownshpae);
            var target = new ShapeService(mockShapeFactory.Object, mockUnknownShapeFactory.Object, mockShapeValidator.Object);

            // Act
            var testResult = target.GetShapeConcreteTypeName(unSupportedShapeName, lengths);

            // Assert
            mockUnknownShapeFactory.Verify(factory => factory.CreateShapeConcreteType(lengths));
            Assert.AreEqual(ErrorConst.UNKNOWN_SHAPE, testResult);
        }
        static void Main(string[] args)
        {
            var rectangle = new Rectangle(5, 6);
            var circle    = new Circle(3 / Math.Sqrt(Math.PI));
            var square    = new Square(2);
            var trapezium = new Trapezium(3, 7, 5, 4);
            var triangle  = new Triangle(17, 17, 30);
            var shapes    = new HashSet <IShape>()
            {
                circle, rectangle, square, trapezium, triangle
            };
            var shapeService = new ShapeService();

            Console.WriteLine(shapeService.CalculateSummaryArea(shapes));
            Console.WriteLine(shapeService.CalculateSummaryPerimeter(shapes));
        }
Exemple #8
0
        private void StartNewGame(object obj, EventArgs e)
        {
            _game     = new Game();
            _gameover = 0;

            _game.GameGrid = new GameGrid(10, 20);

            _shapeService = new ShapeService();

            _game.Score = new Score();

            var shapelist = _game.Shapes.ToList();

            _game.ShapeInPlay = shapelist.PickRandom();

            _game.ShapeInPlay.IsInPlay = true;
        }
Exemple #9
0
        public async Task GetAreaByIdAsync_ValidData_OkAsync(ShapeType type, bool enable, long? x, long? y, long? z, long? radius, double expected)
        {
            await using var context = new SqliteContext();
            var target = new ShapeService(context);

            var request = new ShapeDto
            {
                Type = type,
                RadiusEnabled = enable,
                X = x,
                Y = y,
                Z = z,
                Radius = radius
            };
            var shapeId = await target.CreateAsync(request);

            var area = await target.GetAreaByIdAsync(shapeId);

            Assert.Equal(expected, area);
        }
        /// <summary>
        /// Classify the type of a triangle.
        /// </summary>
        /// <param name="a">Length of side 'a'.</param>
        /// <param name="b">Length of side 'b'.</param>
        /// <param name="c">Length of side 'c'.</param>
        /// <returns>The <see cref="TriangleType"/> type.</returns>
        public TriangleType WhatShapeIsThis(int a, int b, int c)
        {
            var properties = new Dictionary <string, string> {
                { "Argument 'a'", a.ToString() }, { "Argument 'b'", b.ToString() }, { "Argument 'c'", c.ToString() }
            };

            Telemetry.TrackEvent("WhatShapeIsThis", properties);

            TriangleType result = TriangleType.Error;

            try
            {
                result = new ShapeService().ClassifyTriangleType(a, b, c);
            }
            catch (Exception exception)
            {
                Telemetry.TrackException(exception);
            }

            return(result);
        }
Exemple #11
0
        public async Task CreateAsync_ValidData_OkAsync(ShapeType type, bool enable, long? x, long? y, long? z, long? radius = null)
        {
            await using var context = new SqliteContext();
            var target = new ShapeService(context);

            var request = new ShapeDto
            {
                Type = type,
                RadiusEnabled = enable,
                X = x,
                Y = y,
                Z = z,
                Radius = radius
            };
            var shape = await context.Shapes.ByIdOrFailAsync(await target.CreateAsync(request));

            Assert.Equal(x, shape.X);
            Assert.Equal(y, shape.Y);
            Assert.Equal(z, shape.Z);
            Assert.Equal(radius, shape.Radius);
        }
 public SumTests()
 {
     _shapeService = new ShapeService();
 }
Exemple #13
0
        private void Play(object sender, RoutedEventArgs e)
        {
            //Check if Play operation is possible
            if (InitializationList.Count == 0)
            {
                return;
            }

            //Reset
            PlaygroundCanvas.Children.Clear();

            //Add vertical Line for start day
            Grid verticalLine = ShapeService.GetVerticalLineWithNumber(0);

            Canvas.SetTop(verticalLine, 20);
            PlaygroundCanvas.Children.Add(verticalLine);

            List <Image> racerList = new List <Image>();

            //Create start day
            for (int i = 0; i < NumberOfElements; i++)
            {
                Grid horizontalLine = ShapeService.GetHorizontalLineWithNumber(i + 1);
                Canvas.SetLeft(horizontalLine, 20 + (i * 100));

                Image image = ShapeService.GetImage();
                image.Source = new BitmapImage(new Uri(UrlPicture.ACTIVE_HOUSE, UriKind.Relative));
                Canvas.SetLeft(image, 20 + (i * 100));
                Canvas.SetTop(image, 20);

                racerList.Add(image);

                PlaygroundCanvas.Children.Add(horizontalLine);
                PlaygroundCanvas.Children.Add(image);
            }

            PlaygroundCanvas.Width  = 20 + (InitializationList.Count * 100);
            PlaygroundCanvas.Height = 110;

            //Refresh View
            Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
            Thread.Sleep(500);

            //Set NumberOfDasy
            NumberOfDasy = int.Parse(NumberOfDays.Text);

            List <HouseType> currentStatus = GetCurrentRowStatus();
            List <HouseType> nextStatus    = GetNextRowStatus(currentStatus);

            int currentRow = 1;

            for (int day = 1; day <= NumberOfDasy; day++)
            {
                List <int> moveIndexes = new List <int>();

                bool isNeedVerticalLineForNextDay  = false;
                bool isAddedVerticalLineForNextDay = false;

                for (int i = 0; i < nextStatus.Count; i++)
                {
                    if (nextStatus[i] == HouseType.Аctive)
                    {
                        moveIndexes.Add(i);
                    }
                }

                for (int step = 1; step <= 90; step++)
                {
                    foreach (var index in moveIndexes)
                    {
                        var    currentElement  = racerList[index];
                        double currentPosition = Canvas.GetTop(currentElement);
                        Canvas.SetTop(currentElement, currentPosition + 1);

                        if (currentPosition + 90 > PlaygroundCanvas.Height)
                        {
                            PlaygroundCanvas.Height += 1;

                            isNeedVerticalLineForNextDay = true;
                        }
                    }

                    //Create vertical line for next day
                    if (isNeedVerticalLineForNextDay && !isAddedVerticalLineForNextDay)
                    {
                        Grid currentDay = ShapeService.GetVerticalLineWithNumber(currentRow);
                        Canvas.SetTop(currentDay, 20 + (currentRow * 90));
                        PlaygroundCanvas.Children.Add(currentDay);

                        currentRow++;

                        isAddedVerticalLineForNextDay = true;
                    }

                    PlaygroundScrollViewer.ScrollToBottom();
                    Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);

                    Thread.Sleep(10);
                }

                nextStatus = GetNextRowStatus(nextStatus);
            }
        }
 static void Main()
 {
     ShapeService.SaveShape(new ShapeRepository());
 }
Exemple #15
0
 public ShapeController(ShapeService shapeService, DbContext dbContext, IWebHostEnvironment webHostEnvironment)
 {
     _shapeService       = shapeService;
     _webHostEnvironment = webHostEnvironment;
 }
 public ShapeService_ClassifyTriangleShould()
 {
     this.shapeService = new ShapeService();
 }