Esempio n. 1
0
        public static void CreateSpecificationFile()
        {
            Console.WriteLine();
            Console.WriteLine("Insert a line of <space> separated values indicating the numbers for the Street Specification File:");

            var inputNumbers = Console.ReadLine().Trim();
            var strNumbers   = inputNumbers.Split(' ');

            try
            {
                int[] numbers = strNumbers.Select(int.Parse).ToArray();
                streetSpecification = new StreetSpecificationFile(numbers);
                MainMenu();
            }
            catch (FormatException)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid input, please use only numbers and spaces.");
                Console.ResetColor();
                CreateSpecificationFile();
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                CreateSpecificationFile();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                CreateSpecificationFile();
            }
        }
Esempio n. 2
0
        public void StreetNumbers_HaveDuplicates_IsNotValid()
        {
            int[] streetNumbers = new int[] { 1, 2, 3, 3 };

            StreetSpecificationFile streetSpecification = new StreetSpecificationFile(streetNumbers);

            Assert.IsFalse(streetSpecification.IsValid);
        }
Esempio n. 3
0
        public void StreetNumbers_NotStartingAtOne_IsNotValid()
        {
            int[] streetNumbers = new int[] { 2, 3, 4, 5 };

            StreetSpecificationFile streetSpecification = new StreetSpecificationFile(streetNumbers);

            Assert.IsFalse(streetSpecification.IsValid);
        }
Esempio n. 4
0
        public void StreetNumbers_SkipNumbers_IsNotValid()
        {
            int[] streetNumbers = new int[] { 1, 2, 4, 5 };

            StreetSpecificationFile streetSpecification = new StreetSpecificationFile(streetNumbers);

            Assert.IsFalse(streetSpecification.IsValid);
        }
Esempio n. 5
0
        public void StreetNumbers_HaveCorrectFormat_IsValid()
        {
            int[] streetNumbers = new int[] { 1, 2, 3, 4 };

            StreetSpecificationFile streetSpecification = new StreetSpecificationFile(streetNumbers);

            Assert.IsTrue(streetSpecification.IsValid);
        }
        public void RoundDeliveryMethod_IsOrderCorrect()
        {
            var specificationFile = new StreetSpecificationFile(new int[] { 1, 2, 3, 4 });
            var deliveryMethod    = new RoundDeliveryMethod(specificationFile);
            var expectedOrder     = new int[] { 1, 3, 4, 2 };

            CollectionAssert.AreEqual(deliveryMethod.HouseNumbers, expectedOrder);
        }
        public void RoundDeliveryMethod_OneOnlyHouse_NotCrossing()
        {
            int[] numbers = new int[] { 1 };
            StreetSpecificationFile specificationFile;
            RoundDeliveryMethod     deliveryMethod;

            specificationFile = new StreetSpecificationFile(numbers);
            deliveryMethod    = new RoundDeliveryMethod(specificationFile);

            Assert.IsTrue(deliveryMethod.NumberOfCrossings == 0);
        }
        public void RoundDeliveryMethod_HousesOnBothSides_CrossOnce()
        {
            int[] numbers = new int[] { 1, 2, 3, 4 };
            StreetSpecificationFile specificationFile;
            RoundDeliveryMethod     deliveryMethod;

            specificationFile = new StreetSpecificationFile(numbers);
            deliveryMethod    = new RoundDeliveryMethod(specificationFile);

            Assert.IsTrue(deliveryMethod.NumberOfCrossings == 1);
        }
Esempio n. 9
0
        public void StreetSpecificationFile_RightStreetNumbers_AreEven()
        {
            int[] streetNumbers = new int[] { 1, 2, 3, 4 };
            int[] rightNumbers;

            StreetSpecificationFile streetSpecification = new StreetSpecificationFile(streetNumbers);

            rightNumbers = streetSpecification.RightStreetNumbers;

            for (int i = 0; i < rightNumbers.Length; i++)
            {
                if (rightNumbers[i] % 2 > 0)
                {
                    Assert.Fail();
                }
            }
        }
Esempio n. 10
0
        public void StreetSpecificationFile_LeftStreetNumbers_AreOdd()
        {
            int[] streetNumbers = new int[] { 1, 2, 3, 4 };
            int[] leftNumbers;

            StreetSpecificationFile streetSpecification = new StreetSpecificationFile(streetNumbers);

            leftNumbers = streetSpecification.LeftStreetNumbers;

            for (int i = 0; i < leftNumbers.Length; i++)
            {
                if (leftNumbers[i] % 2 == 0)
                {
                    Assert.Fail();
                }
            }
        }
Esempio n. 11
0
        public void StreetNumbers_HaveNoNumbers_ReturnsArgumentException()
        {
            int[] streetNumbers = new int[] {};

            StreetSpecificationFile streetSpecification = new StreetSpecificationFile(streetNumbers);
        }
Esempio n. 12
0
 public void AscendingDeliveryMethod_IsSpecificationFileInvalid_ReturnsException()
 {
     var specificationFile = new StreetSpecificationFile(new int[] { 2, 3, 4 });
     var deliveryMethod    = new AscendingDeliveryMethod(specificationFile);
 }
Esempio n. 13
0
        public void Initialize()
        {
            var specificationFile = new StreetSpecificationFile(numbers);

            deliveryMethod = new AscendingDeliveryMethod(specificationFile);
        }