Ejemplo n.º 1
0
def main():
    # Create a circle and test it
    circle1 = Circle(5)
    print(circle1.area())
    print(circle1.circumference())
    circle2 = Circle(10)
    print(circle2.area())
    print(circle2.circumference())
Ejemplo n.º 2
0
class TestCircle(unittest.TestCase):
    def setUp(self):
        self.circle = Circle(29)

    # Return pi
    def test_area(self):
        self.assertEqual(2642.079421669016, self.circle.area())
Ejemplo n.º 3
0
def test_circle_zero_radius():
    centre = (1, 1)
    radius = 0
    circle = Circle(centre, radius)

    assert circle.perimeter() == 0
    assert circle.area() == 0
Ejemplo n.º 4
0
 def test_10_set_area(self):
     c = Circle(10)
     try:
         c.area = 11
     except AttributeError:
         caught = 'AttributeError'
     self.assertEqual(caught, 'AttributeError')
Ejemplo n.º 5
0
def main():
    # Use this to test the constructor

    c1 = Circle(0, 0, 3)

    # Use these to test the getters

    print("c1 center =", c1.getCenter())
    print("c1 radius =", c1.getRadius())

    # Use these to test the setters

    c1.setCenter(1, 2)
    c1.setRadius(5)
    print()
    print("Modified c1 center =", c1.getCenter())
    print("Modified c1 radius =", c1.getRadius())

    # Use this to test the area method

    print("c1 area =", c1.area())

    # Use this to test the __str__

    print()
    print("Modified Circle c1:")
    print(c1)
 def test_zero_radius(self):
     c = Circle(0)
     perimeter = c.perimeter()
     area = c.area()
     exp_perimeter = 0
     exp_area = 0
     self.assertEqual(perimeter, exp_perimeter)
     self.assertEqual(area, exp_area)
 def test_positive_radius(self):
     c = Circle(10)
     perimeter = c.perimeter()
     area = c.area()
     exp_perimeter = 62.83185307179586
     exp_area = 314.1592653589793
     self.assertEqual(perimeter, exp_perimeter)
     self.assertEqual(area, exp_area)
Ejemplo n.º 8
0
def test_set_area():
    c = Circle(4)
    try:
        c.area = 10
    except AttributeError as error:
        assert error.message == "can't set attribute"
    else:
        assert False
Ejemplo n.º 9
0
 def test_diameter_changeable_but_area_not(self):
     circle = Circle(2)
     self.assertEqual(circle.diameter, 4)
     self.assertEqual(circle.area, math.pi * 4)
     circle.diameter = 3
     self.assertEqual(circle.radius, 1.5)
     with self.assertRaises(AttributeError):
         circle.area = 3
Ejemplo n.º 10
0
def test_circle_area():
    c = Circle(2)
    assert c.area == 12.566370614359172

    with pytest.raises(Exception) as excinfo:
        c = Circle(2)
        c.area = 16
    assert str(excinfo.value) == "can't set attribute"
Ejemplo n.º 11
0
def test_circle_change_area_error():
    msg = ""
    c = Circle(2)
    try:
        c.area = 42
    except AttributeError as e:
        msg = e.args[0]
    assert msg == "can't set attribute"
Ejemplo n.º 12
0
class TestCircle(unittest.TestCase):
    def setUp(self):
        self.tmp = Circle(1, 2, 3)
        self.tmp2 = Circle(0, 0, 0)

    def test_init(self):

        self.assertEqual(self.tmp.pt, Point(1, 2))
        self.assertEqual(self.tmp.pt.x, 1)
        self.assertEqual(self.tmp.pt.y, 2)
        self.assertEqual(self.tmp.radius, 3)
        with self.assertRaises(ValueError):
            Circle(0, 0, -1)

    def test_repr(self):
        self.assertEqual(repr(self.tmp), "Circle(1, 2, 3)")

    def test_eq(self):
        self.assertFalse(self.tmp == Circle(1, 2, 4))
        self.assertTrue(self.tmp == Circle(1.0, 2.0, 3.0))
        self.assertTrue(self.tmp == Circle(1, 2, 3))

    def test_ne(self):
        self.assertTrue(self.tmp != Circle(1, 2, 4))
        self.assertFalse(self.tmp != Circle(1.0, 2.0, 3.0))
        self.assertFalse(self.tmp != Circle(1, 2, 3))

    def test_area(self):
        self.assertEqual(self.tmp.area(), math.pi * pow(3, 2))
        self.assertEqual(self.tmp2.area(), 0)

    def test_move(self):
        self.tmp.move(1, 2)
        self.assertEqual(self.tmp, Circle(2, 4, 3))
        self.tmp2.move(1, 2)
        self.assertEqual(self.tmp2, Circle(1, 2, 0))

    def test_cover(self):
        self.assertEqual(self.tmp.cover(self.tmp2), Circle(1, 2, 3))
        self.assertEqual(self.tmp2.cover(self.tmp), Circle(1, 2, 3))
        self.assertEqual(
            Circle(0, 0, 2).cover(Circle(4, 0, 2)), Circle(2, 0, 4))

    def tearDown(self):
        pass
