Example #1
0
        public void PositiveOneComparison()
        {
            var film1 = new OrderedFilm(1, false, testFilm);
            var film2 = new OrderedFilm(2, false, testFilm);

            film2.AddHigherRankedObject(film1);
            var comparion = film2.CompareTo(film1);

            Assert.AreEqual(-1, comparion);
        }
        public void SortCompleted()
        {
            var film1 = new OrderedFilm(1, false, testFilm);
            var film2 = new OrderedFilm(2, false, testFilm);

            film2.AddHigherRankedObject(film1);

            var sortResult = orderService.OrderFilms(new[] { film1, film2 });

            CollectionAssert.AreEqual(new[] { film2, film1 }, sortResult.SortedResults.ToArray());
            Assert.IsNull(sortResult.LeftSort);
            Assert.IsNull(sortResult.RightSort);
            Assert.IsTrue(sortResult.Completed);
        }
        public void LongSortCompleted()
        {
            var film0 = new OrderedFilm(0, false, testFilm);
            var film1 = new OrderedFilm(1, false, testFilm);
            var film2 = new OrderedFilm(2, false, testFilm);
            var film3 = new OrderedFilm(3, false, testFilm);
            var film4 = new OrderedFilm(4, false, testFilm);
            var film5 = new OrderedFilm(5, false, testFilm);
            var film6 = new OrderedFilm(6, false, testFilm);
            var film7 = new OrderedFilm(7, false, testFilm);
            var film8 = new OrderedFilm(8, false, testFilm);
            var film9 = new OrderedFilm(9, false, testFilm);

            film0.AddHigherRankedObject(film1);
            film0.AddHigherRankedObject(film2);
            film0.AddHigherRankedObject(film3);
            film0.AddHigherRankedObject(film4);
            film0.AddHigherRankedObject(film5);
            film0.AddHigherRankedObject(film6);
            film0.AddHigherRankedObject(film7);
            film0.AddHigherRankedObject(film8);
            film0.AddHigherRankedObject(film9);

            film1.AddHigherRankedObject(film2);
            film1.AddHigherRankedObject(film3);
            film1.AddHigherRankedObject(film4);
            film1.AddHigherRankedObject(film5);
            film1.AddHigherRankedObject(film6);
            film1.AddHigherRankedObject(film7);
            film1.AddHigherRankedObject(film8);
            film1.AddHigherRankedObject(film9);

            film2.AddHigherRankedObject(film3);
            film2.AddHigherRankedObject(film4);
            film2.AddHigherRankedObject(film5);
            film2.AddHigherRankedObject(film6);
            film2.AddHigherRankedObject(film7);
            film2.AddHigherRankedObject(film8);
            film2.AddHigherRankedObject(film9);

            film3.AddHigherRankedObject(film4);
            film3.AddHigherRankedObject(film5);
            film3.AddHigherRankedObject(film6);
            film3.AddHigherRankedObject(film7);
            film3.AddHigherRankedObject(film8);
            film3.AddHigherRankedObject(film9);

            film4.AddHigherRankedObject(film5);
            film4.AddHigherRankedObject(film6);
            film4.AddHigherRankedObject(film7);
            film4.AddHigherRankedObject(film8);
            film4.AddHigherRankedObject(film9);

            film5.AddHigherRankedObject(film6);
            film5.AddHigherRankedObject(film7);
            film5.AddHigherRankedObject(film8);
            film5.AddHigherRankedObject(film9);

            film6.AddHigherRankedObject(film7);
            film6.AddHigherRankedObject(film8);
            film6.AddHigherRankedObject(film9);

            film7.AddHigherRankedObject(film8);
            film7.AddHigherRankedObject(film9);

            film8.AddHigherRankedObject(film9);

            var sortResult = orderService.OrderFilms(new[] {
                film3,
                film6,
                film0,
                film1,
                film9,
                film4,
                film2,
                film8,
                film5,
                film7 });

            CollectionAssert.AreEqual(new[] {
                film0,
                film1,
                film2,
                film3,
                film4,
                film5,
                film6,
                film7,
                film8,
                film9 },
            sortResult.SortedResults.ToArray());
            Assert.IsNull(sortResult.LeftSort);
            Assert.IsNull(sortResult.RightSort);
            Assert.IsTrue(sortResult.Completed);
        }