public void GetNodes_ByDefault_ReturnsAnEmptyArray() { CourseDependencyGraph courseGraph = CreateCourseDependencyGraph(); var courses = courseGraph.GetNodes(); Assert.AreEqual(0, courses.Count()); }
public void CreateNewOrGetExistingNode_WhenCalled_ChangesCourseNodes() { CourseDependencyGraph courseGraph = CreateCourseDependencyGraph(); Course course = courseGraph.CreateNewOrGetExistingNode(GetName()); Assert.AreEqual(1, courseGraph.GetNodes().Count()); }
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); }
private static Course[] PlanCoursesBasedOnPrerequisites(string[] courses, string[][] courseDependencies) { CourseDependencyGraph courseGraph = BuildGraphDataStructure(courses, courseDependencies); return(OrderCourses(courseGraph.GetNodes())); }