Ejemplo n.º 13
0
def test_area():
    c = Circle(2)

    assert c.area == 4 * pi

    with pytest.raises(AttributeError) as e:
        c.area = 4

    assert str(e.value) == 'can\'t set attribute'
def test_set_area():
    '''
    Test 7:  Testing AttributeError
    '''
    #pylint: disable=C0103
    c = Circle(7)

    with pytest.raises(AttributeError):
        c.area = 10
Ejemplo n.º 15
0
def main(args):
    radius = int(args[1])

    print("radius: ", radius)
    print("Creating circle of Radius = %s" % (radius))

    c1 = Circle(radius)

    print("Perimeter: ", c1.perimeter())
    print("Area: ", c1.area())
Ejemplo n.º 16
0
def test_area():
    c = Circle(2)
    assert c.area == 12.566370614359172
    s = Sphere(2)
    assert s.area == 50.26548245743669
    s = Sphere(4)
    assert round(s.area, 5) == 201.06193

    with pytest.raises(AttributeError):
        c.area = 42
        s.area = 42
Ejemplo n.º 17
0
def test_area():
    my_circle = Circle(5)

    assert my_circle.area == (pi * 5 ** 2)

    # Area should not be able to be set
    try:
        my_circle.area = 10
    except AttributeError:
        pass
    else:
        assert False
Ejemplo n.º 18
0
def test_area():
    c = Circle(10)
    assert (c.area == 314.1592653589793)

    # Verify area isn't settable
    try:
        c2 = Circle(2)
        c2.area = 42
    except AttributeError:
        pass
    else:
        assert (False)
Ejemplo n.º 19
0
def test_set_area():
    """
    tests the area of a circle then assigns a new area
    and re-tests the new area. This uses the isclose module
    to test the relative tolerance of the radius and diameter,
    separately, to one one-hundredth
    :return: None
    """
    c = Circle(2)
    assert isclose(c.area, (pi * 2**2), rel_tol=.01)
    c.area = 500
    assert isclose(c.area, 500, rel_tol=.01)
Ejemplo n.º 20
0
def test_change_values_area():
    """
    tests changing the assigned radius of a circle
    by assigning a new area for the circle and testing
    the resultant radius and diameter with the math, isclose
    module.  This isclose module tests the relative tolerance
    of the radius and diameter, separately, to one one-hundredth
    :return: None
    """
    c = Circle(13)
    c.area = 6
    assert isclose(c.radius, 1.38, rel_tol=.01)
    assert isclose(c.diameter, c.radius * 2, rel_tol=.01)
Ejemplo n.º 21
0
 def test_diameter_changeable_but_area_not(self):
     """
     The value of diameter should *also* be changable, and should update
     the radius automatically, but the area should raise an error when a
     caller attempts to change the value
     """
     circle = Circle(2)
     self.assertEqual(circle.diameter, 4)
     self.assertEqual(circle.area, math.pi * 4)
     circle.diameter = 3
     self.assertEqual(circle.radius, 1.5)
     with self.assertRaises(AttributeError):
         circle.area = 3
    def test_circle_initialization_str_repr_and_properties(self):
        c1 = Circle(10)
        c2 = Circle.from_diameter(40)
        assert type(c2) == Circle
        self.assertEqual(c1.radius, 10.0)
        self.assertEqual(c1.diameter, 20.0)
        self.assertEqual(c2.radius, 20.0)
        self.assertEqual(c2.diameter, 40.0)
        c1.radius = 30
        self.assertEqual(c1.diameter, 60.0)
        c2.diameter = 30
        self.assertEqual(c2.radius, 15.0)

        self.assertEqual(str(c1), "Circle with radius: 30.000")
        self.assertEqual(repr(c1), "Circle(30.0)")
        self.assertEqual(round(c1.area), 2827)
        with pytest.raises(AttributeError) as error:
            c1.area = 50
            assert "AttributeError: can't set attribute" in error
