コード例 #1
0
 def test_equality(self):                    # Test 7: Test circle equality
     c = Circle(2) == Circle(3)
     eq = c.__str__()
     self.assertEqual(eq, "False")
     c = Circle(1) == Circle(1)
     eq = c.__str__()
     self.assertEqual(eq, "True")
コード例 #2
0
 def test_inequality(self):                  # Test 8: Test circle inequality
     c = Circle(3) > Circle(2)
     eq = c.__str__()
     self.assertEqual(eq, "True")
     c = Circle(235) < Circle(0)
     eq = c.__str__()
     self.assertEqual(eq, "False")
コード例 #3
0
def test__str__():
    """
    Verifies the built-in string method and built-in repr method
    gets set as expected when initializing a Circle object.
    """
    c2 = Circle(10)
    assert repr(c2) == "Circle(10)"
    assert c2.__str__() == "Circle with radius: 10.00000"
コード例 #4
0
def test_str():
    c = Circle(4.32)
    assert c.__str__() == "Circle with radius 4.32"
    assert str(c) == "Circle with radius 4.32"
コード例 #5
0
ファイル: test_circle.py プロジェクト: zconn/Fall2018-PY210A
def test_str():
    """Tests string method for circle object."""
    c = Circle(10)
    assert c.__str__() == "Circle with radius 10.000000"
コード例 #6
0
    # Test change to radius results in updated diameter
    c11.radius = 55
    assert c11.diameter == 110

    # Test change to diameter results in updated radius
    c11.diameter = 100
    assert c11.radius == 50

    # Test alternate constructor
    c12 = Circle.from_diameter(300)
    assert c12.radius == 150
    assert int(c12.area) == 70685

    # Test str and repr
    assert c11.__str__() == "Circle(50.0)"
    assert c12.__repr__() == "Circle(150.0)"

    # Test numeric protocols
    assert c11 + c12 == Circle(200)
    assert c12 - c11 == Circle(100)
    assert c11 * c12 == Circle(7500)
    assert c12 / c11 == (Circle(3))
    assert c11 * 5 == Circle(250)
    assert c12 + 50 == Circle(200)
    assert c12 - 25 == Circle(125)
    assert c12 / 50 == Circle(3)

    # Test comparison operators
    assert c11 < c12
    assert c12 > c11
コード例 #7
0
def test_str_method():
    c = Circle(8)
    assert c.__str__() == 'Circle with a radius: 8'
コード例 #8
0
 def test_circle_str(self):
     c = Circle(4)
     self.assertEqual(c.__str__(), 'Circle with radius: 4.0')
     self.assertEqual(c.__repr__(), 'Circle(4)')
コード例 #9
0
def test_print():
    c = Circle(4)
    assert c.__str__() == "Circle with radius: 4"
