def createProductList(): productList = [] productList.append(createProduct('flour_1kg', 5, 10)) productList.append(createProduct('sugar_1kg', 7, 100)) productList.append(createProduct('bread', 1, 50)) productList.append(createProduct('butter_200g', 2, 25)) productList.append(createProduct('milk_1l', 2, 140)) return productList
def UI_addProductToList(productList, name, price, quantity): try: price = validateStrictlyPositiveInteger(price) quantity = validateStrictlyPositiveInteger(quantity) addProductToList(productList, createProduct(name, price, quantity)) except ValueError: print('Price / Quantity must be strictly positive integers.')
def test_createProduct (): product = createProduct('flour', 5, 10) assert product[0] == 'flour' assert product[1] == 5 assert product[2] == 10
def test_stringProductList(): productList = [] assert stringProductList(productList) == 'Product list is void.' addProductToList(productList, createProduct('flour', 5, 10)) assert stringProductList(productList) == 'Product list:\nflour: 5$, 10 items'
def test_addProductToList (): productList = [] addProductToList(productList, createProduct('flour', 5, 10)) assert len(productList) == 1 and productList[0][0] == 'flour'