def test_NoDiscounts(self):
		price1 = calculate_discount(100, 10, 0)
		price2 = calculate_discount(100, 0, 30)
		price3 = calculate_discount(100, 0, 0)

		# Check that discount(s) equal to 0 is okay
		self.assertEqual(price1, 90)
		self.assertEqual(price2, 70)
		self.assertEqual(price3, 100)
	def test_NegativeInputs(self):
		# Check that a ValueError is returned with negative input(s)
		with self.assertRaises(ValueError):
			price = calculate_discount(-100, 10, 30)
		with self.assertRaises(ValueError):
			price = calculate_discount(100, -10, 30)
		with self.assertRaises(ValueError):
			price = calculate_discount(100, 10, -30)
		with self.assertRaises(ValueError):
			price = calculate_discount(-100, -10, -30)
Exemple #3
0
    def testCalculate_discount(self):
        discounted_price = calculate_discount(100, .1, 20)
        #check that the right values are returned
        self.assertEqual(discounted_price, 70)

        discounted_price = calculate_discount(100, 0, 0)
        #check that the right values are returned
        self.assertEqual(discounted_price, 100)

        discounted_price = calculate_discount(100, 1, 10)
        #check that the right values are returned
        self.assertEqual(discounted_price, -10)
    def testCalculate_discount(self):
        discounted_price = calculate_discount(100,.1,20)
        #check that the right values are returned
        self.assertEqual(discounted_price, 70)
        
        discounted_price = calculate_discount(100, 0 , 0)
        #check that the right values are returned
        self.assertEqual(discounted_price, 100)

        discounted_price = calculate_discount(100, 1 , 10)
        #check that the right values are returned
        self.assertEqual(discounted_price, -10)
	def testDiscountTooLarge(self):
		with self.assertRaises(ValueError):
			final_cost = calculate_discount(100, 100, 100)
 def test_zero_cost(self):
     self.assertEqual(0, calculate_discount(0, 10, 5))
 def test_negative_discount(self):
     self.assertEqual(200, calculate_discount(200, -25, 0))
     self.assertEqual(17.99, calculate_discount(17.99, 0, -20))
	def testWrongType(self):
		with self.assertRaises(ValueError):
			pay = calculate_discount("10",30,0)
	def testNoAbsDiscount(self):
		pay = calculate_discount(200.0,10.0,0)
		self.assertEqual(pay,180.0)
	def testRelativeTooBig(self):
		with self.assertRaises(ValueError):
			total = calculate_discount(100,200,30)
Exemple #11
0
 def testZeroItemCost(self):
     discounted_total = calculate_discount(0, 10, 30)
     self.assertEqual(discounted_total, 0)
Exemple #12
0
 def testProperDiscount(self):
     discounted_total = calculate_discount(200, 10, 30)
     self.assertEqual(discounted_total, 150)
Exemple #13
0
 def testDiscountedTotalBelowZero(self):
     discounted_total = calculate_discount(5, 10, 30)
     self.assertEqual(discounted_total, 0)
Exemple #14
0
 def testItemCostBelowZero(self):
     discounted_total = calculate_discount(-5, 10, 30)
     self.assertEqual(discounted_total, 0)
 def testMoreThanCost(self):
     final_cost = calculate_discount(100, 110, 30)
     self.assertEqual(final_cost, 0)
 def testNoValue(self):
     with self.assertRaises(ValueError):
         final_cost = calculate_discount()
	def testAbsoluteTooBig(self):
		with self.assertRaises(ValueError):
			total = calculate_discount(100,10,90)	
	def testNoDiscount(self):
		pay = calculate_discount(200.0,0,0)
		pay = round(pay,3)
		self.assertEqual(pay,200.0)
 	def testProperDiscountsApplied(self):
 		total = calculate_discount(100, 10, 30)
 		self.assertEqual(total, 60.00)
	def testNegAbsolute(self):
		pay = calculate_discount(200.0,10.0,-30.0)
		pay = round(pay,3)
		self.assertEqual(pay,210.0)
	def testZeroDiscount(self):
		total = calculate_discount(100, 0, 0)
		self.assertEqual(total, 100.00)	
 def test_discount_greater_than_cost(self):
     self.assertEqual(0, calculate_discount(212.50, 150, 0))
     self.assertEqual(0, calculate_discount(5, 0, 10))
	def testItemCostNotNegative(self):
		discount_price = calculate_discount(-100, 10, 30)
		self.assertEqual(discount_price, "Item cost cannot be a negative number")
 def test_negative_cost(self):
     self.assertEqual(0, calculate_discount(-10, 10, 5))
	def testRelativeDiscountTooHigh(self):
		discount_price = calculate_discount(100, 20000, 30)
		self.assertEqual(discount_price, "Relative discount is too high")
 def test_zero_discounts(self):
     self.assertEqual(200, calculate_discount(200, 0, 0))
	def testAbsoluteDiscountTooHigh(self):
		discount_price = calculate_discount(100, 10, 1000)
		self.assertEqual(discount_price, "Absolute discount is too high")
	def testDiscountNegative(self):
		with self.assertRaises(ValueError):
			final_cost = calculate_discount(100, -10, 1)
	def testAccurateDiscount(self):
	#case 1 --> verify right values are returned for normal cases
		discount_price = calculate_discount	(100, 10, 30)

		self.assertEqual(discount_price, 60)
 def testNegative2(self):
     final_cost = calculate_discount(100, 10, -30)
     self.assertEqual(final_cost, 120)
 def testItemCostBelowZero(self):
     discounted_total = calculate_discount(-5, 10, 30)
     self.assertEqual(discounted_total, 0)
 def testAllZero(self):
     final_cost = calculate_discount(0, 0, 0)
     self.assertEqual(final_cost, 0)
 def testDiscountedTotalBelowZero(self):
     discounted_total = calculate_discount(5, 10, 30)
     self.assertEqual(discounted_total, 0)
 def testNegative1(self):
     final_cost = calculate_discount(100, -10, 30)
     
     # Check that the right values are returned
     self.assertEqual(final_cost, 80)
 def testProperDiscount(self):
     discounted_total = calculate_discount(200, 10, 30)
     self.assertEqual(discounted_total, 150)
	def testNoRelativeDiscount(self):
		pay = calculate_discount(200.0,0,30.0)
		pay = round(pay,3)
		self.assertEqual(pay,170.0)
 def testZeroItemCost(self):
     discounted_total = calculate_discount(0, 10, 30)
     self.assertEqual(discounted_total, 0)
	def testPricelessthanAbsDis(self):
		with self.assertRaises(ValueError):
			pay = calculate_discount(10.0,10.0,30.0)
 def test_zero_relative_discount(self):
     self.assertEqual(90, calculate_discount(100, 0, 10))
	def testNegRelative(self):
		pay = calculate_discount(200.0,-10.0,20.0)
		pay = round(pay,3)
		self.assertEqual(pay,200.0)
 def test_zero_absolute_discount(self):
     self.assertEqual(100, calculate_discount(200, 50, 0))
	def testBasicCase(self):
		pay = calculate_discount(200.0,10.0,30.0)
		self.assertEqual(pay,150.0)
 def test_mixed_discounts(self):
     self.assertEqual(140, calculate_discount(200, 25, 10))
     self.assertEqual(119.75, calculate_discount(195.44, 33.33, 10.55))