def test_solve_4(self): r = StringIO.StringIO( "10 6\n8 5 10 1 7 3 2\n2 1 10\n9 2 7 8\n6 4 1 8 5 3\n4 7 7 2 1 5 3 9 6\n1 1 3" ) w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "3 1 5 7 10 2 8 6 9 4 \n\n")
def test_solve_4 (self) : r = StringIO.StringIO("10 6\n8 5 10 1 7 3 2\n2 1 10\n9 2 7 8\n6 4 1 8 5 3\n4 7 7 2 1 5 3 9 6\n1 1 3") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "3 1 5 7 10 2 8 6 9 4 \n\n")
def test_solve_3 (self) : r = StringIO.StringIO("3 2\n1 2 2 3\n2 1 3") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "3 2 1 \n\n")
#!/usr/bin/env python """ To run the program % python RunPFD.py < RunPFD.in > RunPFD.out % chmod ugo+x RunPFD.py % RunPFD.py < RunPFD.in > RunPFD.out To document the program % pydoc -w PFD """ # ------- # imports # ------- import sys from PFD import pfd_solve # ---- # main # ---- pfd_solve(sys.stdin, sys.stdout)
def test_solve_3(self): r = StringIO.StringIO("3 2\n1 2 2 3\n2 1 3") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "3 2 1 \n\n")
def test_solve_3 (self) : r = StringIO.StringIO("5 4\n2 1 1\n3 1 2\n4 1 3\n5 1 4\n") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "1 2 3 4 5\n\n")
def test_solve_2 (self): r = StringIO.StringIO("3 2\n2 1 1\n3 1 2") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "1 2 3")
def test_solve_3 (self) : r = StringIO.StringIO("18 14\n 3 1 18\n7 1 2\n10 1 7\n12 1 18\n6 2 3 5\n13 2 2 7\n4 1 12\n15 4 2 3 6 13\n9 3 2 7 15\n11 3 18 7 4\n17 4 6 13 4 9\n1 3 10 8 12\n16 6 2 7 8 5 4 11\n14 3 13 4 1\n") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "2 5 7 8 10 13 18 3 6 12 1 4 11 14 15 9 16 17\n\n" )
def test_solve_3 (self) : r = StringIO.StringIO("4 2\n1 3 2 3 4\n2 2 3 4 \n") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "3 4 2 1 \n")
def test_solve_1 (self) : r = StringIO.StringIO("2 1\n1 1 2") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "2 1")
def test_solve_3 (self) : r = StringIO.StringIO("5 1\n5 1 1") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "1 2 3 4 5")
def test_solve_1(self): r = StringIO.StringIO("2 1\n1 1 2") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "2 1")
def test_solve_3(self): r = StringIO.StringIO("5 1\n5 1 1") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "1 2 3 4 5")
def test_solve_3 (self): r = StringIO.StringIO("5 3\n2 1 1\n4 3 3 1 2\n5 1 4\n") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "1 2 3 4 5")
def test_solve_1 (self) : r = StringIO.StringIO("5 4\n3 2 1 5\n2 2 5 3\n4 1 3\n5 1 1\n") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "1 5 3 2 4\n\n")
def test_solve_1(self): r = StringIO.StringIO("5 4\n3 2 1 5\n2 2 5 3\n4 1 3\n5 1 1") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "1 5 3 2 4 \n\n")
def test_solve_2 (self) : r = StringIO.StringIO("1 0\n") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "1\n\n")
def test_solve_2(self): r = StringIO.StringIO("10 0") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "1 2 3 4 5 6 7 8 9 10 \n\n")
""" import sys import random from PFD import pfd_solve # input generator def genRandInput (size) : input_file = open("RunPFD.in", "w") s = str(size) + " " + str(size-1) b = [] a = [0] * size for k in range(1, size + 1): a[k-1] = k random.shuffle(a) current = a.pop() b.append(current) while len(b) != size: temp = "" current = a.pop() temp = str(current) + " " + str(len(b)) for i in b: temp += " " + str(i) s += "\n" + temp b.append(current) input_file.write(s) input_file.close() genRandInput(100) pfd_solve(sys.stdin, sys.stdout)
def test_solve_2 (self) : r = StringIO.StringIO("6 5\n2 2 1 3\n3 1 1\n4 3 2 5 6\n5 1 3\n6 1 5\n") w = StringIO.StringIO() pfd_solve(r, w) self.assert_(w.getvalue() == "1 3 2 5 6 4")