Esempio n. 1
0
        /// <summary>
        /// Displaying the page.
        /// </summary>
        public override void Display()
        {
            base.Display();
            if (Data.Shapes == null || Data.Shapes.Count == 0)
            {
                Output.DisplayInfo("Collection is empty\n\nPress any key to navigate home");
                Input.AnyKey();
                Program.NavigateHome();
            }

            var choiceMethod = Input.ReadEnum <SortShapesBy>("Choose the sort method");

            switch (choiceMethod)
            {
            case SortShapesBy.Area:
                Data.Shapes = ShapeSorter.SortByAscending(Data.Shapes, choiceMethod).ToList();
                break;

            case SortShapesBy.Perimeter:
                Data.Shapes = ShapeSorter.SortByAscending(Data.Shapes, choiceMethod).ToList();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            ShapePrinter.Print(Data.Shapes);
            Output.WriteLine("Press any key to navigate home");
            Input.AnyKey();
            Program.NavigateBack();
        }
Esempio n. 2
0
        public void SortByArea_GivenAList_ShouldSortByArea()
        {
            var sorter = new ShapeSorter <Rectangle>();
            var result = sorter.SortByArea(new List <Rectangle> {
                new Rectangle(11, 11), new Rectangle(10, 10)
            }).ToList();

            Assert.IsTrue(result.First().Area == 100);
        }
Esempio n. 3
0
        /// <summary>
        /// Displays the page.
        /// </summary>
        public override void Display()
        {
            base.Display();
            try
            {
                if (Data.Shapes == null || Data.Shapes.Count == 0)
                {
                    Output.DisplayInfo("Collection is empty!");
                }
                else
                {
                    var choice     = Input.ReadEnum <Quarter>("Enter the Quarter");
                    var collection = ShapeSorter
                                     .SortByDescending(_shapeFinder.Find(Data.Shapes, choice), SortShapesBy.Perimeter).ToList();
                    var path = Input.ReadString("Enter file path: ");
                    _fileManager.Save(path, collection);
                    ShapePrinter.Print(collection);
                }
            }
            catch (ArgumentException e)
            {
                Output.DisplayError(e.Message + e.ParamName);
            }
            catch (FileNotFoundException e)
            {
                Output.DisplayError(e.Message);
            }
            catch (IOException e)
            {
                Output.DisplayError(e.Message);
            }
            catch (Exception e)
            {
                Output.DisplayError(e.Message);
            }

            Output.DisplayInfo("Press any key to navigate home");
            Input.AnyKey();
            Program.NavigateBack();
        }
Esempio n. 4
0
        public void SortByArea_ShouldAcceptListOfRectangles()
        {
            var sorter = new ShapeSorter <Rectangle>();

            sorter.SortByArea(new List <Rectangle>());
        }