def generate_products(num_products=30): products = [] for p in range(30): x = Product(name=generate_names(adjectives, nouns), price=random.randint(5, 100), weight=random.randint(5, 100), flammability=random.uniform(0.0, 2.5)) products.append(x) return products
def generate_products(num_products=30): products = [] for num_product in range(num_products): name = sample(ADJECTIVES, 1)[0] + ' ' + sample(NOUNS, 1)[0] price = randint(5,100) weight = randint(5,100) flammability = uniform(0,2.5) product = Product(name =name,price = price,weight= weight,flammability=flammability) products.append(product) return products
def test_default_product_price(self): prod = Product('Test Product') self.assertEqual(prod.price, 10) self.assertIsInstance(prod.price, int)
def test_explode(self): explode1 = Product('explode1', 0, 10, 0.5) explode2 = Product('explode2', 0, 20, 0.5) explode3 = Product('explode3', 0, 49, 1) explode4 = Product('explode4', 0, 50, 1) self.assertEqual(explode1.explode(), "...fizzle.") self.assertEqual(explode2.explode(), "...boom!") self.assertEqual(explode3.explode(), "...boom!") self.assertEqual(explode4.explode(), "...BABOOM!!")
def test_steability(self): steal1 = Product('steal1', 10, 20) steal2 = Product('steal2', 5, 20) steal3 = Product('steal3', 20, 20) steal4 = Product('steal4', 21, 20) self.assertEqual(steal1.stealability(), "Kinda stealable.") self.assertEqual(steal2.stealability(), "Not so stealable...") self.assertEqual(steal3.stealability(), "Very stealable!") self.assertEqual(steal4.stealability(), "Very stealable!")
def test_default_flammability(self): prod = Product('Test Product') self.assertEqual(prod.flammability, 0.5) self.assertIsInstance(prod.flammability, float)
def test_default_weight(self): prod = Product('Test Product') self.assertEqual(prod.weight, 20) self.assertIsInstance(prod.weight, int)
def test_default_product_price(self): prod = Product('Test Produc') self.assertEqual(prod.price, 10)
def test_product_weight(self): prod = Product('Test Produc') self.assertEqual(prod.weight, 20)