def test_05_test_Visit_Log_Stack(self): stack = Stack(6) for i in range(5): stack.push(i) stack.accept(ScreenPrinter("test")) display_message = "\n-------\n" expected = 'test\n' + display_message + ' 4 ' + display_message + ' 3 ' + display_message + ' 2 ' + display_message + ' 1 ' + display_message + ' 0 ' + display_message + '\n' self.assertEqual(self.capturedOutput.getvalue(), expected)
def test_05_test_Visit_Log_Stack(self): stack = Stack(6) for i in range(5): stack.push(i) stack.accept(FilePrinter("./ThisIsATestFile.txt","")) with open('./ThisIsATestFile.txt', 'r') as myfile: result=myfile.read(); separator = "\n-------\n"; expected = separator+' 4 '+separator+' 3 '+separator+' 2 '+separator+' 1 '+separator+' 0 '+separator; self.assertEqual(result, expected);
def testVisitLogStack(self): stack = Stack(10) for i in range(5): stack.push(i) stack.accept(ScreenPrinter("")) s = "\n-------\n" expected = '\n' + s + ' 4 ' + s + ' 3 ' + s + ' 2 ' + s + ' 1 ' + s + ' 0 ' + s + '\n' self.assertEqual(self.capturedOutput.getvalue(), expected)
def testVisitLogStack(self): stack = Stack(10) for i in range(5): stack.push(i) stack.accept(FilePrinter("./test.txt", "")) with open('./test.txt', 'r') as myfile: result = myfile.read() s = "\n-------\n" expected = s + ' 4 ' + s + ' 3 ' + s + ' 2 ' + s + ' 1 ' + s + ' 0 ' + s self.assertEqual(result, expected)
class FilePrinterTest(unittest.TestCase): def setUp(self): self.printer = FilePrinter("testFile.txt", "testName") self.linkedList = LinkedList() self.stack = Stack(3) self.queue = Queue(3) def tearDown(self): try: os.remove(self.printer.file_path) except IOError: pass # Test __init__() def test_a_Init(self): self.assertEqual(self.printer.file_path, "testFile.txt") self.assertEqual(self.printer.name, "testName") def test_b_VisitLinkedList(self): self.linkedList.append(1) self.linkedList.append(2) self.linkedList.append(3) self.linkedList.accept(self.printer) with open(self.printer.file_path, 'r') as testFile: self.assertEqual(testFile.read(), self.printer.name + "\n(1,2,3)\n") def test_c_VisitStack(self): self.stack.push(1) self.stack.push(2) self.stack.push(3) self.stack.accept(self.printer) filler="\n-------\n" with open(self.printer.file_path, 'r') as testFile: self.assertEqual(testFile.read(), self.printer.name +filler+' 3 '+filler+' 2 '+filler+' 1 '+filler) def test_d_VisitLogQueue(self): self.queue.enqueue(1) self.queue.enqueue(2) self.queue.enqueue(3) self.queue.accept(self.printer) with open(self.printer.file_path, 'r') as testFile: self.assertEqual(testFile.read(), self.printer.name + "\n|1|2|3|\n")
class ScreenPrinterTest(unittest.TestCase): def setUp(self): self.screenPrinter = ScreenPrinter("test") self.linkedList = LinkedList() self.stack = Stack(3) self.queue = Queue(3) # Test __init__() def test_a_Init(self): self.assertEqual(self.screenPrinter.name, "test") def test_b_VisitLinkedList(self): self.linkedList.append(1) self.linkedList.append(2) self.linkedList.append(3) sys.stdout = io.StringIO() self.linkedList.accept(ScreenPrinter("")) self.assertEqual(sys.stdout.getvalue(), "\n\n(1,2,3)\n\n") sys.stdout = sys.__stdout__ def test_c_VisitStack(self): self.stack.push(1) self.stack.push(2) self.stack.push(3) sys.stdout = io.StringIO() self.stack.accept(ScreenPrinter("")) filler = "\n-------\n" self.assertEqual( sys.stdout.getvalue(), '\n' + filler + ' 3 ' + filler + ' 2 ' + filler + ' 1 ' + filler + '\n') sys.stdout = sys.__stdout__ def test_d_VisitLogQueue(self): self.queue.enqueue(1) self.queue.enqueue(2) self.queue.enqueue(3) sys.stdout = io.StringIO() self.queue.accept(ScreenPrinter("")) self.assertEqual(sys.stdout.getvalue(), "\n\n|1|2|3|\n\n") sys.stdout = sys.__stdout__