def test_eval_3(self): nodes = { 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [] } numDep = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] answer = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] n = 10 pfd_eval(nodes, numDep, answer, n) self.assert_(n == 10) self.assert_( str(nodes) == "{1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: []}" ) self.assert_( str(numDep) == "[0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]") self.assert_(str(answer) == "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]")
def test_eval_2(self): nodes = { 1: [8, 6, 4], 2: [8, 4], 3: [8, 6, 4, 1], 4: [], 5: [6, 4], 6: [4], 7: [8, 9, 4], 8: [9, 6], 9: [4], 10: [8, 2] } numDep = [0, 1, 1, 0, 7, 0, 4, 0, 5, 2, 0] answer = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] n = 10 pfd_eval(nodes, numDep, answer, n) self.assert_(n == 10) self.assert_( str(nodes) == "{1: [8, 6, 4], 2: [8, 4], 3: [8, 6, 4, 1], 4: [], 5: [6, 4], 6: [4], 7: [8, 9, 4], 8: [9, 6], 9: [4], 10: [8, 2]}" ) self.assert_( str(numDep) == "[0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]") self.assert_(str(answer) == "[3, 1, 5, 7, 10, 2, 8, 6, 9, 4]")
def test_eval_2 (self) : nodes = {1: [8, 6, 4], 2: [8, 4], 3: [8, 6, 4, 1], 4: [], 5: [6, 4], 6: [4], 7: [8, 9, 4], 8: [9, 6], 9: [4], 10: [8, 2]} numDep = [0, 1, 1, 0, 7, 0, 4, 0, 5, 2, 0] answer = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] n = 10 pfd_eval(nodes, numDep, answer, n) self.assert_(n == 10) self.assert_(str(nodes) == "{1: [8, 6, 4], 2: [8, 4], 3: [8, 6, 4, 1], 4: [], 5: [6, 4], 6: [4], 7: [8, 9, 4], 8: [9, 6], 9: [4], 10: [8, 2]}") self.assert_(str(numDep) == "[0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]") self.assert_(str(answer) == "[3, 1, 5, 7, 10, 2, 8, 6, 9, 4]")
def test_eval_1 (self) : nodes = {1: [3, 5], 2: [], 3: [2, 4], 4: [], 5: [3, 2]} numDep = [0, 0, 2, 2, 1, 1] answer = [0, 0, 0, 0, 0] n = 5 pfd_eval(nodes, numDep, answer, n) self.assert_(n == 5) self.assert_(str(nodes) == "{1: [3, 5], 2: [], 3: [2, 4], 4: [], 5: [3, 2]}") self.assert_(str(numDep) == "[0, -1, -1, -1, -1, -1]") self.assert_(str(answer) == "[1, 5, 3, 2, 4]")
def test_eval_3 (self) : nodes = {1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: []} numDep = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] answer = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] n = 10 pfd_eval(nodes, numDep, answer, n) self.assert_(n == 10) self.assert_(str(nodes) == "{1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: []}") self.assert_(str(numDep) == "[0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]") self.assert_(str(answer) == "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]")
def test_eval_4 (self) : nodes = {1: [], 2: [5], 3: [], 4: [5, 1, 2], 5: [1], 6: [1], 7: [], 8: [5, 1], 9: [5, 1, 2], 10: [5], 11: [1], 12: [1], 13: [1], 14: [1], 15: [], 16: [1], 17: [5], 18: [1]} numDep = [0, 11, 2, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] answer = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] n = 18 pfd_eval(nodes, numDep, answer, n) self.assert_(n == 18) self.assert_(str(nodes) == "{1: [], 2: [5], 3: [], 4: [5, 1, 2], 5: [1], 6: [1], 7: [], 8: [5, 1], 9: [5, 1, 2], 10: [5], 11: [1], 12: [1], 13: [1], 14: [1], 15: [], 16: [1], 17: [5], 18: [1]}") self.assert_(str(numDep) == "[0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]") self.assert_(str(answer) == "[3, 4, 6, 7, 8, 9, 2, 10, 11, 12, 13, 14, 15, 16, 17, 5, 18, 1]")
def test_eval_1(self): nodes = {1: [3, 5], 2: [], 3: [2, 4], 4: [], 5: [3, 2]} numDep = [0, 0, 2, 2, 1, 1] answer = [0, 0, 0, 0, 0] n = 5 pfd_eval(nodes, numDep, answer, n) self.assert_(n == 5) self.assert_( str(nodes) == "{1: [3, 5], 2: [], 3: [2, 4], 4: [], 5: [3, 2]}") self.assert_(str(numDep) == "[0, -1, -1, -1, -1, -1]") self.assert_(str(answer) == "[1, 5, 3, 2, 4]")
def test_eval_1 (self) : al= {} al[1] = [3, 5] al[2] = [] al[3] = [2,4] al[4] = [] al[5] = [3,2] td = {} td[1] = [0,1] td[2] = [2,2] td[3] = [2,3] td[4] = [1,4] td[5] = [1,5] heap = [] heapq.heappush(heap, td[1]) heapq.heappush(heap, td[2]) heapq.heappush(heap, td[3]) heapq.heappush(heap, td[4]) heapq.heappush(heap, td[5]) ord_list = pfd_eval(al, heap, td) self.assert_(ord_list[0] == 1) self.assert_(ord_list[1] == 5) self.assert_(ord_list[2] == 3) self.assert_(ord_list[3] == 2) self.assert_(ord_list[4] == 4)
def test_eval_2 (self) : al= {} al[1] = [] td = {} td[1] = [0,1] heap = [] heapq.heappush(heap, td[1]) ord_list = pfd_eval(al, heap, td) self.assert_(ord_list[0] == 1)
def test_eval_1 (self) : b = [[3, 2, 1, 5], [2, 2, 5, 3], [4, 1, 3], [5, 1, 1]] vs = dict() i = 1 while i <= 4 : vs[b[i-1][0]] = VertexPFD(b[i-1]) i += 1 vs[1] = VertexPFD([1, 0]) vs[1].succ = [5, 3] vs[3].succ = [2, 4] vs[5].succ = [2, 3] r = pfd_eval(vs) self.assert_(r == [1, 5, 3, 2, 4])
def test_eval_2 (self) : b = [[1, 2, 2, 3], [2, 1, 3]] vs = dict() i = 1 while i <= 2 : vs[b[i-1][0]] = VertexPFD(b[i-1]) i += 1 vs[3] = VertexPFD([3, 0]) vs[1].succ = [2] vs[2].succ = [1] vs[3].succ = [1, 2] r = pfd_eval(vs) self.assert_(r == [3, 2, 1])
def test_eval_4(self): nodes = { 1: [], 2: [5], 3: [], 4: [5, 1, 2], 5: [1], 6: [1], 7: [], 8: [5, 1], 9: [5, 1, 2], 10: [5], 11: [1], 12: [1], 13: [1], 14: [1], 15: [], 16: [1], 17: [5], 18: [1] } numDep = [0, 11, 2, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] answer = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] n = 18 pfd_eval(nodes, numDep, answer, n) self.assert_(n == 18) self.assert_( str(nodes) == "{1: [], 2: [5], 3: [], 4: [5, 1, 2], 5: [1], 6: [1], 7: [], 8: [5, 1], 9: [5, 1, 2], 10: [5], 11: [1], 12: [1], 13: [1], 14: [1], 15: [], 16: [1], 17: [5], 18: [1]}" ) self.assert_( str(numDep) == "[0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]" ) self.assert_( str(answer) == "[3, 4, 6, 7, 8, 9, 2, 10, 11, 12, 13, 14, 15, 16, 17, 5, 18, 1]")
def test_eval_1 (self) : vertices = [Vertex() for _ in range(6)] vertices[3].numPred = 2 vertices[3].listPred = [1, 5] vertices[2].numPred = 2 vertices[2].listPred = [5, 3] vertices[4].numPred = 1 vertices[4].listPred = [3] vertices[5].numPred = 1 vertices[5].listPred = [1] vertices[1].listSuc = [3, 5] vertices[3].listSuc = [2, 4] vertices[5].listSuc = [2, 3] result = pfd_eval(vertices) self.assert_(result == [1, 5, 3, 2, 4])
def test_eval_3 (self) : vertices = [Vertex() for _ in range(5)] vertices[1].numPred = 1 vertices[1].listPred = [3] vertices[1].listSuc = [2] vertices[2].numPred = 2 vertices[2].listPred = [1, 3] vertices[2].listSuc = [4] vertices[3].numPred = 0 vertices[3].listPred = [] vertices[3].listSuc = [1, 2, 4] vertices[4].numPred = 2 vertices[4].listPred = [3, 2] vertices[4].listSuc = [] result = pfd_eval(vertices) self.assert_(result == [3, 1, 2, 4])
def test_eval_2 (self) : vertices = [Vertex() for _ in range(7)] vertices[2].numPred = 2 vertices[2].listPred = [1, 3] vertices[3].numPred = 1 vertices[3].listPred = [1] vertices[4].numPred = 3 vertices[4].listPred = [2, 5, 6] vertices[5].numPred = 1 vertices[5].listPred = [3] vertices[6].numPred = 1 vertices[6].listPred = [5] vertices[1].listSuc = [2, 3] vertices[2].listSuc = [4] vertices[3].listSuc = [2, 5] vertices[5].listSuc = [4, 6] vertices[6].listSuc = [4] result = pfd_eval(vertices) self.assert_(result == [1, 3, 2, 5, 6, 4])
def test_eval_1 (self): p = [[], [], [5, 3], [1, 5], [3], [1]] s = [[], [3, 5], [], [2, 4], [], [2, 3]] out = pfd_eval(p, s) self.assert_(out == ['1', ' ', '5', ' ', '3', ' ', '2', ' ', '4'])
def test_eval_2 (self): p = [[], [], [1], [2]] s = [[], [2], [3], []] out = pfd_eval(p, s) self.assert_(out == ['1', ' ', '2', ' ', '3'])
def test_eval_3 (self): p = [[], [], [1], [], [3, 1, 2], [4]] s = [[], [2, 4], [4], [4], [5], []] out = pfd_eval(p, s) self.assert_(out == ['1', ' ', '2', ' ', '3', ' ', '4', ' ', '5'])
def test_eval_1(self): v = pfd_eval([[1, []], [0, [1]]]) self.assert_(v == [2, 1])
def test_eval_2(self): v = pfd_eval([[0, [3, 5]], [2, []], [2, [2, 4]], [1, []], [1, [3, 2]]]) self.assert_(v == [1, 5, 3, 2, 4])
def test_eval_3(self): v = pfd_eval([[0, [5]], [0, []], [0, []], [0, []], [1, []]]) self.assert_(v == [1, 2, 3, 4, 5])
def test_eval_1 (self) : v = pfd_eval([[1, []], [0, [1]]]) self.assert_(v == [2, 1] )
def test_eval_3 (self) : v = pfd_eval([[0, [5]], [0, []], [0, []], [0, []], [1, []]]) self.assert_(v == [1, 2, 3, 4, 5])
def test_eval_2 (self) : v = pfd_eval([[0, [3, 5]], [2, []], [2, [2, 4]], [1, []], [1, [3, 2]]]) self.assert_(v == [1, 5, 3, 2, 4])