예제 #1
0
 def test_BoxingGLove(self):
     glove = BoxingGlove('Punchy the third')
     self.assertEqual(glove.name, 'Punchy the third')
     self.assertEqual(glove.weight, 10)
     self.assertEqual(glove.price, 10)
     glove.explode()
     glove.punch()
예제 #2
0
 def test_default_boxing_weight(self):
     """Test weight of default boxing gloves"""
     glove = BoxingGlove('Punch Puncher')
     self.assertEqual(glove.weight, 10)
 def test_default_boxing_weight(self):
     """Default boxing gloves are lighter!"""
     glove = BoxingGlove('Punch Puncher')
     self.assertEqual(glove.weight, 10)
Of course, Acme doesn't just sell generic products - it sells all sorts of
special specific things!

Make a subclass of `Product` named `BoxingGlove` that does the following:

- Change the default `weight` to 10 (but leave other defaults unchanged)
- Override the `explode` method to always return "...it's a glove."
- Add a `punch` method that returns "That tickles." if the weight is below 5,
  "Hey that hurt!" if the weight is greater or equal to 5 but less than 15, and
  "OUCH!" otherwise
  
Example test run:

```python
>>> from acme import BoxingGlove
>>> glove = BoxingGlove('Punchy the Third')
>>> glove.price
10
>>> glove.weight
10
>>> glove.punch()
'Hey that hurt!'
>>> glove.explode()
"...it's a glove."
```

### Part 4 - Class Report

Now you can represent your inventory - let's use these classes and write an
`acme_report.py` module to generate random products and print a summary of them.
For the purposes of these functions we will only use the `Product` class.
 def test_subclass_default(self):
     prod = BoxingGlove("Mike_Tyson")
     self.assertEqual(prod.price, 10)
예제 #6
0
    def punch(self):
        if self.weight < 5:
            return "That tickles."
        elif self.weight >= 5 and self.weight < 15:
            return "Hey that hurt!"
        else:
            return "OUCH!"

%load acme.py
from acme import Product
            prod = Product("A Cool Toy")
    print("prod.identifier", prod.identifier)
    print("prod.name", prod.name)
    print("prod.price", prod.price)
    print("prod.weight", prod.weight)
    print("prod.flammability", prod.flammability)

%load acme.py
from acme import Product
            prod = Product("A Cool Toy")
    print(prod.stealability())
    print(prod.explode())

%load acme.py
from acme import Product, BoxingGlove

           glove = BoxingGlove('Punchy the Third')
    print(glove.price) # 10
    print(glove.weight) # 10
    print(glove.punch())
    pip install -i https://test.pypi.org/simple/ lambdata-rokshanaparul
 def test_boxing_glove_price(self):
     """Test that the boxing glove SKU's default price is 10."""
     glove = BoxingGlove('Test boxing glove SKU')
     self.assertEqual(glove.price, 10)
예제 #8
0
파일: acme_test.py 프로젝트: rhiag/unit3
def test_default_attributes_boxing_glove():
    """Testing the default values of BoxingGlove"""
    glove = BoxingGlove("New Gloves")
    assert glove.price == 10
    assert glove.weight == 10
예제 #9
0
 def test_default_boxingGlove(self):
     glove = BoxingGlove('Test Punch')
     self.assertEqual(glove.weight, 10)
     self.assertEqual(glove.stealability(), 'Very stealable!')
     self.assertEqual(glove.explode(), "...it's a glove.")
예제 #10
0
from acme import Product
from acme import BoxingGlove

prod = Product('A Cool Toy')
print('name:', prod.name)
print('price:', prod.price)
print('weight:', prod.weight)
print('flammability:', prod.flammability)
print('identifier:', prod.identifier)

print('stealable?', prod.stealability())
print('explodable?', prod.explode())

print("=========================")

glove = BoxingGlove('Punchy the Third')
print('Glove price:', glove.price)
print('Glove weight:', glove.weight)
print('Glove punch:', glove.punch())
print('Glove explode:', glove.explode())
예제 #11
0
from acme import Product
from acme import BoxingGlove
from acme_report import generate_products, inventory_report

prod = Product('A Cool Toy')

glove = BoxingGlove('a glove')

print(prod.name)

print(prod.price)

print(prod.weight)

print(prod.flammability)

print(prod.identifier)

print(prod.stealability())

print(prod.explode())

print(glove.price)

print(glove.weight)

print(glove.punch())

print(glove.explode())

print(inventory_report(generate_products()))
예제 #12
0
from acme import Product
from acme import BoxingGlove

# part 1, 2
prod = Product('A Cool Toy')

print(prod.name)  # 'A Cool Toy'
print(prod.price)  # 10
print(prod.weight)  # 20
print(prod.flammability)  # 0.5
print(prod.identifier)  # ?

print(prod.stealability())
print(prod.explode())

# part 3
glove = BoxingGlove('Punchy the Third')
print(glove.price)  # 10
print(glove.weight)  # 10
print(glove.punch())  # 'Hey that hurt!'
print(glove.explode())  # "...it's a glove."
예제 #13
0
 def test_default_boxing_weight(self):
     """Test default boxing gloves are lighter."""
     glove = BoxingGlove("Test glove")
     self.assertEqual(glove.weight, 10)
예제 #14
0
 def test_default_boxing_glove_weight(self):
     """
     Test default Boxing Glove weight == 10.
     """
     glove = BoxingGlove('Test Boxing Glove')
     self.assertEqual(glove.weight, 10)
예제 #15
0
from acme import Product
from acme import BoxingGlove

prod = Product("A Cool Toy")
glove = BoxingGlove("Punchy the Third")

print(prod.name)
print(prod.price)
print(prod.weight)
print(prod.flammability)
print(prod.identifier)
prod.stealability()
prod.explode()
print(glove.price)
print(glove.weight)
glove.punch()
glove.explode()