示例#1
0
        public void GetAllSequences_OnNoCompletionPossible()
        {
            var factory = new CourseMockupFactory();

            // Build mockup list with size = n.
            int n       = 5;
            var courses = factory.BuildDummyList(n);

            // Build circular pre-requisites (invalid pre-requisites).
            factory.SetPrerequisiteAsFirstCourse(ref courses);
            courses[0].Prerequisites.Add(courses[1].Id);

            var permutator = new CoursePermutator(courses);
            var sequences  = permutator.GetAllSequences().ToList();
        }
示例#2
0
        public void GetAllSequences_EnsureCorrectOrderLength()
        {
            var factory = new CourseMockupFactory();

            for (int i = 1; i <= 7; i++)
            {
                // Build mockup list with size = i.
                var courses = factory.BuildDummyList(i);
                factory.SetPrerequisiteAsFirstCourse(ref courses);

                var permutator = new CoursePermutator(courses);
                var sequences  = permutator.GetAllSequences();

                foreach (var order in sequences)
                {
                    // Each order needs to have the same length as the total courses length.
                    if (order.Count() != i)
                    {
                        Assert.Fail();
                    }
                }
            }
        }
        public void IsAvailable_OnIncompletePrerequisite()
        {
            // Build mockup objects with no pre-requisites.
            int n       = 5;
            var factory = new CourseMockupFactory();
            var courses = factory.BuildDummyList(5);

            factory.SetPrerequisiteAsFirstCourse(ref courses);

            // Set that no course has been completed.
            var completedCourseDictionary = new Dictionary <int, bool>();

            for (int i = 0; i < courses.Count; i++)
            {
                completedCourseDictionary.Add(courses[i].Id, false);
            }

            // As all courses requires first course id (1) and given that no course has been completed,
            // The second to last course should return false, while the first one should return true.
            Assert.IsTrue(CourseAvailabilityChecker.IsAvailable(completedCourseDictionary, courses[0]));
            for (int i = 1; i < n; i++)
            {
                Assert.IsFalse(CourseAvailabilityChecker.IsAvailable(completedCourseDictionary, courses[i]));
            }

            // Second case, try for partial pre-requisite match.
            // Set course 3 (index: 2) to require course 2 (on top of 1).
            int targetIndex = 2;

            courses[targetIndex].Prerequisites.Add(2);

            // Mark course 1 as completed.
            completedCourseDictionary[1] = true;

            // As course 3 requires 1 and 2, and only 1 is completed, this should return false.
            Assert.IsFalse(CourseAvailabilityChecker.IsAvailable(completedCourseDictionary, courses[targetIndex]));
        }
示例#4
0
        public void GetAllSequences_EnsureCorrectOrderSequence()
        {
            var factory = new CourseMockupFactory();

            for (int i = 1; i <= 7; i++)
            {
                // Build mockup list with size = i.
                var courses = factory.BuildDummyList(i);
                factory.SetPrerequisiteAsFirstCourse(ref courses);

                var permutator = new CoursePermutator(courses);
                var sequences  = permutator.GetAllSequences();

                foreach (var course in courses)
                {
                    var prerequisites = course.Prerequisites;

                    foreach (var order in sequences)
                    {
                        bool isCourseFound = false;
                        foreach (var courseId in order.ToList())
                        {
                            if (courseId == course.Id)
                            {
                                isCourseFound = true;
                            }

                            if (isCourseFound && prerequisites.Contains(courseId))
                            {
                                Assert.Fail();
                            }
                        }
                    }
                }
            }
        }