public void FindOrderTest3() { CourseSchedule courseSchedule = new CourseSchedule(); int[][] pre = new int[0][]; //pre[0] = new int[0]; int[] res = courseSchedule.FindOrder(1, pre); Assert.IsTrue(res[0] == 0); }
public void FindOrderTest() { CourseSchedule courseSchedule = new CourseSchedule(); int[][] pre = new int[1][]; pre[0] = new int[] { 1, 0 }; int[] res = courseSchedule.FindOrder(2, pre); Assert.IsTrue(res[0] == 0); Assert.IsTrue(res[1] == 1); }
public void FindOrderTest4() { CourseSchedule courseSchedule = new CourseSchedule(); int[][] pre = new int[2][]; pre[0] = new int[] { 0, 1 }; pre[1] = new int[] { 1, 0 }; int[] res = courseSchedule.FindOrder(2, pre); Assert.IsTrue(res.Length == 0); }
public void TestFindOrder() { Assert.AreEqual(new int[] { 0, 1, 2, 3 }, CourseSchedule.FindOrder(4, new int[, ] { { 1, 0 }, { 2, 0 }, { 3, 1 }, { 3, 2 } })); // can have multiple solution Assert.AreEqual(new int[] { 0, 1, 2 }, CourseSchedule.FindOrder(3, new int[, ] { { 1, 0 }, { 2, 0 }, { 2, 1 } })); Assert.AreEqual(new int[] { }, CourseSchedule.FindOrder(3, new int[, ] { { 1, 0 }, { 0, 1 } })); }
public void TestOrder() { //无环 var arr = new int[, ] { { 1, 0 }, { 2, 0 }, { 3, 1 }, { 5, 2 }, { 4, 3 }, { 3, 6 }, }; var r = CourseSchedule.FindOrder(7, arr); //上面这图里按照我写的算法是分层次的 06最外层,12第二层,35第三层,4最后,同一层次里数组里先出现结果里也先出现 var s = string.Join("", r); Assert.AreEqual(s.Substring(0, 2), "06"); Assert.AreEqual(s.Substring(2, 2), "12"); Assert.AreEqual(s.Substring(4, 2), "35"); Assert.AreEqual(s.Substring(6, 1), "4"); //无环 arr = new int[, ] { { 1, 0 }, { 2, 0 }, { 3, 1 }, { 3, 2 } }; r = CourseSchedule.FindOrder(4, arr); //上面这图里按照我写的算法是分层次的 06最外层,12第二层,35第三层,4最后,同一层次里数组里先出现结果里也先出现 s = string.Join("", r); Assert.AreEqual(s.Substring(0, 1), "0"); Assert.AreEqual(s.Substring(1, 2), "12"); Assert.AreEqual(s.Substring(3, 1), "3"); //有环 arr = new int[, ] { { 1, 0 }, { 2, 0 }, { 3, 1 }, { 5, 2 }, { 4, 3 }, { 3, 6 }, { 6, 4 }, }; r = CourseSchedule.FindOrder(7, arr); Assert.AreEqual(r.Length, 0); }
public void FindOrderTest2() { CourseSchedule courseSchedule = new CourseSchedule(); int[][] pre = new int[4][]; pre[0] = new int[] { 1, 0 }; pre[1] = new int[] { 2, 0 }; pre[2] = new int[] { 3, 1 }; pre[3] = new int[] { 3, 2 }; int[] res = courseSchedule.FindOrder(4, pre); Assert.IsTrue(res[0] == 0); Assert.IsTrue(res[1] == 1 || res[1] == 2); Assert.IsTrue(res[2] == 1 || res[2] == 2); Assert.IsTrue(res[3] == 3); }