From a47510de141d3a9ec11aebfb2de1c6002c595774 Mon Sep 17 00:00:00 2001 From: manuel Date: Sun, 22 May 2011 14:04:00 +0200 Subject: more account stuff --- bank-eiffel/account.e | 79 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index 8faabdc..7555baa 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -7,28 +7,71 @@ note class ACCOUNT +create + make + +-- TODO +-- interest should defined by bank (via make?) +-- add more checks to invariant (like balance >= creditline) ? +-- check if balance is a getter and not a setter (doesn't has an assign) +-- + check if authorized_signers is a getter and not a setter (it doesn't has an assign) +-- -> if not: add a getter (via Result or so..) and move them to {NONE} +-- much other stuff to test like: lower creditline so that balance will be invalid feature -- Access - transfer_minamount: REAL_32 assign set_transfer_minamount + transfer_minamount: REAL_64 assign set_transfer_minamount -- Mindestbetrag für jede Einzahlung, Auszahlung und Überweisung - authorized_signers: SET [PERSON] assign set_authorized_signers + authorized_signers: SET [PERSON] -- Zeichnungsberechtigte attribute Result := ({like authorized_signers}).default end --| Remove line when Void Safety is properly set - balance: REAL_64 - -- Kontostand - creditline: REAL_64 assign set_creditline -- Kreditrahmen - interest_deposit: REAL_32 assign set_interest_deposit + interest_deposit: REAL_64 assign set_interest_deposit -- Habenverzinsung - interest_debit: REAL_32 assign set_interest_debit + interest_debit: REAL_64 assign set_interest_debit -- Sollverzinsung + balance: REAL_64 + -- Kontostand + +feature -- Initialization + + make (an_authorized_signer: PERSON) + do + add_authorized_signers (an_authorized_signer) + balance := 0 + end + +feature -- Basic operations + + deposit (an_amount: like transfer_minamount) + require + an_amount_positive: an_amount > 0.0 + transfer_minamount_ok: an_amount >= transfer_minamount + do + balance := balance + an_amount + ensure + balance_increased: balance > old balance + deposited: balance = old balance + an_amount + end + + withdraw (an_amount: like transfer_minamount) + require + an_amount_positive: an_amount > 0.0 + transfer_minamount_ok: an_amount >= transfer_minamount + do + balance := balance - an_amount + ensure + balance_increased: balance < old balance + withdrawed: balance = old balance - an_amount + creditline_ok: balance >= creditline + end + feature -- Element change set_transfer_minamount (a_transfer_minamount: like transfer_minamount) @@ -41,14 +84,25 @@ feature -- Element change transfer_minamount_assigned: transfer_minamount = a_transfer_minamount end - set_authorized_signers (an_authorized_signers: like authorized_signers) - -- Assign `authorized_signers' with `an_authorized_signers'. + add_authorized_signers (an_authorized_signer: PERSON) + require + an_authorized_signer_attached: an_authorized_signer /= Void + an_authorized_signer_notinlist: not authorized_signers.has (an_authorized_signer) + do + authorized_signers.put (an_authorized_signer) + ensure + authorized_signers_assigned: authorized_signers.has (an_authorized_signer) + end + + remove_authorized_signers (an_authorized_signer: PERSON) require - an_authorized_signers_attached: an_authorized_signers /= Void + an_authorized_signer_attached: an_authorized_signer /= Void + an_authorized_signer_inlist: authorized_signers.has (an_authorized_signer) + authorized_signers_never_empty: authorized_signers.count >= 2 do - authorized_signers := an_authorized_signers + authorized_signers.prune (an_authorized_signer) ensure - authorized_signers_assigned: authorized_signers = an_authorized_signers + authorized_signers_assigned: not authorized_signers.has (an_authorized_signer) end set_creditline (a_creditline: like creditline) @@ -83,5 +137,6 @@ invariant interest_debit_within_bounds: interest_debit >= 0.0 and interest_debit <= 1.0 interest_deposit_within_bounds: interest_deposit >= 0.0 and interest_deposit <= 1.0 authorized_signers_attached: authorized_signers /= Void + authorized_signers_not_empty: authorized_signers.count > 0 transfer_minamount_positive: transfer_minamount > 0.0 end -- cgit v1.2.3