コード例 #1
0
from budget import Category
from budget import get_percentage, get_percentage_string, get_deposit_sum, get_withdraw_sum, get_new_balance, compose_string_list, make_string, create_spend_chart, print_spend_chart
import pprint
food = Category('Food')
food.deposit(1000.00, 'initial deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'resturant and more food')
food.withdraw(50.00, 'Clothing')
food.withdraw(300.00, 'big grocery shopping')
food.withdraw(150.00, 'night out with friends')

Clothes = Category('Clothing')
Clothes.deposit(2000.00, 'initital deposit')
Clothes.withdraw(800.00, 'bought clothes for work')
Clothes.withdraw(200.00, 'work uniform')
Clothes.withdraw(150.00, 'bought new sneakers')

Auto = Category('Auto')
Auto.deposit(10000.00, 'initial deposit')
Auto.withdraw(5000.00, 'repair after accident')
Auto.withdraw(500.00, 'new bumper plates')
Auto.withdraw(300.00, 'new tires')
#new_balance = get_deposit_sum(food)
#old_balance = new_balance - get_withdraw_sum(food)

#print(food)
category_list = [food, Clothes, Auto]

for item in category_list:
    print_spend_chart(create_spend_chart(item))
    print('')
コード例 #2
0
ファイル: main.py プロジェクト: alivemary/budget-app
# This entrypoint file to be used in development. Start by reading README.md
from unittest import main
from budget import Category, create_spend_chart

food = Category("Food")
food.deposit(1000, "initial deposit")
food.withdraw(10.15, "groceries")
food.withdraw(15.89, "restaurant and more food for dessert")
print(food.get_balance())
clothing = Category("Clothing")
food.transfer(50, clothing)
clothing.withdraw(25.55)
clothing.withdraw(100)
auto = Category("Auto")
auto.deposit(1000, "initial deposit")
auto.withdraw(15)

print(food)
print(clothing)

print(create_spend_chart([food, clothing, auto]))

# Run unit tests automatically
main(module="test_module", exit=False)
コード例 #3
0
ファイル: test_budget.py プロジェクト: rupayanr/python
 def setUp(self):
     self.food = Category("Food")
     self.laundry = Category("Laundry")
コード例 #4
0
ファイル: test_budget.py プロジェクト: rupayanr/python
class TestBudget(unittest.TestCase):
    def setUp(self):
        self.food = Category("Food")
        self.laundry = Category("Laundry")

    def tearDown(self):
        pass

    def test_deposit(self):
        self.food.deposit(1000, "Initial Deposit")
        actual = self.food.ledger[0]
        expected = {"amount": 1000, "description": "Initial Deposit"}
        self.assertEqual(
            actual, expected,
            "Expected deposit method to create a specific object in ledger")

    def test_deposit_no_description(self):
        self.laundry.deposit(1000)
        actual = self.laundry.ledger[0]
        expected = {"amount": 1000, "description": ""}
        self.assertEqual(
            actual, expected,
            'Expected deposit method to create a specific object in ledger')

    def test_withdraw(self):
        self.food.deposit(2000, "Initial Deposit")
        good_withdraw = self.food.withdraw(1000, "BBQ Nation")
        actual = self.food.ledger[1]
        expected = {"amount": -1000, "description": "BBQ Nation"}
        self.assertTrue(good_withdraw, 'Expected method to return true')
        self.assertEqual(
            actual, expected,
            "Expected withdraw method to create a specific object in ledger")

    def test_withdraw_no_description(self):
        self.laundry.deposit(2000, "Initial deposit")
        good_withdraw = self.laundry.withdraw(1000)
        actual = self.laundry.ledger[1]
        expected = {"amount": -1000, "description": ""}
        self.assertTrue(good_withdraw, 'Expected method to return true')
        self.assertEqual(
            actual, expected,
            'Expected withdraw method to create a specific object in ledger')

    def test_transfer(self):
        self.food.deposit(1000, "deposit")
        self.laundry.deposit(1000, "Initial deposit")
        good_transfer = self.laundry.transfer(500, self.food)
        actual = self.food.ledger[1]
        expected = {
            "amount": 500,
            "description": "Transfered from " + self.laundry.category
        }
        self.assertEqual(
            actual, expected,
            'Expected trasnfer method to create a specific object in ledger')
        self.assertTrue(good_transfer, 'Expected method to return true')
コード例 #5
0
ファイル: main.py プロジェクト: rupayanr/python
import budget
from budget import create_spend_chart
from budget import Category

food = Category("Food")
food.deposit(4000, "deposit")
food.withdraw(2000, "bbq nation")

petrol = Category("Petrol")
petrol.deposit(10000, "deposit")
petrol.withdraw(5000, "petrol")

print(food)
print(petrol)

create_spend_chart([food, petrol])
コード例 #6
0
from budget import Category, create_spend_chart
from unittest import main

food = Category('Food')
food.deposit(1000, 'initial deposit')
food.withdraw(10.15, 'groceries')
print(food.get_balance())

clothing = Category('Clothing')
food.transfer(50, clothing)
clothing.withdraw(25.55)
clothing.withdraw(100)

auto = Category('Auto')
auto.deposit(1000, 'initial deposit')
auto.withdraw(15)

print(food)
print('')
print(clothing)
print('')
print(create_spend_chart([food, clothing, auto]))

# main(module='test_module',exit=False)