Beispiel #1
0
        public void GetNodes_ByDefault_ReturnsAnEmptyArray()
        {
            CourseDependencyGraph courseGraph = CreateCourseDependencyGraph();
            var courses = courseGraph.GetNodes();

            Assert.AreEqual(0, courses.Count());
        }
Beispiel #2
0
        public void CreateNewOrGetExistingNode_WhenCalled_ChangesCourseNodes()
        {
            CourseDependencyGraph courseGraph = CreateCourseDependencyGraph();
            Course course = courseGraph.CreateNewOrGetExistingNode(GetName());

            Assert.AreEqual(1, courseGraph.GetNodes().Count());
        }
Beispiel #3
0
        private static CourseDependencyGraph BuildGraphDataStructure(string[] courses, string[][] dependencyArray)
        {
            CourseDependencyGraph courseGraph = new CourseDependencyGraph();

            foreach (var course in courses)
            {
                courseGraph.CreateNewOrGetExistingNode(course);
            }

            foreach (string[] dependency in dependencyArray)
            {
                string firstCourse  = dependency[0];
                string secondCourse = dependency[1];

                courseGraph.AddEdge(firstCourse, secondCourse);
            }

            return(courseGraph);
        }
Beispiel #4
0
        private static Course[] PlanCoursesBasedOnPrerequisites(string[] courses, string[][] courseDependencies)
        {
            CourseDependencyGraph courseGraph = BuildGraphDataStructure(courses, courseDependencies);

            return(OrderCourses(courseGraph.GetNodes()));
        }