コード例 #10
0
class TestCircle(unittest.TestCase):
    def setUp(self):
        self.c1 = Circle(2)
        self.c2 = Circle(4.5)
        self.c3 = Circle(6)
        self.c4 = Circle.from_diameter(3)
        self.c5 = Circle(6)

    def tearDown(self):
        pass

    def test__init__(self):
        with self.assertRaises(TypeError):
            a_circle = Circle(-1)
            another_circle = Circle('tri')

    def test_diameter(self):
        self.assertEqual(self.c1.diameter, 4)
        self.assertEqual(self.c2.diameter, 4.5 * 2)
        self.assertEqual(self.c3.diameter, 12)

    def test_area(self):
        self.assertEqual(self.c1.area, round(math.pi * 2**2, 5))
        self.assertEqual(self.c2.area, round(math.pi * 4.5**2, 5))
        self.assertEqual(self.c3.area, round(math.pi * 6**2, 5))

    def test_from_diameter(self):
        self.assertEqual(self.c4.diameter, 3)
        self.assertEqual(self.c4.radius, 3 / 2)

        with self.assertRaises(TypeError):
            c = Circle.from_diameter('t')

    def test__str__(self):
        test_template = 'Circle with radius: {}'
        self.assertEqual(self.c1.__str__(), test_template.format(2))
        self.assertEqual(self.c2.__str__(), test_template.format(4.5))
        self.assertEqual(self.c3.__str__(), test_template.format(6))

    def test__repr__(self):
        test_template = 'Circle({})'
        self.assertEqual(self.c1.__repr__(), test_template.format(2))
        self.assertEqual(self.c2.__repr__(), test_template.format(4.5))
        self.assertEqual(self.c3.__repr__(), test_template.format(6))

    def test__add__(self):
        self.assertEqual(self.c1 + self.c3, Circle(8))
        self.assertEqual(self.c2 + self.c3, Circle(10.5))

        with self.assertRaises(TypeError):
            self.c1 + 2

    def test__iadd__(self):
        self.assertEqual(self.c1.__iadd__(self.c2), Circle(6.5))

        with self.assertRaises(TypeError):
            self.c1 += 6

    def test__mul__(self):
        self.assertEqual(self.c5 * 2, Circle(12))
        self.assertEqual(self.c2 * 5, Circle(4.5 * 5))

        with self.assertRaises(TypeError):
            self.c3 * self.c5

    def test__rmul__(self):
        self.assertEqual(2 * self.c5, Circle(6 * 2))
        self.assertEqual(5 * self.c2, Circle(4.5 * 5))

    def test__imul__(self):
        self.assertEqual(self.c3.__imul__(3), Circle(18))
        self.assertEqual(self.c2.__imul__(4), Circle(4.5 * 4))

        with self.assertRaises(TypeError):
            self.c3 *= self.c1

    def test__gt__(self):
        self.assertTrue(self.c2.radius > self.c1.radius)
        self.assertTrue(self.c5.radius > self.c1.radius)
        self.assertFalse(self.c2.radius > self.c5.radius)

    def test__lt__(self):
        self.assertTrue(self.c1.radius < self.c5.radius)
        self.assertFalse(self.c2.radius < self.c1.radius)
        self.assertTrue(self.c1.radius < self.c3.radius)

    def test__eq__(self):
        self.assertTrue(self.c3.radius == self.c5.radius)
コード例 #11
0
 def test_addition(self):                    # Test 5: Test circle addition (adding multiple circles)
     c = Circle(1) + Circle(1)
     c_print = c.__str__()
     self.assertEqual(c_print, "Circle 2")
コード例 #12
0
def test_circle_str():
    """ Verify circle __str__ output """
    radius = 5
    a_circle = Circle(radius)
    assert a_circle.__str__() == f"Circle with radius: {radius}"
コード例 #13
0
def test_str():
    c = Circle(4.32)
    assert c.__str__() == "Circle with radius 4.32"
    assert str(c) == "Circle with radius 4.32"
コード例 #14
0
def test_str():
    my_circle = Circle(3)
    assert my_circle.__str__() == "circle with radius {:.6f}".format(
        my_circle.rad)
コード例 #15
0
def test_str():
    c = Circle(4)
    s = 'Circle with radius: 4.00'
    cs = c.__str__()  # note, must perform bound method call with ()
    assert s == cs
コード例 #16
0
def test_str():
    c = Circle(4)
    assert c.__str__() == "Circle with radius: 4.000000"
コード例 #17
0
def  test_str():
    c = Circle(4)
    s = 'Circle with radius: 4.00'
    cs = c.__str__()  # note, must perform bound method call with ()
    assert s == cs
コード例 #18
0
 def test_multiplication(self):              # Test 6: Test circle multiplication (multiplying multiple circles)
     c = Circle(2) * Circle(2)
     c_print = c.__str__()
     self.assertEqual(c_print, "Circle 4")
コード例 #19
0
def test_str_method():
    c = Circle(4)
    assert c.__str__() == 'Circle with radius: 4.000000'
コード例 #20
0
def test_print():
    c = Circle(4)
    assert c.__str__() == 'Circle with radius: 4'
    assert repr(c) == 'Circle(4)'
コード例 #21
0
def test_str():
    c = Circle(4)
    assert c.__str__() == "Circle with radius: 4.000000"