Es 05 Bank

This commit is contained in:
2024-04-30 19:10:57 +02:00
parent 01c9a72de0
commit 5b79d90923
3 changed files with 183 additions and 0 deletions

37
tests/es05_bank.rs Normal file
View File

@@ -0,0 +1,37 @@
use esercizi::es05_bank::BankAccount;
#[test]
fn test_bank() {
let name = "Nome".to_string();
let mut account = BankAccount::new(name.clone(), 1000.0, 10000.0, 0.02);
assert_eq!(account.balance(), 0.0);
assert_eq!(account.state(), "Red");
account.deposit(1001.0);
assert_eq!(account.balance(), 1001.0);
assert_eq!(account.state(), "Silver");
account.pay_interest();
assert_eq!(account.balance(), 1001.0);
assert_eq!(account.state(), "Silver");
account.withdraw(100.0);
assert_eq!(account.balance(), 901.0);
assert_eq!(account.state(), "Red");
account.withdraw(1.0);
assert_eq!(account.balance(), 901.0);
assert_eq!(account.state(), "Red");
account.deposit(100000.0);
assert_eq!(account.balance(), 100901.0);
assert_eq!(account.state(), "Gold");
account.pay_interest();
assert_eq!(account.balance(), 98882.98);
assert_eq!(account.state(), "Gold");
account.withdraw(90882.98);
assert_eq!(account.balance(), 8000.0);
assert_eq!(account.state(), "Silver");
}