Ejemplo n.º 23
0
class TestCircle(unittest.TestCase):
    def setUp(self):
        self.c1 = Circle(1, 1, 1)
        self.c2 = Circle(3, 1, 1)

    def test_repr(self):
        self.assertEqual(repr(self.c1), "Circle(1, 1, 1)")
        self.assertEqual(repr(self.c2), "Circle(3, 1, 1)")

    def test_eq(self):
        self.assertTrue(self.c1 == Circle(1, 1, 1))
        self.assertFalse(self.c2 == Circle(1, 3, 1))
        with self.assertRaises(Exception) as context:
            self.c1 == 1

        self.assertTrue(isinstance(context.exception, TypeError))

    def test_ne(self):
        self.assertFalse(self.c1 != Circle(1, 1, 1))
        self.assertTrue(self.c2 != Circle(1, 3, 1))
        with self.assertRaises(Exception) as context:
            self.c1 != 1

        self.assertTrue(isinstance(context.exception, TypeError))

    def test_area(self):
        self.assertEqual(self.c1.area(), math.pi)
        self.assertEqual(Circle(1, 1, 5).area(), 25 * math.pi)

    def test_move(self):
        self.assertEqual(self.c1.move(2, 0), self.c2)

    def test_cover(self):
        self.assertEqual(self.c1.cover(self.c2), Circle(2, 1, 2))
        with self.assertRaises(Exception) as context:
            self.c1.cover(2)

        self.assertTrue(isinstance(context.exception, TypeError))

    def tearDown(self):
        pass
Ejemplo n.º 24
0
def test_set_area():

    c = Circle(10)

    with pytest.raises(AttributeError):
        c.area = 100
Ejemplo n.º 25
0
# Tutorial
from circle import Circle

print 'Circuitous version', Circle.version
c = Circle(10)
print 'A circle of radius', c.radius
print 'has an area of', c.area()
print
Ejemplo n.º 26
0
def test_set_area():
    c = Circle(4)

    with pytest.raises(AttributeError):
        c.area = 44
Ejemplo n.º 27
0
def test_circle_area():
    my_circle = Circle(4)
    assert my_circle.area == 50.26548245743669
    #Test that area is read-only
    with pytest.raises(AttributeError):
        my_circle.area = 10
Ejemplo n.º 28
0
def test_areaset():
    c = Circle(2)
    with pytest.raises(AttributeError):
        c.area = 4*pi 
Ejemplo n.º 29
0
def test_no_set_area():
    my_circle = Circle(3)
    with pytest.raises(AttributeError):
        my_circle.area = 20
from circle import Circle

c = Circle(4)
c.set_center([0, 0])
c.set_color("Yellow")

print "Area of %s %sis %f" % (c.get_color(), c.name, c.area())
Ejemplo n.º 31
0
def test_no_set_area():
    c = Circle(4.52)
    with pytest.raises(AttributeError):
        c.area = 5.67
Ejemplo n.º 32
0
def test_area_of_circle():
    circle = Circle(2)
    assert math.isclose(circle.area, 12.566370, rel_tol=1e-7)

    with pytest.raises(AttributeError):
        circle.area = 42
Ejemplo n.º 33
0
from circle import Circle

bbd = 25.1
# NameError: name 'bbd_to_radius' is not defined
c = Circle(bbd_to_radius(bbd))

print 'A circle with a bbd of 25.1'
print 'has a radius of',c.radius
print 'and an area of',c.area()
print
Ejemplo n.º 34
0
def test_area():
    c = Circle(4)
    assert c.area == math.pi * 16
    with pytest.raises(AttributeError):
        c.area = 1
Ejemplo n.º 35
0
def test_step4():
    c = Circle(2)
    assert c.area == pi * 2**2
    with pytest.raises(AttributeError):
        c.area = 10
Ejemplo n.º 36
0
# Tutorial
from circle import Circle

print "Citrus version", Circle.version

c = Circle(10)
print "A circle of radius", c.radius
print "has an area of", c.area()
print
Ejemplo n.º 37
0
 def test_area(self):
     cir = Circle(3)
     self.assertEqual(28.27, cir.area())
Ejemplo n.º 38
0
print "the diameter:", c.diameter
print "the area:", c.area

print
print "setting the diameter to 6:"
c.diameter = 6
print "the radius:", c.radius    
print "the diameter:", c.diameter
print "the area:", c.area

print
print "trying to delete the diameter"
try:
    del c.diameter
except Exception as err:
    print "Whoops:", err
    
print
print "trying to set the area"
try:
    c.area = 40.0
except Exception as err:
    print "Whoops:", err

c1 = Circle(2)
c2 = Circle(4)
 
print
print "adding two circles together"
print c1 + c2
Ejemplo n.º 39
0
 def test_step4(self):
     c = Circle(2)
     self.assertAlmostEqual(c.area, 2**2 * pi)
     with self.assertRaises(AttributeError):
         c.area = 42
         print("The user cannot set the area")
from circle import Circle

c = Circle(4)
c.set_center([0, 0])
c.set_color("Yellow")
c.name = "Sun"
print "Area of %s is %f" % (c.name, c.area())