import unittest import io import re from unittest import mock import math import copy import inspect import student_X as main #Replace student_X with your filename class TriangleEqTests(unittest.TestCase): def test_default_case(self): function = main.Triangle.__eq__ test = False try: incorrect = "" result = function.__doc__ result = result.strip() test = result != incorrect except: pass message = "No docstring." self.assertTrue(test, message) main.Point #check that the Point class is included a = main.Point(60, -4) b = main.Point(120, -8) c = main.Point(1, 2) d = main.Point(5, 5) t1 = main.Triangle(a, b, c) t2 = main.Triangle(d, b, c) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = False correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work for a case where the two triangles are different." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(a, d, c) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = False correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work for a case where the two triangles are different." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(a, b, d) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = False correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work for a case where the two triangles are different." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(d, a, b) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = False correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work for a case where the two triangles are different." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(d, b, a) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = False correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work for a case where the two triangles are different." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(a, d, b) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = False correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work for a case where the two triangles are different." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(d, c, b) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = False correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work for a case where the two triangles are different." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(a, c, d) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = False correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work for a case where the two triangles are different." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(a, b, c) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = True correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work when the two triangles have equal points in the same parameter order." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(a, c, b) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = True correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work when the have the same points, but the last two in swapped order." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(b, a, c) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = True correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work when they are equal but the first and second parameters are swapped." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(c, b, a) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = True correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work when they are equal, but the first and last are in swapped order." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(b, c, a) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = True correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work in one of the cases where they are equal." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) t1 = main.Triangle(a, b, c) t2 = main.Triangle(c, a, b) inputs = (t1, t2) tested_inputs = inputs #change this if you need to test specific inputs #expected answers correct_inputs = inputs correct_result = True correct_printed = "" #run the test with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: if isinstance(inputs, tuple): result = function(*inputs) else: result = function(inputs) printed_output = fake_stdout.getvalue().strip() test = correct_printed == printed_output message = "Shouldn't print anything." self.assertTrue(test, message) test = result == correct_result message = "Doesn't work in one of the cases where they are equal." self.assertTrue(test, message) test = tested_inputs == correct_inputs message = "Modifies the inputs." self.assertTrue(test, message) if __name__ == "__main__": tests = TriangleEqTests() tests.test_default_case()