def test__str__method(self): """This function tests the str function""" Rectangle.reset_objects() s1 = Square(5) self.assertEqual(str(s1), "[Square] (1) 0/0 - 5") s2 = Square(2, 2) self.assertEqual(str(s2), "[Square] (2) 2/0 - 2") s3 = Square(3, 1, 3) self.assertEqual(str(s3), "[Square] (3) 1/3 - 3")
def test_singlerectanglecreationwithallvalues(self): """This function tests for single instance creati\ on""" Rectangle.reset_objects() s1 = Rectangle(10, 10, 10, 10, 10) self.assertEqual(s1.width, 10) self.assertEqual(s1.height, 10) self.assertEqual(s1.x, 10) self.assertEqual(s1.y, 10) self.assertEqual(s1.id, 10)
def test_fornoargumentstoupdate(self): """a cagar""" Rectangle.reset_objects() r1 = Rectangle(10, 10, 10, 10, 10) r1.update() self.assertEqual(r1.id, 10) self.assertEqual(r1.width, 10) self.assertEqual(r1.height, 10) self.assertEqual(r1.x, 10) self.assertEqual(r1.y, 10)
def test_fornoargumentstoupdate(self): """This function tests that update accepts 0 arguments""" Rectangle.reset_objects() r1 = Rectangle(10, 10, 10, 10, 10) r1.update() self.assertEqual(r1.id, 10) self.assertEqual(r1.width, 10) self.assertEqual(r1.height, 10) self.assertEqual(r1.x, 10) self.assertEqual(r1.y, 10)
def test_updatekwargsall(self): """This function tests updating all attrs with kwargs""" Rectangle.reset_objects() r1 = Rectangle(10, 10, 10, 10, 10) r1.update(width=5, height=5, x=5, y=5, id=5) self.assertEqual(r1.width, 5) self.assertEqual(r1.height, 5) self.assertEqual(r1.x, 5) self.assertEqual(r1.y, 5) self.assertEqual(r1.id, 5)
def test_updatewithdict(self): """This function tests the to_dictionary function""" Rectangle.reset_objects() r1 = Rectangle(10, 2, 3, 9) r1_dictionary = r1.to_dictionary() r2 = Rectangle(1, 1) r2.update(**r1_dictionary) self.assertEqual(r2.width, 10) self.assertEqual(r2.height, 2) self.assertEqual(r2.x, 3) self.assertEqual(r2.y, 9)
def test_updatekwargswidth(self): """This function tests updating width with kwargs""" Rectangle.reset_objects() r1 = Rectangle(10, 10, 10, 10, 10) r1.update(width=1) self.assertEqual(r1.width, 1)
def test_rectanglecreationwith1and2(self): """This function tests for ereationwithtwoattributesset""" Rectangle.reset_objects() r1 = Rectangle(1, 2) self.assertEqual(r1.width, 1) self.assertEqual(r1.height, 2)
def test_publicareamethod(self): """This function tests the public area method""" Rectangle.reset_objects() r1 = Rectangle(5, 10, 7, 9, 100) self.assertEqual(r1.area(), 50)
def test_infy(self): """This function tests for inf y value""" Rectangle.reset_objects() with self.assertRaises(TypeError) as e: r1 = Rectangle(10, 10, 5, float('Inf'), 7) self.assertEqual(str(e.exception), 'y must be an integer')
def test_kwargsskipped(self): """This function tests updating args with kwargs""" Rectangle.reset_objects() r1 = Rectangle(10, 10, 10, 10, 10) r1.update(1, 2, 3, 4, 5, id=10) self.assertEqual(r1.id, 1)
def test_updatekwargsy(self): """This function tests updating y with kwargs""" Rectangle.reset_objects() r1 = Rectangle(10, 10, 10, 10, 10) r1.update(y=4) self.assertEqual(r1.y, 4)
def test_widthsetter(self): """This function tests the width setter""" Rectangle.reset_objects() r1 = Rectangle(25, 20, 30, 35, 100) r1.width = 45 self.assertEqual(r1.width, 45)
def test_ygetter(self): """This function tests for getting y""" Rectangle.reset_objects() r1 = Rectangle(25, 20, 30, 35, 100) self.assertEqual(r1.y, 35)
def test_heightgetter(self): """This function tests for getting height""" Rectangle.reset_objects() r1 = Rectangle(25, 20, 30, 35, 100) self.assertEqual(r1.height, 20)
def test_widthgetter(self): """This function tests for getting width""" Rectangle.reset_objects() r1 = Rectangle(25, 20, 30, 35, 100) self.assertEqual(r1.width, 25)
def test_recNoneid(self): """This function tests for None argument""" Rectangle.reset_objects() r1 = Rectangle(10, 10, 10, 10, None) self.assertEqual(r1.id, 1)
def test_noidgiven(self): """This function tests that id is auto-set when none is given""" Rectangle.reset_objects() r1 = Rectangle(10, 2) self.assertEqual(r1.id, 1)
def test_inf(self): """This function tests for NaN""" Rectangle.reset_objects() with self.assertRaises(TypeError) as e: r1 = Rectangle(float('inf'), 10, 10, 5, 7) self.assertEqual(str(e.exception), 'width must be an integer')
def test_updatekwargsheight(self): """This function tests updating height with kwargs""" Rectangle.reset_objects() r1 = Rectangle(10, 10, 10, 10, 10) r1.update(height=2) self.assertEqual(r1.height, 2)
def test_updatekwargsx(self): """This function tests updating x with kwargs""" Rectangle.reset_objects() r1 = Rectangle(10, 10, 10, 10, 10) r1.update(x=3) self.assertEqual(r1.x, 3)
def test_heightsetter(self): """This function tests the height setter""" Rectangle.reset_objects() r1 = Rectangle(25, 20, 30, 35, 100) r1.height = 40 self.assertEqual(r1.height, 40)
def test_updatekwargsid(self): """This function tests updating id with kwargs""" Rectangle.reset_objects() r1 = Rectangle(10, 10, 10, 10, 10) r1.update(id=5) self.assertEqual(r1.id, 5)
def test_xsetter(self): """This function tests the x setter""" Rectangle.reset_objects() r1 = Rectangle(25, 20, 30, 35, 100) r1.x = 50 self.assertEqual(r1.x, 50)
def test_rectanglecreationwithheight0(self): """This function tests for height set to 0""" Rectangle.reset_objects() with self.assertRaises(ValueError) as e: r1 = Rectangle(1, 0) self.assertEqual(str(e.exception), 'height must be > 0')
def test_allbadvalues(self): """This function tests for bad width value""" Rectangle.reset_objects() with self.assertRaises(TypeError) as e: r1 = Rectangle(False, "foo", {"str": 7}, ("hello", ), True) self.assertEqual(str(e.exception), 'width must be an integer')
def test_singlerectanglecreation(self): """This function tests for single instance creation""" Rectangle.reset_objects() r1 = Rectangle(10, 2) self.assertEqual(r1.id, 1)
def test_NaNx(self): """This function tests for NaN x value""" Rectangle.reset_objects() with self.assertRaises(TypeError) as e: r1 = Rectangle(10, 10, float('nan'), 5, 7) self.assertEqual(str(e.exception), 'x must be an integer')
def test_ysetter(self): """This function tests the y setter""" Rectangle.reset_objects() r1 = Rectangle(25, 20, 30, 35, 100) r1.y = 55 self.assertEqual(r1.y, 55)
def test_badyvaluewithfuncs(self): """This function tests for bad y value with funcs""" Rectangle.reset_objects() with self.assertRaises(TypeError) as e: r1 = Rectangle(2, 1, 2, print(), 3) self.assertEqual(str(e.exception), 'y must be an integer')