Esempio n. 1
0
    def test_VM_cancelButton(self):
        myVM = VM.VendingSM()

        myVM.inputEvent(VM.COIN_1)
        self.assertEqual(1, myVM.getCredit(), "Amount of credit is wrong")

        myVM.inputEvent(CANCELBUTTON)
        self.assertEqual(0, myVM.getCredit(), "Amount of credit is wrong")
class VendingMachineTestCase(unittest.TestCase):

    def setUp(self):
        self.vendingMachine = VendingMachine(5)

    def tearDown(self):
        pass

    def test_add_items(self):
        name = "Gum"
        price = .75
        quantity = 20
        gum = Item(name, price, quantity)
        
        location = 0
        self.vendingMachine.addItem(gum,location)
        self.assertEqual(gum, self.vendingMachine.checkItem(location)) 

    def test_add_money(self):
        '''Tests how the machine handles adding money'''
        #add one dollar to the empty vending machine and the balance should be one.
        self.vendingMachine.addMoney(1)

        self.assertEqual(self.vendingMachine.pendingBalance, 1)

        #add one more dollar and pending balance should be 2
        self.vendingMachine.addMoney(1)
        
        self.assertEqual(self.vendingMachine.pendingBalance, 2)
Esempio n. 3
0
    def test_VM_reqA1(self):
        myVM = VM.VendingSM()

        myVM.inputEvent(VM.COIN_1)
        self.assertEqual(1, myVM.getCredit(), "Amount of credit is wrong")

        myVM.inputEvent(VM.COIN_2)
        self.assertEqual(3, myVM.getCredit(), "Amount of credit is wrong")

        myVM.inputEvent(VM.COIN_5)
        self.assertEqual(8, myVM.getCredit(), "Amount of credit is wrong")

        myVM.inputEvent(VM.COIN_10)
        self.assertEqual(18, myVM.getCredit(), "Amount of credit is wrong")

        myVM.inputEvent(VM.COIN_20)
        self.assertEqual(38, myVM.getCredit(), "Amount of credit is wrong")
Esempio n. 4
0
 def test_convert_number_to_coins_without_exact_matched_coin_value(self):
     vm = VendingMachine()
     self.assertEqual(vm.find_match_coins(0.35), ['Q', 'D'])
Esempio n. 5
0
 def test_output_product_and_response_without_enough_input_money(self):
     vm = VendingMachine()
     vm._user_input_value = 0.55
     self.assertEqual(
         vm.output_product_and_response('A'),
         ['Don\'t have enough money, please insert $0.10 extra.'])
Esempio n. 6
0
 def test_output_product_and_response_with_changes(self):
     vm = VendingMachine()
     vm._user_input_value = 0.75
     self.assertEqual(vm.output_product_and_response('A'), ['A', 'N', 'N'])
Esempio n. 7
0
# StateMachine/vendingmachine/VendingMachineTest.py
# Demonstrates use of StateMachine.py
import VendingMachine

vm = VendingMachine()
for input in [
        Money.quarter, Money.quarter, Money.dollar, FirstDigit.A,
        SecondDigit.two, FirstDigit.A, SecondDigit.two, FirstDigit.C,
        SecondDigit.three, FirstDigit.D, SecondDigit.one, Quit.quit
]:
    vm.nextState(input)
