From 559387cc3c179943d9b064b59c0ba10164bcef55 Mon Sep 17 00:00:00 2001 From: totycro Date: Mon, 23 May 2011 00:53:33 +0200 Subject: Fixed access to privates Added preconditions --- bank-eiffel/account.e | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index 78a293f..39e4167 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -58,6 +58,13 @@ feature {NONE} -- Initialization an_interest_deposit_range: ARRAY[REAL_64]; an_interest_debit_range: ARRAY[REAL_64]; a_credit_line_range: ARRAY[REAL_64]) + require + a_credit_line_range.count() = 2 + an_interest_debit_range.count() = 2 + an_interest_deposit_range.count() = 2 + a_credit_line_range.item (0) < a_credit_line_range.item (1) + an_interest_debit_range.item (0) < an_interest_debit_range.item (1) + an_interest_deposit_range.item (0) < an_interest_deposit_range.item (1) do create authorized_signers.make(1) add_authorized_signer (an_authorized_signer) @@ -75,9 +82,9 @@ feature -- Basic operations deposit (an_amount: like transfer_minamount; an_authorized_signer: PERSON) require - an_authorized_signer_authorized: authorized_signers.has (an_authorized_signer) + an_authorized_signer_authorized: has_authorized_signer (an_authorized_signer) an_amount_positive: an_amount > 0.0 - transfer_minamount_ok: an_amount >= transfer_minamount + transfer_minamount_ok: an_amount >= get_transfer_minamount do balance := balance + an_amount ensure @@ -87,9 +94,9 @@ feature -- Basic operations withdraw (an_amount: like transfer_minamount; an_authorized_signer: PERSON) require - an_authorized_signer_authorized: authorized_signers.has (an_authorized_signer) + an_authorized_signer_authorized: has_authorized_signer (an_authorized_signer) an_amount_positive: an_amount > 0.0 - transfer_minamount_ok: an_amount >= transfer_minamount + transfer_minamount_ok: an_amount >= get_transfer_minamount do balance := balance - an_amount ensure @@ -109,7 +116,7 @@ feature -- Basic operations add_authorized_signer (an_authorized_signer: PERSON) require an_authorized_signer_attached: an_authorized_signer /= Void - an_authorized_signer_notinlist: not authorized_signers.has (an_authorized_signer) + an_authorized_signer_notinlist: not has_authorized_signer (an_authorized_signer) do authorized_signers.put (an_authorized_signer) ensure @@ -119,14 +126,31 @@ feature -- Basic operations remove_authorized_signer (an_authorized_signer: PERSON) require 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 + an_authorized_signer_inlist: has_authorized_signer (an_authorized_signer) + authorized_signers_never_empty: authorized_signers_count >= 2 do authorized_signers.prune (an_authorized_signer) ensure authorized_signers_assigned: not authorized_signers.has (an_authorized_signer) end + has_authorized_signer (an_authorized_signer: PERSON) : BOOLEAN + do + Result := authorized_signers.has (an_authorized_signer) + end + + + authorized_signers_count : INTEGER + do + Result := authorized_signers.count + end + + get_transfer_minamount : REAL_64 + do + Result := transfer_minamount + end + + feature {NONE} -- Implementation set_transfer_minamount (a_transfer_minamount: like transfer_minamount) @@ -172,7 +196,6 @@ invariant interest_deposit_within_bounds: interest_deposit >= interest_deposit_range.item (0) and interest_deposit <= interest_deposit_range.item (1) - 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 -- cgit v1.2.3