Advertisement
pacho_the_python

Untitled

Apr 16th, 2024
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.84 KB | None | 0 0
  1. import unittest
  2.  
  3. class TestRestaurant(unittest.TestCase):
  4.  
  5.     def setUp(self):
  6.         # Initialize a restaurant with a capacity of 3
  7.         self.restaurant = Restaurant("Test Restaurant", 3)
  8.  
  9.     def test_init(self):
  10.         # Test if the restaurant is initialized correctly
  11.         self.assertEqual(self.restaurant.name, "Test Restaurant")
  12.         self.assertEqual(self.restaurant.capacity, 3)
  13.         self.assertEqual(self.restaurant.waiters, [])
  14.  
  15.     def test_name_setter(self):
  16.         # Test setting the name property with a valid name
  17.         self.restaurant.name = "New Restaurant Name"
  18.         self.assertEqual(self.restaurant.name, "New Restaurant Name")
  19.  
  20.         # Test setting the name property with an invalid name
  21.         with self.assertRaises(ValueError):
  22.             self.restaurant.name = ""
  23.  
  24.     def test_capacity_setter(self):
  25.         # Test setting the capacity property with a valid capacity
  26.         self.restaurant.capacity = 5
  27.         self.assertEqual(self.restaurant.capacity, 5)
  28.  
  29.         # Test setting the capacity property with an invalid capacity
  30.         with self.assertRaises(ValueError):
  31.             self.restaurant.capacity = -1
  32.  
  33.     def test_add_waiter(self):
  34.         # Test adding a waiter to the restaurant
  35.         result = self.restaurant.add_waiter("John")
  36.         self.assertEqual(result, "The waiter John has been added.")
  37.  
  38.         # Test adding a waiter with the same name
  39.         result = self.restaurant.add_waiter("John")
  40.         self.assertEqual(result, "The waiter John already exists!")
  41.  
  42.         # Test adding a waiter when the restaurant is at full capacity
  43.         self.restaurant.add_waiter("Alice")
  44.         self.restaurant.add_waiter("Bob")
  45.         result = self.restaurant.add_waiter("Eve")
  46.         self.assertEqual(result, "No more places!")
  47.  
  48.     def test_remove_waiter(self):
  49.         # Test removing a waiter from the restaurant
  50.         self.restaurant.add_waiter("John")
  51.         result = self.restaurant.remove_waiter("John")
  52.         self.assertEqual(result, "The waiter John has been removed.")
  53.  
  54.         # Test removing a waiter that does not exist
  55.         result = self.restaurant.remove_waiter("Alice")
  56.         self.assertEqual(result, "No waiter found with the name Alice.")
  57.  
  58.     def test_get_total_earnings(self):
  59.         # Test getting total earnings when there are no waiters
  60.         result = self.restaurant.get_total_earnings()
  61.         self.assertEqual(result, 0)
  62.  
  63.         # Test getting total earnings when there are waiters
  64.         self.restaurant.add_waiter("John")
  65.         self.restaurant.add_waiter("Alice")
  66.         self.restaurant.waiters[0]['total_earnings'] = 100
  67.         self.restaurant.waiters[1]['total_earnings'] = 200
  68.         result = self.restaurant.get_total_earnings()
  69.         self.assertEqual(result, 300)
  70.  
  71.     def test_get_waiters(self):
  72.         # Test getting waiters with no filters
  73.         self.restaurant.add_waiter("John")
  74.         self.restaurant.add_waiter("Alice")
  75.         self.restaurant.add_waiter("Bob")
  76.         result = self.restaurant.get_waiters()
  77.         self.assertEqual(len(result), 3)
  78.  
  79.         # Test getting waiters with min_earnings filter
  80.         self.restaurant.waiters[0]['total_earnings'] = 100
  81.         self.restaurant.waiters[1]['total_earnings'] = 200
  82.         self.restaurant.waiters[2]['total_earnings'] = 300
  83.         result = self.restaurant.get_waiters(min_earnings=150)
  84.         self.assertEqual(len(result), 2)
  85.  
  86.         # Test getting waiters with max_earnings filter
  87.         result = self.restaurant.get_waiters(max_earnings=250)
  88.         self.assertEqual(len(result), 2)
  89.  
  90.         # Test getting waiters with both min_earnings and max_earnings filters
  91.         result = self.restaurant.get_waiters(min_earnings=100, max_earnings=250)
  92.         self.assertEqual(len(result), 2)
  93.  
  94. if __name__ == '__main__':
  95.     unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement