Пример #1
0
        public void PassSmall()
        {
            List <Card> trips = new List <Card>()
            {
                new Card()
                {
                    From = "Мельбурн", To = "Кельн"
                },
                new Card()
                {
                    From = "Москва", To = "Париж"
                },
                new Card()
                {
                    From = "Кельн", To = "Москва"
                },
            };
            SortCardAlgorithm sca = new SortCardAlgorithm(trips);
            var result            = sca.SortSecondMethod();
            int count             = 0;

            for (int i = 0; i < result.Count - 1; i++)
            {
                if (result[i].To == result[i + 1].From)
                {
                    count++;
                }
            }
            Assert.Equal(count + 1, result.Count);
        }
Пример #2
0
        public void TestInvalidPath1()
        {
            List <Card> trips = new List <Card>()
            {
                new Card()
                {
                    From = "Мельбурн", To = "Кельн"
                },
                new Card()
                {
                    From = "Москва", To = "Париж"
                },
                new Card()
                {
                    From = "Кельн", To = "Москва"
                },
                new Card()
                {
                    From = "Мельбурн", To = "Москва"
                },
            };
            SortCardAlgorithm sca = new SortCardAlgorithm(trips);

            Assert.Throws(typeof(InvalidPathException), () => { sca.SortSecondMethod(); });
        }
Пример #3
0
        public void TestRecursiveOneElement()
        {
            List <Card> trips = new List <Card>()
            {
                new Card()
                {
                    From = "Мельбурн", To = "Мельбурн"
                }
            };
            SortCardAlgorithm sca = new SortCardAlgorithm(trips);

            Assert.Throws(typeof(RecursivePathException), () => { sca.SortSecondMethod(); });
        }
Пример #4
0
        public void PassMiddle()
        {
            List <Card> trips = new List <Card>()
            {
                new Card()
                {
                    From = "Кельн", To = "Париж"
                },
                new Card()
                {
                    From = "Париж", To = "Москва"
                },
                new Card()
                {
                    From = "Москва", To = "Пенза"
                },
                new Card()
                {
                    From = "Пенза", To = "Рязань"
                },
                new Card()
                {
                    From = "Рязань", To = "Новгород"
                },
                new Card()
                {
                    From = "Новгород", To = "Сочи"
                },
                new Card()
                {
                    From = "Сочи", To = "Ростов"
                },
                new Card()
                {
                    From = "Ростов", To = "Краков"
                },
                new Card()
                {
                    From = "Краков", To = "Лондон"
                },
                new Card()
                {
                    From = "Лондон", To = "Милан"
                }
            };

            // шаффл по методу Кнута
            ShuffleCard.Shuffle <Card>(trips);

            trips.Insert(0, new Card()
            {
                From = "Мельбурн", To = "Кельн"
            });

            foreach (var trip in trips)
            {
                _output.WriteLine("Из " + trip.From + " в " + trip.To);
            }

            SortCardAlgorithm sca = new SortCardAlgorithm(trips);
            var result            = sca.SortSecondMethod();
            int count             = 0;

            for (int i = 0; i < result.Count - 1; i++)
            {
                if (result[i].To == result[i + 1].From)
                {
                    count++;
                }
            }
            Assert.Equal(count + 1, result.Count);
        }