Spaces:
Running
on
Zero
Running
on
Zero
File size: 6,477 Bytes
a746d34 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
2024-06-10T16:03:31.970093 ================================ System Message ================================ You will get instructions for code to write. You will write a very long answer. Make sure that every detail of the architecture is, in the end, implemented as code. Think step by step and reason yourself to the correct decisions to make sure we get it right. First lay out the names of the core classes, functions, methods that will be necessary, As well as a quick comment on their purpose. You will output the content of each file necessary to achieve the goal, including ALL code. Represent files like so: FILENAME ``` CODE ``` The following tokens must be replaced like so: FILENAME is the lowercase combined path and file name including the file extension CODE is the code in the file Example representation of a file: src/hello_world.py ``` print("Hello World") ``` Do not comment on what every file does. Please note that the code should be fully functional. No placeholders. You will start with the "entrypoint" file, then go to the ones that are imported by that file, and so on. Please note that the code should be fully functional. No placeholders. Follow a language and framework appropriate best practice file naming convention. Make sure that files contain all imports, types etc. The code should be fully functional. Make sure that code in different files are compatible with each other. Ensure to implement all code, if you are unsure, write a plausible implementation. Include module dependency or package manager dependency definition file. Before you finish, double check that all parts of the architecture is present in the files. When you are done, write finish with "this concludes a fully working implementation". Useful to know: Almost always put different classes in different files. Always use the programming language the user asks for. For Python, you always create an appropriate requirements.txt file. For NodeJS, you always create an appropriate package.json file. Always add a comment briefly describing the purpose of the function definition. Add comments explaining very complex bits of logic. Always follow the best practices for the requested languages for folder/file structure and how to package the project. Python toolbelt preferences: - pytest - dataclasses ================================ Human Message ================================= Request: n ================================== Ai Message ================================== I'll assume you want me to create a Python project. Since you didn't specify a particular task or problem to solve, I'll create a simple project that demonstrates a basic architecture. Let's create a project that simulates a simple banking system. We'll have classes for `Account`, `Customer`, and `Bank`. The `Bank` class will manage a list of customers, and each customer will have one or more accounts. Here's the project structure: ``` banking_system requirements.txt src __init__.py account.py bank.py customer.py main.py tests __init__.py test_account.py test_bank.py test_customer.py ``` Here's the code for each file: **requirements.txt** ``` pytest dataclasses ``` **src/__init__.py** ``` # empty file ``` **src/account.py** ``` from dataclasses import dataclass @dataclass class Account: """Represents a bank account.""" account_number: int balance: float = 0.0 def deposit(self, amount: float) -> None: """Deposit money into the account.""" self.balance += amount def withdraw(self, amount: float) -> None: """Withdraw money from the account.""" if amount > self.balance: raise ValueError("Insufficient balance") self.balance -= amount ``` **src/bank.py** ``` from typing import List from .account import Account from .customer import Customer class Bank: """Represents a bank.""" def __init__(self): self.customers: List[Customer] = [] def add_customer(self, customer: Customer) -> None: """Add a customer to the bank.""" self.customers.append(customer) def get_customer(self, customer_id: int) -> Customer: """Get a customer by ID.""" for customer in self.customers: if customer.customer_id == customer_id: return customer return None ``` **src/customer.py** ``` from dataclasses import dataclass from .account import Account @dataclass class Customer: """Represents a bank customer.""" customer_id: int name: str accounts: List[Account] = None def __post_init__(self): self.accounts = [] def add_account(self, account: Account) -> None: """Add an account to the customer.""" self.accounts.append(account) ``` **src/main.py** ``` from .bank import Bank from .customer import Customer from .account import Account def main(): bank = Bank() customer1 = Customer(customer_id=1, name="John Doe") customer1.add_account(Account(account_number=1234)) customer1.add_account(Account(account_number=5678)) bank.add_customer(customer1) print(bank.get_customer(1).accounts) if __name__ == "__main__": main() ``` **tests/__init__.py** ``` # empty file ``` **tests/test_account.py** ``` from unittest import TestCase from src.account import Account class TestAccount(TestCase): def test_deposit(self): account = Account(account_number=1234) account.deposit(100.0) self.assertEqual(account.balance, 100.0) def test_withdraw(self): account = Account(account_number=1234) account.deposit(100.0) account.withdraw(50.0) self.assertEqual(account.balance, 50.0) ``` **tests/test_bank.py** ``` from unittest import TestCase from src.bank import Bank from src.customer import Customer class TestBank(TestCase): def test_add_customer(self): bank = Bank() customer = Customer(customer_id=1, name="John Doe") bank.add_customer(customer) self.assertIn(customer, bank.customers) ``` **tests/test_customer.py** ``` from unittest import TestCase from src.customer import Customer from src.account import Account class TestCustomer(TestCase): def test_add_account(self): customer = Customer(customer_id=1, name="John Doe") account = Account(account_number=1234) customer.add_account(account) self.assertIn(account, customer.accounts) ``` This concludes a fully working implementation. |