Esempio n. 8
0
        content = req.text
        data = json.loads(content)
        answer = data['text']
        return answer
        '''
# 注册文本消息,绑定到text_reply处理函数
# text_reply msg_files可以处理好友之间的聊天回复
@itchat.msg_register([TEXT,MAP,CARD,NOTE])
def text_reply(msg):
    # if not msg['Text'] == []:
    itchat.send('%s' % replyMessage(msg['Text']),msg['FromUserName'])
    lastmsg = msg

@itchat.msg_register(itchat.content.SHARING, isMpChat=True)
def reply_msg(msg):
    print("收到一条公众号信息:", msg['User']['NickName'], msg['FileName'])
    message = msg['FileName']
    if msg['User']['NickName'] == '微信支付':
        incomeStart = [i for i in range(len(message)) if message[i] == '款']
        incomeEnd =[i for i in range(len(message)) if message[i] == '元']
        message = message[incomeStart[0] + 1 : incomeEnd[0]]
        vm.insertMoney(float(message))

# @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
# def download_files(msg):
#     msg['Text'](msg['FileName'])
#     return '@%s@%s' % ({'Picture': 'img', 'Video': 'vid'}.get(msg['Type'], 'fil'), msg['FileName'])

if __name__ == '__main__':
    vm = VendingMachine.VendingMachine()
    itchat.run()
Esempio n. 9
0
 def test_enter_different_mode_return_item_C_with_changes(self):
     vm = VendingMachine()
     self.assertEqual(vm.enter_different_mode('Q, Q, DOLLAR, Q, GET-C'),
                      ['C', 'Q'])
Esempio n. 10
0
 def test_krone(self):
     vending_machine = vm.VendingMachine(vm.KRONE_VALUES)
     self.assertEqual(vending_machine.calculate_change(2, 1.25),
                      [20, 20, 20, 10, 5])
Esempio n. 11
0
 def test_enter_different_mode_return_item_A_with_changes(self):
     vm = VendingMachine()
     self.assertEqual(vm.enter_different_mode('Q, Q, Q, Q, GET-A'),
                      ['A', 'Q', 'D'])
Esempio n. 12
0
    def test_VM_reqA3(self):
        myVM = VM.VendingSM()

        myVM.inputEvent(VM.PRODUCTSELECT, VM.COLA)
        self.assertEqual(VM.SALE, myVM.getState(),
                         "VM did not get into correct state")
Esempio n. 13
0
 def test_countCurrency(self):
     assert (VendingMachine.countCurrency(16) == "10:1,5:1,1:1,")
Esempio n. 14
0
 def setUp(self):
     self.vending_machine = VendingMachine()
Esempio n. 15
0
class TestVendingMachine(unittest.TestCase):
    def setUp(self):
        self.vending_machine = VendingMachine()

    # Test sprawdzający cenę towaru
    def test_get_product_price(self):
        self.assertEqual(250, self.vending_machine.get_product_price(32))

    # Test oczekujący brak reszty
    def test_no_change(self):
        self.vending_machine.insert_coin(200)
        self.vending_machine.insert_coin(50)

        result = self.vending_machine.payment(32)
        self.assertEqual('Brak reszty.', result[0])

    # Test oczekujący 10gr reszty po wrzuconej nadwyżce
    def test_get10gr_change(self):
        self.vending_machine.coins[10]['owned'] = 1

        self.vending_machine.insert_coin(200)
        self.vending_machine.insert_coin(20)
        self.vending_machine.insert_coin(20)
        self.vending_machine.insert_coin(20)

        result = self.vending_machine.payment(32)
        self.assertEqual({10: 1}, result[0])

    # Test oczekujący wystąpienie wyjątku ProductUnavailableException gdy produkt jest niedostępny
    def test_out_of_stock(self):
        for i in range(5):
            self.vending_machine.insert_coin(200)
            self.vending_machine.insert_coin(50)
            self.vending_machine.payment(32)

        self.vending_machine.insert_coin(200)
        self.vending_machine.insert_coin(50)

        self.assertRaises(ProductUnavailableException,
                          self.vending_machine.payment, 32)

    # Test oczekujący wystąpienie wyjątku InvalidProductNumberException gdy chcemy pobrać cenę nieistniejącego produktu
    def test_get_non_existing_product_price(self):
        self.assertRaises(InvalidProductNumberException,
                          self.vending_machine.get_product_price, 5)

    # Test sprawdzający zwrot otrzymanych monet
    def test_withdraw_inserted_money(self):
        self.vending_machine.insert_coin(100)
        self.vending_machine.insert_coin(50)
        self.vending_machine.insert_coin(10)
        self.vending_machine.insert_coin(10)
        self.vending_machine.insert_coin(50)
        self.assertEqual({
            10: 2,
            50: 2,
            100: 1
        }, self.vending_machine.withdraw())

    # Test sprawdzający wrzucenie za małej kwoty, wybranie poprawnego numeru towaru,
    # wrzucenie reszty monet do odliczonej kwoty, ponowne wybranie poprawnego numeru towaru - oczekiwany brak reszty.
    def test_pay_missing_part(self):
        self.vending_machine.insert_coin(100)
        self.vending_machine.insert_coin(50)
        self.assertRaises(NotEnoughMoneyException,
                          self.vending_machine.payment, 32)

        self.vending_machine.insert_coin(100)
        result = self.vending_machine.payment(32)
        self.assertEqual('Brak reszty.', result[0])

    # Test płatności odliczoną kwotą w monetach 1gr - oczekiwany brak reszty.
    def test_pay_in_cents(self):
        for i in range(250):
            self.vending_machine.insert_coin(1)
        result = self.vending_machine.payment(32)
        self.assertEqual('Brak reszty.', result[0])
Esempio n. 16
0
 def test_pound(self):
     vending_machine = vm.VendingMachine(vm.POUND_VALUES)
     self.assertEqual(vending_machine.calculate_change(2, 1.25),
                      [50, 20, 5])
Esempio n. 17
0
 def test_find_match_coins_with_matched_coin_value(self):
     vm = VendingMachine()
     self.assertEqual(vm.find_match_coins(0.35), ['Q', 'D'])
Esempio n. 18
0
 def test_parse_user_iput(self):
     vm = VendingMachine()
     self.assertEqual(vm.parse_input_to_list('Q, Q, Q, Q, GET-B'),
                      ['Q', 'Q', 'Q', 'Q', 'GET-B'])
Esempio n. 19
0
 def test_find_the_largest_available_coin_for_D(self):
     vm = VendingMachine()
     self.assertEqual(vm.find_the_largest_available_coin(0.1), 'D')
Esempio n. 20
0
 def test_dollar(self):
     vending_machine = vm.VendingMachine(vm.DOLLAR_VALUES)
     self.assertEqual(vending_machine.calculate_change(2, 1.25),
                      [25, 25, 25])
Esempio n. 21
0
 def test_enter_different_mode_return_item_A_with_not_enough_input_money(
         self):
     vm = VendingMachine()
     self.assertEqual(
         vm.enter_different_mode('Q, Q, GET-A'),
         ['Don\'t have enough money, please insert $0.15 extra.'])
 def setUp(self):
     self.vendingMachine = VendingMachine(5)
Esempio n. 23
0
 def test_enter_different_mode_return_item_B_with_no_changes(self):
     vm = VendingMachine()
     self.assertEqual(vm.enter_different_mode('Q, Q, Q, Q, GET-B'), ['B'])
Esempio n. 24
0
 def test_enter_different_mode_return_invalid_input(self):
     vm = VendingMachine()
     self.assertEqual(vm.enter_different_mode('K'), 'Invalid Input!')
Esempio n. 25
0
 def test_enter_service_mode(self):
     vm = VendingMachine()
     self.assertEqual(vm.enter_different_mode('SERVICE'),
                      'Enter Service Mode...')
Esempio n. 26
0
 def test_enter_different_mode_return_coins(self):
     vm = VendingMachine()
     self.assertEqual(vm.enter_different_mode('Q, N, COIN-RETURN'),
                      ['Q', 'N'])
Esempio n. 27
0
# StateMachine/vendingmachine/VendingMachineTest.py
# Demonstrates use of StateMachine.py
import VendingMachine

vm = VendingMachine()
for input in [
    Money.quarter,
    Money.quarter,
    Money.dollar,
    FirstDigit.A,
    SecondDigit.two,
    FirstDigit.A,
    SecondDigit.two,
    FirstDigit.C,
    SecondDigit.three,
    FirstDigit.D,
    SecondDigit.one,
    Quit.quit]:
    vm.nextState(input)
Esempio n. 28
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from VendingMachine import *


if __name__ == '__main__':
    try:
        coffeeMachine = VendingMachine(sys.argv[1])
        coffeeMachine.saveToFile()
    except IndexError:
        print("Se requiere un argumento de linea de comando")