Advertisement
go6odn28

storage_test_code

Feb 24th, 2024
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. class Storage:
  2.     def __init__(self, capacity):
  3.         self.capacity = capacity
  4.         self.storage = []
  5.  
  6.     def add_product(self, product: str):
  7.         if len(self.storage) < self.capacity:
  8.             self.storage.append(product)
  9.  
  10.     def get_products(self):
  11.         return self.storage
  12.  
  13.  
  14. # TEST CODE
  15. from unittest import TestCase, main
  16.  
  17.  
  18. class StorageTest(TestCase):
  19.     def test_01_init(self):
  20.         storage1 = Storage(2)
  21.         self.assertEqual(storage1.capacity, 2)
  22.         self.assertEqual(storage1.storage, [])
  23.  
  24.     def test_2_add_product(self):
  25.         storage1 = Storage(2)
  26.         storage1.add_product("apple")
  27.         self.assertEqual(storage1.storage, ["apple"])
  28.  
  29.     def test_3_add_product_with_not_enough_capacity(self):
  30.         storage1 = Storage(1)
  31.         storage1.add_product("apple")
  32.         storage1.add_product("banana")
  33.         storage1.add_product("orange")
  34.         self.assertEqual(storage1.storage, ["apple"])
  35.  
  36.     def test_4_get_product(self):
  37.         storage1 = Storage(2)
  38.         storage1.add_product("apple")
  39.         storage1.add_product("banana")
  40.         result = storage1.get_products()
  41.         self.assertEqual(result, ["apple", "banana"])
  42.  
  43.  
  44. if __name__ == "__main__":
  45.     main()
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement