Advertisement
pacho_the_python

Untitled

Apr 16th, 2024
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. import unittest
  2.  
  3. class TestGetWaiters(unittest.TestCase):
  4.     def setUp(self):
  5.         # Mock data for testing
  6.         self.waiters = [
  7.             {'name': 'John', 'total_earnings': 100},
  8.             {'name': 'Alice', 'total_earnings': 200},
  9.             {'name': 'Bob', 'total_earnings': 150},
  10.             {'name': 'Eve', 'total_earnings': 300}
  11.         ]
  12.         self.test_object = YourClass(self.waiters)  # Replace YourClass with your actual class name
  13.  
  14.     def test_no_filter(self):
  15.         # Test when no filter is applied
  16.         result = self.test_object.get_waiters()
  17.         self.assertEqual(len(result), 4)  # Expecting all 4 waiters
  18.  
  19.     def test_min_earnings_filter(self):
  20.         # Test when only min_earnings filter is applied
  21.         result = self.test_object.get_waiters(min_earnings=150)
  22.         self.assertEqual(len(result), 3)  # Expecting 3 waiters with earnings >= 150
  23.  
  24.     def test_max_earnings_filter(self):
  25.         # Test when only max_earnings filter is applied
  26.         result = self.test_object.get_waiters(max_earnings=200)
  27.         self.assertEqual(len(result), 3)  # Expecting 3 waiters with earnings <= 200
  28.  
  29.     def test_both_filters(self):
  30.         # Test when both min_earnings and max_earnings filters are applied
  31.         result = self.test_object.get_waiters(min_earnings=150, max_earnings=250)
  32.         self.assertEqual(len(result), 2)  # Expecting 2 waiters with earnings between 150 and 250
  33.  
  34.     def test_invalid_filters(self):
  35.         # Test when invalid filters are provided
  36.         result = self.test_object.get_waiters(min_earnings=500, max_earnings=1000)
  37.         self.assertEqual(len(result), 0)  # Expecting no waiters as earnings range is invalid
  38.  
  39. if __name__ == '__main__':
  40.     unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement