SHARE
TWEET

Untitled

a guest Jun 25th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import unittest
  2. from Automat import Automat
  3. from Bank import Bank
  4. from Item import Item
  5. from exceptions.NoItemException import NoItemException
  6.  
  7.  
  8. class AutomatTest(unittest.TestCase):
  9.  
  10.     def test_checkPriceOfGivenID(self):
  11.         bank = Bank()
  12.         automat = Automat(bank)
  13.         Cola = Item(2)
  14.         automat.add_object(Cola)
  15.         self.assertEqual(automat.find_price_of_given_id(30), 2)
  16.  
  17.     def test_checkPriceOfGivenIDWithInvalidID(self):
  18.         bank = Bank()
  19.         automat = Automat(bank)
  20.         Cola = Item(2)
  21.         automat.add_object(Cola)
  22.         self.assertRaises(NoItemException, automat.find_price_of_given_id(31))
  23.      
  24. if __name__ == '__main__':
  25.     unittest.main()
  26.  
  27.  
  28. from Item import Item
  29. from exceptions.NoItemException import NoItemException
  30. from exceptions.NoProperAmountException import NoProperAmountException
  31. from Coin import Coin
  32. from decimal import *
  33. class Automat:
  34.  
  35.     def __init__(self, _bank, objects=None):
  36.         self.item_id = 30
  37.         self.bank = _bank
  38.         if objects is None:
  39.             objects = {}
  40.  
  41.  
  42.         self.objects = objects
  43.         self.purchaseItemBank = []
  44.  
  45.     def add_object(self, obj: Item):
  46.         id_to_assign = self.item_id
  47.         self.objects.update({id_to_assign: obj})
  48.         self.item_id += 1
  49.         return id_to_assign
  50.  
  51.     def find_price_of_given_id(self, item_id):
  52.         if self.objects.get(item_id) is not None:
  53.             return self.objects.get(item_id).get_price()
  54.         else:
  55.             raise NoItemException
  56.  
  57.     def find_amount_of_given_id(self, item_id):
  58.         if self.objects.get(item_id) is not None:
  59.             return self.objects.get(item_id).get_amount()
  60.         else:
  61.             raise NoItemException
  62.  
  63.     def checkIfAmountIsPositive(self, item_id):
  64.         if self.objects.get(item_id) is not None:
  65.             var = True if self.objects.get(item_id).get_amount() > 0 else False
  66.             return var
  67.         else:
  68.             raise NoItemException
  69.  
  70.     def withdrawItem(self, item_id):
  71.         self.objects.get(item_id).decrease()
  72.  
  73.     def getAmountOfGivenNominal(self, coinValue):
  74.         counter = 0
  75.         for iterator in self.bank.bank:
  76.             if iterator.getCoinValue() == coinValue:
  77.                 counter += 1
  78.         return counter
  79.      
  80. Error
  81. Traceback (most recent call last):
  82.   File "C:ProgramDataAnaconda3libunittestcase.py", line 59, in testPartExecutor
  83.     yield
  84.   File "C:ProgramDataAnaconda3libunittestcase.py", line 615, in run
  85.     testMethod()
  86.   File "C:UsersAdminPycharmProjectsvending-machineAutomatTest.py", line 22, in test_checkPriceOfGivenIDWithInvalidID
  87.     self.assertRaises(NoItemException, automat.find_price_of_given_id(31))
  88.   File "C:UsersAdminPycharmProjectsvending-machineAutomat.py", line 28, in find_price_of_given_id
  89.     raise NoItemException
  90. exceptions.NoItemException.NoItemException
  91.  
  92.  
  93.  
  94. Ran 1 test in 0.003s
  95.  
  96. FAILED (errors=1)
  97.  
  98. Process finished with exit code 1
  99.      
  100. class Item:
  101.     def __init__(self, price, amount=5):
  102.         self.amount = amount
  103.         self.price = price
  104.  
  105.     def get_price(self):
  106.         return self.price
  107.  
  108.     def get_amount(self):
  109.         return self.amount
  110.  
  111.     def decrease(self):
  112.         self.amount -= 1
  113.  
  114.     def __str__(self):
  115.         return f"{self.amount} @ {self.price}"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top