From be3258068761a7c9eba329d205195f4cb3dd1eef Mon Sep 17 00:00:00 2001 From: totycro Date: Sun, 22 May 2011 22:13:33 +0200 Subject: Added preset ranges for values to accout --- bank-eiffel/account.e | 34 ++++++++++++++++++++++++++++++---- bank-eiffel/tests/test_account.e | 16 +++++++++++++++- 2 files changed, 45 insertions(+), 5 deletions(-) (limited to 'bank-eiffel') diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index 3ef7a8b..0a7d202 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -20,6 +20,16 @@ create feature -- Access + creditline_range: ARRAY[REAL_64] + attribute Result := ({like creditline_range}).default end --| Remove line when Void Safety is properly set + + interest_debit_range: ARRAY[REAL_64] + attribute Result := ({like interest_debit_range}).default end --| Remove line when Void Safety is properly set + + interest_deposit_range: ARRAY[REAL_64] + -- min/max for interest_deposit + attribute Result := ({like interest_deposit_range}).default end --| Remove line when Void Safety is properly set + transfer_minamount: REAL_64 assign set_transfer_minamount -- Mindestbetrag für jede Einzahlung, Auszahlung und Überweisung @@ -41,12 +51,24 @@ feature -- Access feature {NONE} -- Initialization - make (an_authorized_signer: PERSON) + make (an_authorized_signer: PERSON; + an_interest_deposit: REAL_64; + an_interest_debit: REAL_64; + a_credit_line: REAL_64; + an_interest_deposit_range: ARRAY[REAL_64]; + an_interest_debit_range: ARRAY[REAL_64]; + a_credit_line_range: ARRAY[REAL_64]) do create authorized_signers.make(1) add_authorized_signer (an_authorized_signer) transfer_minamount := 2 balance := 0 + creditline := a_credit_line + interest_debit := an_interest_debit + interest_deposit := an_interest_deposit + interest_deposit_range := an_interest_deposit_range + interest_debit_range := an_interest_debit_range + creditline_range := a_credit_line_range end feature -- Basic operations @@ -137,8 +159,6 @@ feature {NONE} -- Implementation set_interest_debit (an_interest_debit: like interest_debit) -- Assign `interest_debit' with `an_interest_debit'. - require - an_interest_debit_within_bounds: an_interest_debit >= 0.0 and an_interest_debit <= 1.0 do interest_debit := an_interest_debit ensure @@ -146,9 +166,15 @@ feature {NONE} -- Implementation end invariant - interest_debit_within_bounds: interest_debit >= 0.0 and interest_debit <= 1.0 + interest_debit_within_bounds: + interest_debit >= interest_debit_range.item (0) and + interest_debit <= interest_debit_range.item (1) + 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 + creditline_range_correct: creditline >= creditline_range.item (0) and creditline <= creditline_range.item (1) end diff --git a/bank-eiffel/tests/test_account.e b/bank-eiffel/tests/test_account.e index a460023..3086402 100644 --- a/bank-eiffel/tests/test_account.e +++ b/bank-eiffel/tests/test_account.e @@ -20,10 +20,24 @@ feature -- Test routines person1: PERSON person2: PERSON account: ACCOUNT + cre: ARRAY[REAL_64] + deb_rng: ARRAY[REAL_64] + dep_rng: ARRAY[REAL_64] do create person1.make ("SOME_SURNAME_1", "SOME_FIRSTNAME_1") create person2.make ("SOME_SURNAME_2", "SOME_FIRSTNAME_2") - create account.make (person1) + + create cre.make_filled (0.0, 0, 1) + cre.put (-100.0, 0) + cre.put (-50.0, 1) + create deb_rng.make(0,1) + deb_rng.put (0.1, 0) + deb_rng.put (2.2, 1) + create dep_rng.make(0,1) + dep_rng.put (0.1, 0) + dep_rng.put (2.2, 1) + + create account.make (person1, 1.0, 2.0, -50.0, deb_rng, dep_rng, cre) account.add_authorized_signer (person2) --assert ("not_implemented", False) end -- cgit v1.2.3 From 3d70ca15591e4f4db578ba44fda674e6e44a7e56 Mon Sep 17 00:00:00 2001 From: totycro Date: Sun, 22 May 2011 23:12:59 +0200 Subject: members should be private --- bank-eiffel/account.e | 2 +- bank-eiffel/tests/test_account.e | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'bank-eiffel') diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index 0a7d202..78a293f 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -18,7 +18,7 @@ create -- -> 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 +feature {NONE} -- Access creditline_range: ARRAY[REAL_64] attribute Result := ({like creditline_range}).default end --| Remove line when Void Safety is properly set diff --git a/bank-eiffel/tests/test_account.e b/bank-eiffel/tests/test_account.e index 3086402..6e65f52 100644 --- a/bank-eiffel/tests/test_account.e +++ b/bank-eiffel/tests/test_account.e @@ -39,6 +39,8 @@ feature -- Test routines create account.make (person1, 1.0, 2.0, -50.0, deb_rng, dep_rng, cre) account.add_authorized_signer (person2) + + --assert ("not_implemented", False) end -- cgit v1.2.3 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(-) (limited to 'bank-eiffel') 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 From 3d0cdbe62989a59975938d4a0ab734d3e7f41be8 Mon Sep 17 00:00:00 2001 From: totycro Date: Mon, 23 May 2011 01:21:19 +0200 Subject: added advance --- bank-eiffel/account.e | 34 +++++++++++++++++++++++----------- bank-eiffel/tests/test_account.e | 31 ++++++++++++++++--------------- 2 files changed, 39 insertions(+), 26 deletions(-) (limited to 'bank-eiffel') diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index 39e4167..61145f0 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -62,14 +62,14 @@ feature {NONE} -- Initialization 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) + a_credit_line_range.item (1) < a_credit_line_range.item (2) + an_interest_debit_range.item (1) < an_interest_debit_range.item (2) + an_interest_deposit_range.item (1) < an_interest_deposit_range.item (2) do create authorized_signers.make(1) add_authorized_signer (an_authorized_signer) - transfer_minamount := 2 - balance := 0 + transfer_minamount := 2.0 + balance := 0.0 creditline := a_credit_line interest_debit := an_interest_debit interest_deposit := an_interest_deposit @@ -139,7 +139,6 @@ feature -- Basic operations Result := authorized_signers.has (an_authorized_signer) end - authorized_signers_count : INTEGER do Result := authorized_signers.count @@ -150,6 +149,19 @@ feature -- Basic operations Result := transfer_minamount end + get_balance : REAL_64 + do + Result := balance + end + + advance + do + if balance < 0.0 then -- debit + balance := balance + (balance * interest_debit) + else -- deposit + balance := balance + (balance * interest_deposit) + end + end feature {NONE} -- Implementation @@ -191,13 +203,13 @@ feature {NONE} -- Implementation invariant interest_debit_within_bounds: - interest_debit >= interest_debit_range.item (0) and - interest_debit <= interest_debit_range.item (1) + interest_debit >= interest_debit_range.item (1) and + interest_debit <= interest_debit_range.item (2) interest_deposit_within_bounds: - interest_deposit >= interest_deposit_range.item (0) and - interest_deposit <= interest_deposit_range.item (1) + interest_deposit >= interest_deposit_range.item (1) and + interest_deposit <= interest_deposit_range.item (2) authorized_signers_attached: authorized_signers /= Void authorized_signers_not_empty: authorized_signers.count > 0 transfer_minamount_positive: transfer_minamount > 0.0 - creditline_range_correct: creditline >= creditline_range.item (0) and creditline <= creditline_range.item (1) + creditline_range_correct: creditline >= creditline_range.item (1) and creditline <= creditline_range.item (2) end diff --git a/bank-eiffel/tests/test_account.e b/bank-eiffel/tests/test_account.e index 6e65f52..e0dfe4d 100644 --- a/bank-eiffel/tests/test_account.e +++ b/bank-eiffel/tests/test_account.e @@ -20,30 +20,31 @@ feature -- Test routines person1: PERSON person2: PERSON account: ACCOUNT - cre: ARRAY[REAL_64] - deb_rng: ARRAY[REAL_64] - dep_rng: ARRAY[REAL_64] do create person1.make ("SOME_SURNAME_1", "SOME_FIRSTNAME_1") create person2.make ("SOME_SURNAME_2", "SOME_FIRSTNAME_2") - create cre.make_filled (0.0, 0, 1) - cre.put (-100.0, 0) - cre.put (-50.0, 1) - create deb_rng.make(0,1) - deb_rng.put (0.1, 0) - deb_rng.put (2.2, 1) - create dep_rng.make(0,1) - dep_rng.put (0.1, 0) - dep_rng.put (2.2, 1) - - create account.make (person1, 1.0, 2.0, -50.0, deb_rng, dep_rng, cre) + create account.make (person1, 0.01, 0.02, -50.0, <<0.01, 0.022>>, <<0.01, 0.02>>, <<-100, -50>>) account.add_authorized_signer (person2) --assert ("not_implemented", False) end -end + ADVANCE + local + person1: PERSON + account: ACCOUNT + b : REAL_64 + do + create person1.make ("SOME_SURNAME_1", "SOME_FIRSTNAME_1") + create account.make (person1, 0.01, 0.02, -50.0, <<0.01, 0.022>>, <<0.01, 0.02>>, <<-100, -50>>) + + account.deposit (100.0, person1) + account.advance + + assert("balance not correct", account.get_balance = 101.0) + end +end -- cgit v1.2.3 From e03195a9325d2671208efc45f4a4d083664eafe2 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 23 May 2011 19:28:45 +0200 Subject: make all void-safe and much more improvements --- bank-eiffel/account.e | 151 ++++++++++++++++----------------------- bank-eiffel/bank.e | 21 ++++++ bank-eiffel/bank.ecf | 2 +- bank-eiffel/person.e | 10 ++- bank-eiffel/retiree.e | 3 + bank-eiffel/retireeaccount.e | 10 +++ bank-eiffel/student.e | 3 + bank-eiffel/studentaccount.e | 10 +++ bank-eiffel/tests/test_account.e | 65 +++++++++++++---- bank-eiffel/tests/test_person.e | 22 ------ 10 files changed, 164 insertions(+), 133 deletions(-) (limited to 'bank-eiffel') diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index 61145f0..d0a3fc4 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -10,32 +10,10 @@ class 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 -feature {NONE} -- Access - - creditline_range: ARRAY[REAL_64] - attribute Result := ({like creditline_range}).default end --| Remove line when Void Safety is properly set - - interest_debit_range: ARRAY[REAL_64] - attribute Result := ({like interest_debit_range}).default end --| Remove line when Void Safety is properly set - - interest_deposit_range: ARRAY[REAL_64] - -- min/max for interest_deposit - attribute Result := ({like interest_deposit_range}).default end --| Remove line when Void Safety is properly set - - transfer_minamount: REAL_64 assign set_transfer_minamount - -- Mindestbetrag für jede Einzahlung, Auszahlung und Überweisung - - authorized_signers: ARRAYED_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 @@ -46,25 +24,36 @@ feature {NONE} -- Access interest_debit: REAL_64 assign set_interest_debit -- Sollverzinsung - balance: REAL_64 - -- Kontostand + transfer_minamount: REAL_64 assign set_transfer_minamount + -- Mindestbetrag fuer jede Einzahlung, Auszahlung und Ueberweisung + +feature {NONE} -- Implementation + + creditline_range: TUPLE [min: like creditline; max: like creditline] + -- min/max for creditline + + interest_deposit_range: TUPLE [min: like interest_deposit; max: like interest_deposit] + -- min/max for interest_deposit + + interest_debit_range: TUPLE [min: like interest_debit; max: like interest_debit] + -- min/max for interest_debit + + authorized_signers: ARRAYED_SET [PERSON] + -- Zeichnungsberechtigte feature {NONE} -- Initialization make (an_authorized_signer: PERSON; - an_interest_deposit: REAL_64; - an_interest_debit: REAL_64; - a_credit_line: REAL_64; - an_interest_deposit_range: ARRAY[REAL_64]; - an_interest_debit_range: ARRAY[REAL_64]; - a_credit_line_range: ARRAY[REAL_64]) + an_interest_deposit: like interest_deposit; + an_interest_debit: like interest_debit; + a_credit_line: like creditline; + an_interest_deposit_range: like interest_deposit_range; + an_interest_debit_range: like interest_debit_range; + a_credit_line_range: like creditline_range) require - a_credit_line_range.count() = 2 - an_interest_debit_range.count() = 2 - an_interest_deposit_range.count() = 2 - a_credit_line_range.item (1) < a_credit_line_range.item (2) - an_interest_debit_range.item (1) < an_interest_debit_range.item (2) - an_interest_deposit_range.item (1) < an_interest_deposit_range.item (2) + a_credit_line_range.min < a_credit_line_range.max + an_interest_debit_range.min < an_interest_debit_range.max + an_interest_deposit_range.min < an_interest_deposit_range.max do create authorized_signers.make(1) add_authorized_signer (an_authorized_signer) @@ -82,9 +71,8 @@ feature -- Basic operations deposit (an_amount: like transfer_minamount; an_authorized_signer: PERSON) require - an_authorized_signer_authorized: has_authorized_signer (an_authorized_signer) - an_amount_positive: an_amount > 0.0 - transfer_minamount_ok: an_amount >= get_transfer_minamount + an_authorized_signer_authorized: get_authorized_signers.has (an_authorized_signer) + transfer_minamount_ok: an_amount >= transfer_minamount do balance := balance + an_amount ensure @@ -94,71 +82,55 @@ feature -- Basic operations withdraw (an_amount: like transfer_minamount; an_authorized_signer: PERSON) require - an_authorized_signer_authorized: has_authorized_signer (an_authorized_signer) - an_amount_positive: an_amount > 0.0 - transfer_minamount_ok: an_amount >= get_transfer_minamount + an_authorized_signer_authorized: get_authorized_signers.has (an_authorized_signer) + transfer_minamount_ok: an_amount >= transfer_minamount do balance := balance - an_amount ensure balance_decreased: balance < old balance withdrawed: balance = old balance - an_amount - creditline_ok: balance >= creditline + balance_beneath_creditline: balance >= creditline end - transfer(an_amount: like transfer_minamount; an_authorized_signer: PERSON; an_account: like Current; another_authorized_signer: PERSON;) - require - an_account_attached: an_account /= Void + transfer(an_amount: like transfer_minamount; an_authorized_signer: PERSON; + an_account: like Current; another_authorized_signer: PERSON) do withdraw (an_amount, an_authorized_signer) an_account.deposit (an_amount, another_authorized_signer) end add_authorized_signer (an_authorized_signer: PERSON) - require - an_authorized_signer_attached: an_authorized_signer /= Void - an_authorized_signer_notinlist: not has_authorized_signer (an_authorized_signer) do - authorized_signers.put (an_authorized_signer) + if not authorized_signers.has (an_authorized_signer) then + authorized_signers.put (an_authorized_signer) + end ensure authorized_signers_assigned: authorized_signers.has (an_authorized_signer) end remove_authorized_signer (an_authorized_signer: PERSON) require - an_authorized_signer_attached: an_authorized_signer /= Void - an_authorized_signer_inlist: has_authorized_signer (an_authorized_signer) - authorized_signers_never_empty: authorized_signers_count >= 2 + authorized_signers_never_empty: get_authorized_signers.count >= 2 do - authorized_signers.prune (an_authorized_signer) + if authorized_signers.has (an_authorized_signer) then + authorized_signers.prune (an_authorized_signer) + end ensure authorized_signers_assigned: not authorized_signers.has (an_authorized_signer) end - has_authorized_signer (an_authorized_signer: PERSON) : BOOLEAN + get_authorized_signers: FINITE [PERSON] 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 - - get_balance : REAL_64 - do - Result := balance + Result := authorized_signers end advance do - if balance < 0.0 then -- debit + if balance < 0.0 then + -- debit balance := balance + (balance * interest_debit) - else -- deposit + else + -- deposit balance := balance + (balance * interest_deposit) end end @@ -166,7 +138,6 @@ feature -- Basic operations feature {NONE} -- Implementation set_transfer_minamount (a_transfer_minamount: like transfer_minamount) - -- Assign `transfer_minamount' with `a_transfer_minamount'. require a_transfer_minamount_positive: a_transfer_minamount > 0.0 do @@ -176,7 +147,9 @@ feature {NONE} -- Implementation end set_creditline (a_creditline: like creditline) - -- Assign `creditline' with `a_creditline'. + require + a_creditline_within_bounds: a_creditline >= creditline_range.min + and a_creditline <= creditline_range.max do creditline := a_creditline ensure @@ -184,9 +157,9 @@ feature {NONE} -- Implementation end set_interest_deposit (an_interest_deposit: like interest_deposit) - -- Assign `interest_deposit' with `an_interest_deposit'. require - an_interest_deposit_within_bounds: an_interest_deposit >= 0.0 and an_interest_deposit <= 1.0 + an_interest_deposit_within_bounds: interest_deposit >= interest_deposit_range.min + and interest_deposit <= interest_deposit_range.max do interest_deposit := an_interest_deposit ensure @@ -194,7 +167,9 @@ feature {NONE} -- Implementation end set_interest_debit (an_interest_debit: like interest_debit) - -- Assign `interest_debit' with `an_interest_debit'. + require + an_interest_deposit_within_bounds: interest_debit >= interest_debit_range.min + and interest_debit <= interest_debit_range.max do interest_debit := an_interest_debit ensure @@ -202,14 +177,12 @@ feature {NONE} -- Implementation end invariant - interest_debit_within_bounds: - interest_debit >= interest_debit_range.item (1) and - interest_debit <= interest_debit_range.item (2) - interest_deposit_within_bounds: - interest_deposit >= interest_deposit_range.item (1) and - interest_deposit <= interest_deposit_range.item (2) - authorized_signers_attached: authorized_signers /= Void authorized_signers_not_empty: authorized_signers.count > 0 transfer_minamount_positive: transfer_minamount > 0.0 - creditline_range_correct: creditline >= creditline_range.item (1) and creditline <= creditline_range.item (2) + creditline_within_bounds: creditline >= creditline_range.min + and creditline <= creditline_range.max + interest_debit_within_bounds: interest_debit >= interest_debit_range.min + and interest_debit <= interest_debit_range.max + interest_deposit_within_bounds: interest_deposit >= interest_deposit_range.min + and interest_deposit <= interest_deposit_range.max end diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e index 32d10ff..7c30afb 100644 --- a/bank-eiffel/bank.e +++ b/bank-eiffel/bank.e @@ -10,11 +10,32 @@ class create make +feature {NONE} -- Implementation + + customers: ARRAYED_SET [PERSON] + -- Kunden + + accounts: ARRAYED_SET [ACCOUNT] + -- Vorname + feature {NONE} -- Initialization make do + create customers.make(100) + create accounts.make(100) + end + +feature -- Basic operations + get_customers: FINITE [PERSON] + do + Result := customers + end + + get_accounts: FINITE [ACCOUNT] + do + Result := accounts end end diff --git a/bank-eiffel/bank.ecf b/bank-eiffel/bank.ecf index b3bf92c..1eef831 100644 --- a/bank-eiffel/bank.ecf +++ b/bank-eiffel/bank.ecf @@ -4,7 +4,7 @@ FOOP Exercise #3 - diff --git a/bank-eiffel/person.e b/bank-eiffel/person.e index 54e1a45..9a2b281 100644 --- a/bank-eiffel/person.e +++ b/bank-eiffel/person.e @@ -14,11 +14,9 @@ feature -- Access surname: STRING_8 assign set_surname -- Nachname - attribute Result := ({like surname}).default end --| Remove line when Void Safety is properly set firstname: STRING_8 assign set_firstname -- Vorname - attribute Result := ({like firstname}).default end --| Remove line when Void Safety is properly set feature {NONE} -- Initialization @@ -33,7 +31,7 @@ feature {NONE} -- Implementation set_surname (a_surname: like surname) -- Assign `surname' with `a_surname'. require - a_surname_not_empty: a_surname /= Void and then not a_surname.is_empty + a_surname_not_empty: not a_surname.is_empty do surname := a_surname ensure @@ -43,7 +41,7 @@ feature {NONE} -- Implementation set_firstname (a_firstname: like firstname) -- Assign `firstname' with `a_firstname'. require - a_firstname_not_empty: a_firstname /= Void and then not a_firstname.is_empty + a_firstname_not_empty: not a_firstname.is_empty do firstname := a_firstname ensure @@ -51,6 +49,6 @@ feature {NONE} -- Implementation end invariant - firstname_not_empty: firstname /= Void and then not firstname.is_empty - surname_not_empty: surname /= Void and then not surname.is_empty + firstname_not_empty: not firstname.is_empty + surname_not_empty: not surname.is_empty end diff --git a/bank-eiffel/retiree.e b/bank-eiffel/retiree.e index 57e5d05..7f24d89 100644 --- a/bank-eiffel/retiree.e +++ b/bank-eiffel/retiree.e @@ -10,4 +10,7 @@ class inherit PERSON +create + make + end diff --git a/bank-eiffel/retireeaccount.e b/bank-eiffel/retireeaccount.e index 3f56fd4..cf9bc91 100644 --- a/bank-eiffel/retireeaccount.e +++ b/bank-eiffel/retireeaccount.e @@ -10,6 +10,16 @@ class inherit ACCOUNT +create + make + invariant authorized_signers_only_one: authorized_signers.count = 1 + authorized_signers_attached: authorized_signers.linear_representation /= Void + authorized_signers_only_retirees: + (attached authorized_signers.linear_representation as signers) implies signers.for_all( + agent (person: PERSON): BOOLEAN + do + Result := attached {RETIREE} person + end) end diff --git a/bank-eiffel/student.e b/bank-eiffel/student.e index 2b5afd4..f910fa7 100644 --- a/bank-eiffel/student.e +++ b/bank-eiffel/student.e @@ -10,4 +10,7 @@ class inherit PERSON +create + make + end diff --git a/bank-eiffel/studentaccount.e b/bank-eiffel/studentaccount.e index a80d4bb..d1ccaef 100644 --- a/bank-eiffel/studentaccount.e +++ b/bank-eiffel/studentaccount.e @@ -10,6 +10,16 @@ class inherit ACCOUNT +create + make + invariant authorized_signers_only_one: authorized_signers.count = 1 + authorized_signers_attached: authorized_signers.linear_representation /= Void + authorized_signers_only_students: + (attached authorized_signers.linear_representation as signers) implies signers.for_all( + agent (person: PERSON): BOOLEAN + do + Result := attached {STUDENT} person + end) end diff --git a/bank-eiffel/tests/test_account.e b/bank-eiffel/tests/test_account.e index e0dfe4d..e1ca892 100644 --- a/bank-eiffel/tests/test_account.e +++ b/bank-eiffel/tests/test_account.e @@ -19,32 +19,67 @@ feature -- Test routines local person1: PERSON person2: PERSON - account: ACCOUNT + person3: PERSON + account1: ACCOUNT + account2: ACCOUNT do create person1.make ("SOME_SURNAME_1", "SOME_FIRSTNAME_1") create person2.make ("SOME_SURNAME_2", "SOME_FIRSTNAME_2") + create person3.make ("SOME_SURNAME_3", "SOME_FIRSTNAME_3") - create account.make (person1, 0.01, 0.02, -50.0, <<0.01, 0.022>>, <<0.01, 0.02>>, <<-100, -50>>) - account.add_authorized_signer (person2) + create account1.make (person1, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + assert("CREATE_EDIT_ACCOUNT_SIGNER_1", account1.get_authorized_signers.count = 1) + account1.add_authorized_signer (person2) + account1.add_authorized_signer (person2) + account1.add_authorized_signer (person3) + account1.remove_authorized_signer (person3) + assert("CREATE_EDIT_ACCOUNT_SIGNER_2", account1.get_authorized_signers.count = 2) + assert("CREATE_EDIT_ACCOUNT_BALANCE_1", account1.balance = 0.0) + account1.deposit (50.0, person1) + account1.deposit (50.0, person2) + -- balance = 100.0 + account1.advance + -- balance = 100.0 + 1% deposit + account1.withdraw (100.0 + 100.0 * 0.01 + 50.0, person1) + -- balance = -50.0 + account1.creditline := -100.0 + account1.withdraw (50.0, person1) + -- balance = -100.0 + account1.advance + -- balance = -100.0 + 2% debit + assert("CREATE_EDIT_ACCOUNT_BALANCE_2", account1.balance = -102.0) - --assert ("not_implemented", False) + create account2.make(person3, 0.01, 0.02, -50, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + account2.deposit (102.0, person3) + account2.transfer (102.0, person3, account1, person1) + assert("CREATE_EDIT_ACCOUNT_BALANCE_3", account1.balance = 0.0 and account2.balance = 0.0) + + account1.interest_deposit := 0.01 + account1.interest_deposit := 0.022 + account1.interest_debit := 0.01 + account1.interest_debit := 0.02 + account1.creditline := -100.0 + account1.creditline := -50.0 + account1.transfer_minamount := 10.0 end - ADVANCE + CREATE_STUDENTACCOUNT local - person1: PERSON - account: ACCOUNT - b : REAL_64 + person: STUDENT + account: STUDENTACCOUNT do - create person1.make ("SOME_SURNAME_1", "SOME_FIRSTNAME_1") - create account.make (person1, 0.01, 0.02, -50.0, <<0.01, 0.022>>, <<0.01, 0.02>>, <<-100, -50>>) - - account.deposit (100.0, person1) - account.advance - - assert("balance not correct", account.get_balance = 101.0) + create person.make("SOME_SURNAME", "SOME_FIRSTNAME") + create account.make(person, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) end + CREATE_RETIREEACCOUNT + local + person: RETIREE + account: RETIREEACCOUNT + do + create person.make("SOME_SURNAME", "SOME_FIRSTNAME") + create account.make(person, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + end end diff --git a/bank-eiffel/tests/test_person.e b/bank-eiffel/tests/test_person.e index a501deb..67aea34 100644 --- a/bank-eiffel/tests/test_person.e +++ b/bank-eiffel/tests/test_person.e @@ -41,23 +41,12 @@ feature -- Test routines doretry := False assert("CREATE_EDIT_PERSON_EMPTY_SURNAME_1", False) elseif retry_count = 1 then - create person.make(void, "SOME_FIRSTNAME") - doretry := False - assert("CREATE_EDIT_PERSON_EMPTY_SURNAME_2", False) - elseif retry_count = 2 then doretry := False create person.make("SOME_SURNAME", "SOME_FIRSTNAME") doretry := True person.surname := "" doretry := False assert("CREATE_EDIT_PERSON_EMPTY_SURNAME_3", False) - elseif retry_count = 3 then - doretry := False - create person.make("SOME_SURNAME", "SOME_FIRSTNAME") - doretry := True - person.surname := void - doretry := False - assert("CREATE_EDIT_PERSON_EMPTY_SURNAME_4", False) else doretry := False end @@ -80,23 +69,12 @@ feature -- Test routines doretry := False assert("CREATE_EDIT_PERSON_EMPTY_FIRSTNAME_1", False) elseif retry_count = 1 then - create person.make("SOME_SURNAME", void) - doretry := False - assert("CREATE_EDIT_PERSON_EMPTY_FIRSTNAME_2", False) - elseif retry_count = 2 then doretry := False create person.make("SOME_SURNAME", "SOME_FIRSTNAME") doretry := True person.firstname := "" doretry := False assert("CREATE_EDIT_PERSON_EMPTY_FIRSTNAME_3", False) - elseif retry_count = 3 then - doretry := False - create person.make("SOME_SURNAME", "SOME_FIRSTNAME") - doretry := True - person.firstname := void - doretry := False - assert("CREATE_EDIT_PERSON_EMPTY_FIRSTNAME_4", False) else doretry := False end -- cgit v1.2.3 From 1daf62f05c19e6f96d16d3688055dfd20d89d2b8 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 23 May 2011 20:37:54 +0200 Subject: - add tests - remove notes - fix minamount for subaccounts --- bank-eiffel/account.e | 16 +++--- bank-eiffel/application.e | 5 -- bank-eiffel/bank.e | 6 --- bank-eiffel/person.e | 6 --- bank-eiffel/retiree.e | 8 +-- bank-eiffel/retireeaccount.e | 18 ++++--- bank-eiffel/student.e | 6 --- bank-eiffel/studentaccount.e | 16 +++--- bank-eiffel/tests/test_account.e | 111 ++++++++++++++++++++++++++++++++------- bank-eiffel/tests/test_person.e | 37 ++++--------- 10 files changed, 131 insertions(+), 98 deletions(-) (limited to 'bank-eiffel') diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index d0a3fc4..1fc62fb 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -1,9 +1,3 @@ -note - description: "Summary description for {ACCOUNT}." - author: "" - date: "$Date$" - revision: "$Revision$" - class ACCOUNT @@ -57,14 +51,15 @@ feature {NONE} -- Initialization do create authorized_signers.make(1) add_authorized_signer (an_authorized_signer) - transfer_minamount := 2.0 - balance := 0.0 creditline := a_credit_line interest_debit := an_interest_debit interest_deposit := an_interest_deposit interest_deposit_range := an_interest_deposit_range interest_debit_range := an_interest_debit_range creditline_range := a_credit_line_range + + set_default_transfer_minamount + balance := 0.0 end feature -- Basic operations @@ -146,6 +141,11 @@ feature {NONE} -- Implementation transfer_minamount_assigned: transfer_minamount = a_transfer_minamount end + set_default_transfer_minamount + do + set_transfer_minamount (2.0) + end + set_creditline (a_creditline: like creditline) require a_creditline_within_bounds: a_creditline >= creditline_range.min diff --git a/bank-eiffel/application.e b/bank-eiffel/application.e index c880bf9..55b02d9 100644 --- a/bank-eiffel/application.e +++ b/bank-eiffel/application.e @@ -1,8 +1,3 @@ -note - description : "bank application root class" - date : "$Date$" - revision : "$Revision$" - class APPLICATION diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e index 7c30afb..bad3bda 100644 --- a/bank-eiffel/bank.e +++ b/bank-eiffel/bank.e @@ -1,9 +1,3 @@ -note - description: "Summary description for {BANK}." - author: "" - date: "$Date$" - revision: "$Revision$" - class BANK diff --git a/bank-eiffel/person.e b/bank-eiffel/person.e index 9a2b281..ffaab72 100644 --- a/bank-eiffel/person.e +++ b/bank-eiffel/person.e @@ -1,9 +1,3 @@ -note - description: "Summary description for {PERSON}." - author: "" - date: "$Date$" - revision: "$Revision$" - class PERSON diff --git a/bank-eiffel/retiree.e b/bank-eiffel/retiree.e index 7f24d89..e8a2edd 100644 --- a/bank-eiffel/retiree.e +++ b/bank-eiffel/retiree.e @@ -1,9 +1,3 @@ -note - description: "Summary description for {RETIREE}." - author: "" - date: "$Date$" - revision: "$Revision$" - class RETIREE @@ -12,5 +6,5 @@ inherit create make - + end diff --git a/bank-eiffel/retireeaccount.e b/bank-eiffel/retireeaccount.e index cf9bc91..3db0cd4 100644 --- a/bank-eiffel/retireeaccount.e +++ b/bank-eiffel/retireeaccount.e @@ -1,18 +1,22 @@ -note - description: "Summary description for {RETIREEACCOUNT}." - author: "" - date: "$Date$" - revision: "$Revision$" - class RETIREEACCOUNT inherit ACCOUNT - + redefine + set_default_transfer_minamount + end + create make +feature {NONE} -- Implementation + + set_default_transfer_minamount + do + set_transfer_minamount (1.0) + end + invariant authorized_signers_only_one: authorized_signers.count = 1 authorized_signers_attached: authorized_signers.linear_representation /= Void diff --git a/bank-eiffel/student.e b/bank-eiffel/student.e index f910fa7..0c3863a 100644 --- a/bank-eiffel/student.e +++ b/bank-eiffel/student.e @@ -1,9 +1,3 @@ -note - description: "Summary description for {STUDENT}." - author: "" - date: "$Date$" - revision: "$Revision$" - class STUDENT diff --git a/bank-eiffel/studentaccount.e b/bank-eiffel/studentaccount.e index d1ccaef..04a9e31 100644 --- a/bank-eiffel/studentaccount.e +++ b/bank-eiffel/studentaccount.e @@ -1,18 +1,22 @@ -note - description: "Summary description for {STUDENTACCOUNT}." - author: "" - date: "$Date$" - revision: "$Revision$" - class STUDENTACCOUNT inherit ACCOUNT + redefine + set_default_transfer_minamount + end create make +feature {NONE} -- Implementation + + set_default_transfer_minamount + do + set_transfer_minamount (1.0) + end + invariant authorized_signers_only_one: authorized_signers.count = 1 authorized_signers_attached: authorized_signers.linear_representation /= Void diff --git a/bank-eiffel/tests/test_account.e b/bank-eiffel/tests/test_account.e index e1ca892..4430ab0 100644 --- a/bank-eiffel/tests/test_account.e +++ b/bank-eiffel/tests/test_account.e @@ -1,12 +1,3 @@ -note - description: "[ - Eiffel tests that can be executed by testing tool. - ]" - author: "EiffelStudio test wizard" - date: "$Date$" - revision: "$Revision$" - testing: "type/manual" - class TEST_ACCOUNT @@ -23,11 +14,13 @@ feature -- Test routines account1: ACCOUNT account2: ACCOUNT do - create person1.make ("SOME_SURNAME_1", "SOME_FIRSTNAME_1") - create person2.make ("SOME_SURNAME_2", "SOME_FIRSTNAME_2") - create person3.make ("SOME_SURNAME_3", "SOME_FIRSTNAME_3") + create person1.make ("PERSON1", "PERSON1") + create person2.make ("PERSON2", "PERSON2") + create person3.make ("PERSON3", "PERSON3") create account1.make (person1, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + assert("CREATE_EDIT_ACCOUNT_MINAMOUNT", account1.transfer_minamount = 2.0) + assert("CREATE_EDIT_ACCOUNT_SIGNER_1", account1.get_authorized_signers.count = 1) account1.add_authorized_signer (person2) account1.add_authorized_signer (person2) @@ -66,20 +59,100 @@ feature -- Test routines CREATE_STUDENTACCOUNT local - person: STUDENT + student: STUDENT + account: STUDENTACCOUNT + do + create student.make("STUDENT", "STUDENT") + create account.make(student, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + assert("CREATE_STUDENTACCOUNT", attached {ACCOUNT} account) + assert("CREATE_STUDENTACCOUNT_MINAMOUNT", account.transfer_minamount = 1.0) + end + + CREATE_STUDENTACCOUNT_ONLY_STUDENTS + local account: STUDENTACCOUNT + student: STUDENT + person: PERSON + retiree: RETIREE + retry_count: INTEGER do - create person.make("SOME_SURNAME", "SOME_FIRSTNAME") - create account.make(person, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + create student.make("STUDENT", "STUDENT") + create person.make("PERSON", "PERSON") + create retiree.make("RETIREE", "RETIREE") + + if retry_count = 0 then + create account.make(person, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + assert("CREATE_STUDENTACCOUNT_ONLY_STUDENTS_1", False) + elseif retry_count = 1 then + create account.make(retiree, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + assert("CREATE_STUDENTACCOUNT_ONLY_STUDENTS_2", False) + elseif retry_count = 2 then + create account.make(student, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + account.add_authorized_signer (create {STUDENT}.make("STUDENT2", "STUDENT2")) + assert("CREATE_STUDENTACCOUNT_ONE_STUDENT_ONLY_1", False) + elseif retry_count = 3 then + create account.make(student, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + account.add_authorized_signer (person) + assert("CREATE_STUDENTACCOUNT_ONE_STUDENT_ONLY_2", False) + elseif retry_count = 4 then + create account.make(student, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + account.add_authorized_signer (retiree) + assert("CREATE_STUDENTACCOUNT_ONE_STUDENT_ONLY_3", False) + end + rescue + if not (create {EXCEPTIONS}).is_developer_exception then + retry_count := retry_count + 1 + retry + end end CREATE_RETIREEACCOUNT local - person: RETIREE + retiree: RETIREE account: RETIREEACCOUNT do - create person.make("SOME_SURNAME", "SOME_FIRSTNAME") - create account.make(person, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + create retiree.make("RETIREE", "RETIREE") + create account.make(retiree, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + assert("CREATE_RETIREEACCOUNT", attached {ACCOUNT} account) + assert("CREATE_RETIREEACCOUNT_MINAMOUNT", account.transfer_minamount = 1.0) end -end + + CREATE_RETIREEACCOUNT_ONLY_RETIREES + local + account: RETIREEACCOUNT + retiree: RETIREE + person: PERSON + student: STUDENT + retry_count: INTEGER + do + create retiree.make("RETIREE", "RETIREE") + create person.make("PERSON", "PERSON") + create student.make("STUDENT", "STUDENT") + + if retry_count = 0 then + create account.make(person, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + assert("CREATE_RETIREEACCOUNT_ONLY_RETIREES_1", False) + elseif retry_count = 1 then + create account.make(student, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + assert("CREATE_RETIREEACCOUNT_ONLY_RETIREES_2", False) + elseif retry_count = 2 then + create account.make(retiree, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + account.add_authorized_signer (create {RETIREE}.make("RETIREE2", "RETIREE2")) + assert("CREATE_RETIREEACCOUNT_ONE_RETIREE_ONLY_1", False) + elseif retry_count = 3 then + create account.make(retiree, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + account.add_authorized_signer (person) + assert("CREATE_RETIREEACCOUNT_ONE_RETIREE_ONLY_2", False) + elseif retry_count = 4 then + create account.make(retiree, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + account.add_authorized_signer (student) + assert("CREATE_RETIREEACCOUNT_ONE_RETIREE_ONLY_3", False) + end + rescue + if not (create {EXCEPTIONS}).is_developer_exception then + retry_count := retry_count + 1 + retry + end + end +end diff --git a/bank-eiffel/tests/test_person.e b/bank-eiffel/tests/test_person.e index 67aea34..f42767c 100644 --- a/bank-eiffel/tests/test_person.e +++ b/bank-eiffel/tests/test_person.e @@ -1,12 +1,3 @@ -note - description: "[ - Eiffel tests that can be executed by testing tool. - ]" - author: "EiffelStudio test wizard" - date: "$Date$" - revision: "$Revision$" - testing: "type/manual" - class TEST_PERSON @@ -14,10 +5,11 @@ inherit EQA_TEST_SET feature -- Test routines - CREATE_EDIT_PERSON local person: PERSON + student: STUDENT + retiree: RETIREE do create person.make("SOME_SURNAME_1", "SOME_FIRSTNAME_1") assert("CREATE_EDIT_PERSON_FIRSTNAME_1", person.firstname.is_equal("SOME_FIRSTNAME_1")) @@ -27,31 +19,28 @@ feature -- Test routines assert("CREATE_EDIT_PERSON_FIRSTNAME_2", person.firstname.is_equal("SOME_FIRSTNAME_2")) person.surname := "SOME_SURNAME_2" assert("CREATE_EDIT_PERSON_SURNAME_2", person.surname.is_equal("SOME_SURNAME_2")) + + create student.make ("STUDENT_SURNAME", "STUDENT_FIRSTNAME") + assert("CREATE_EDIT_PERSON_STUDENT", attached {PERSON} student) + create retiree.make ("RETIREE_SURNAME", "RETIREE_FIRSTNAME") + assert("CREATE_EDIT_PERSON_RETIREE", attached {PERSON} student) end CREATE_EDIT_PERSON_EMPTY_SURNAME local person: PERSON retry_count: INTEGER - doretry: BOOLEAN do if retry_count = 0 then - doretry := True create person.make("", "SOME_FIRSTNAME") - doretry := False assert("CREATE_EDIT_PERSON_EMPTY_SURNAME_1", False) elseif retry_count = 1 then - doretry := False create person.make("SOME_SURNAME", "SOME_FIRSTNAME") - doretry := True person.surname := "" - doretry := False assert("CREATE_EDIT_PERSON_EMPTY_SURNAME_3", False) - else - doretry := False end rescue - if doretry then + if not (create {EXCEPTIONS}).is_developer_exception then retry_count := retry_count + 1 retry end @@ -61,25 +50,17 @@ feature -- Test routines local person: PERSON retry_count: INTEGER - doretry: BOOLEAN do if retry_count = 0 then - doretry := True create person.make("SOME_SURNAME", "") - doretry := False assert("CREATE_EDIT_PERSON_EMPTY_FIRSTNAME_1", False) elseif retry_count = 1 then - doretry := False create person.make("SOME_SURNAME", "SOME_FIRSTNAME") - doretry := True person.firstname := "" - doretry := False assert("CREATE_EDIT_PERSON_EMPTY_FIRSTNAME_3", False) - else - doretry := False end rescue - if doretry then + if not (create {EXCEPTIONS}).is_developer_exception then retry_count := retry_count + 1 retry end -- cgit v1.2.3 From 9a787349e121be1ad9e83d4086244cd90422ee0e Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 23 May 2011 21:30:40 +0200 Subject: more tests --- bank-eiffel/account.e | 3 +- bank-eiffel/tests/test_account.e | 139 ++++++++++++++++++++++++++++++++------- bank-eiffel/tests/test_person.e | 24 ++++--- 3 files changed, 133 insertions(+), 33 deletions(-) (limited to 'bank-eiffel') diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index 1fc62fb..7c127ec 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -105,7 +105,8 @@ feature -- Basic operations remove_authorized_signer (an_authorized_signer: PERSON) require - authorized_signers_never_empty: get_authorized_signers.count >= 2 + authorized_signers_never_empty: (get_authorized_signers.has (an_authorized_signer) + and get_authorized_signers.count >= 2) or True do if authorized_signers.has (an_authorized_signer) then authorized_signers.prune (an_authorized_signer) diff --git a/bank-eiffel/tests/test_account.e b/bank-eiffel/tests/test_account.e index 4430ab0..212ad6a 100644 --- a/bank-eiffel/tests/test_account.e +++ b/bank-eiffel/tests/test_account.e @@ -57,6 +57,97 @@ feature -- Test routines account1.transfer_minamount := 10.0 end + ACCOUNT_CHECK_RANGES + local + person: PERSON + account: ACCOUNT + retry_count: INTEGER + do + create person.make("PERSON", "PERSON") + create account.make(person, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + + inspect retry_count + when 0 then + account.interest_deposit := 0.0 + assert("ACCOUNT_CHECK_RANGES_INTEREST_DEPOSIT_MIN", False) + when 1 then + account.interest_deposit := 0.023 + assert("ACCOUNT_CHECK_RANGES_INTEREST_DEPOSIT_MAX", False) + when 2 then + account.interest_debit := 0.0 + assert("ACCOUNT_CHECK_RANGES_INTEREST_DEBIT_MIN", False) + when 3 then + account.interest_debit := 0.03 + assert("ACCOUNT_CHECK_RANGES_INTEREST_DEBIT_MAX", False) + when 4 then + account.creditline := -101.0 + assert("ACCOUNT_CHECK_RANGES_CREDITLINE_MIN", False) + when 5 then + account.creditline := -49.0 + assert("ACCOUNT_CHECK_RANGES_CREDITLINE_MAX", False) + when 6 then + account.transfer_minamount := -1.0 + assert("ACCOUNT_CHECK_RANGES_TRANSFER_MINAMOUNT_POSITIVE", False) + else + end + rescue + if not (create {EXCEPTIONS}).is_developer_exception then + retry_count := retry_count + 1 + retry + end + end + + ACCOUNT_CHECK_OPERATIONS + local + person1: PERSON + account1: ACCOUNT + person2: PERSON + account2: ACCOUNT + retry_count: INTEGER + i: INTEGER + do + create person1.make("PERSON1", "PERSON1") + create person2.make("PERSON2", "PERSON2") + create account1.make(person1, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + create account2.make(person2, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) + + inspect retry_count + when 0 then + account1.deposit (10.0, person2) + assert("ACCOUNT_CHECK_OPERATIONS_DEPOSIT_OTHER", False) + when 1 then + account1.withdraw (10.0, person2) + assert("ACCOUNT_CHECK_OPERATIONS_WITHDRAW_OTHER", False) + when 2 then + account1.transfer (10.0, person2, account2, person2) + assert("ACCOUNT_CHECK_OPERATIONS_TRANSFER_OTHER_1", False) + when 3 then + account1.transfer (10.0, person1, account2, person1) + assert("ACCOUNT_CHECK_OPERATIONS_TRANSFER_OTHER_2", False) + when 4 then + account1.withdraw (51.0, person1) + assert("ACCOUNT_CHECK_OPERATIONS_WITHDRAW_OVER_CREDIT", False) + when 5 then + account1.deposit (1.0, person1) + assert("ACCOUNT_CHECK_OPERATIONS_DEPOSIT_BELOW_MINAMOUNT", False) + when 6 then + account1.withdraw (1.0, person1) + assert("ACCOUNT_CHECK_OPERATIONS_WITHDRAW_BELOW_MINAMOUNT", False) + when 7 then + account1.transfer (1.0, person1, account2, person2) + assert("ACCOUNT_CHECK_OPERATIONS_TRANSFER_BELOW_MINAMOUNT", False) + when 8 then + account1.remove_authorized_signer (person1) + assert("ACCOUNT_CHECK_OPERATIONS_REMOVE_AUTHORIZED_SIGNER_EMPTY", False) + else + end + rescue + if retry_count /= 9 and not (create {EXCEPTIONS}).is_developer_exception then + retry_count := retry_count + 1 + retry + end + end + CREATE_STUDENTACCOUNT local student: STUDENT @@ -68,7 +159,7 @@ feature -- Test routines assert("CREATE_STUDENTACCOUNT_MINAMOUNT", account.transfer_minamount = 1.0) end - CREATE_STUDENTACCOUNT_ONLY_STUDENTS + STUDENTACCOUNT_ONLY_STUDENTS local account: STUDENTACCOUNT student: STUDENT @@ -80,24 +171,26 @@ feature -- Test routines create person.make("PERSON", "PERSON") create retiree.make("RETIREE", "RETIREE") - if retry_count = 0 then + inspect retry_count + when 0 then create account.make(person, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) - assert("CREATE_STUDENTACCOUNT_ONLY_STUDENTS_1", False) - elseif retry_count = 1 then + assert("STUDENTACCOUNT_ONLY_STUDENTS_1", False) + when 1 then create account.make(retiree, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) - assert("CREATE_STUDENTACCOUNT_ONLY_STUDENTS_2", False) - elseif retry_count = 2 then + assert("STUDENTACCOUNT_ONLY_STUDENTS_2", False) + when 2 then create account.make(student, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) account.add_authorized_signer (create {STUDENT}.make("STUDENT2", "STUDENT2")) - assert("CREATE_STUDENTACCOUNT_ONE_STUDENT_ONLY_1", False) - elseif retry_count = 3 then + assert("STUDENTACCOUNT_ONE_STUDENT_ONLY_1", False) + when 3 then create account.make(student, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) account.add_authorized_signer (person) - assert("CREATE_STUDENTACCOUNT_ONE_STUDENT_ONLY_2", False) - elseif retry_count = 4 then + assert("STUDENTACCOUNT_ONE_STUDENT_ONLY_2", False) + when 4 then create account.make(student, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) account.add_authorized_signer (retiree) - assert("CREATE_STUDENTACCOUNT_ONE_STUDENT_ONLY_3", False) + assert("STUDENTACCOUNT_ONE_STUDENT_ONLY_3", False) + else end rescue if not (create {EXCEPTIONS}).is_developer_exception then @@ -118,7 +211,7 @@ feature -- Test routines end - CREATE_RETIREEACCOUNT_ONLY_RETIREES + RETIREEACCOUNT_ONLY_RETIREES local account: RETIREEACCOUNT retiree: RETIREE @@ -130,24 +223,26 @@ feature -- Test routines create person.make("PERSON", "PERSON") create student.make("STUDENT", "STUDENT") - if retry_count = 0 then + inspect retry_count + when 0 then create account.make(person, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) - assert("CREATE_RETIREEACCOUNT_ONLY_RETIREES_1", False) - elseif retry_count = 1 then + assert("RETIREEACCOUNT_ONLY_RETIREES_1", False) + when 1 then create account.make(student, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) - assert("CREATE_RETIREEACCOUNT_ONLY_RETIREES_2", False) - elseif retry_count = 2 then + assert("RETIREEACCOUNT_ONLY_RETIREES_2", False) + when 2 then create account.make(retiree, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) account.add_authorized_signer (create {RETIREE}.make("RETIREE2", "RETIREE2")) - assert("CREATE_RETIREEACCOUNT_ONE_RETIREE_ONLY_1", False) - elseif retry_count = 3 then + assert("RETIREEACCOUNT_ONE_RETIREE_ONLY_1", False) + when 3 then create account.make(retiree, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) account.add_authorized_signer (person) - assert("CREATE_RETIREEACCOUNT_ONE_RETIREE_ONLY_2", False) - elseif retry_count = 4 then + assert("RETIREEACCOUNT_ONE_RETIREE_ONLY_2", False) + when 4 then create account.make(retiree, 0.01, 0.02, -50.0, [0.01, 0.022], [0.01, 0.02], [-100.0, -50.0]) account.add_authorized_signer (student) - assert("CREATE_RETIREEACCOUNT_ONE_RETIREE_ONLY_3", False) + assert("RETIREEACCOUNT_ONE_RETIREE_ONLY_3", False) + else end rescue if not (create {EXCEPTIONS}).is_developer_exception then diff --git a/bank-eiffel/tests/test_person.e b/bank-eiffel/tests/test_person.e index f42767c..01e9a50 100644 --- a/bank-eiffel/tests/test_person.e +++ b/bank-eiffel/tests/test_person.e @@ -26,18 +26,20 @@ feature -- Test routines assert("CREATE_EDIT_PERSON_RETIREE", attached {PERSON} student) end - CREATE_EDIT_PERSON_EMPTY_SURNAME + PERSON_EMPTY_SURNAME local person: PERSON retry_count: INTEGER do - if retry_count = 0 then + inspect retry_count + when 0 then create person.make("", "SOME_FIRSTNAME") - assert("CREATE_EDIT_PERSON_EMPTY_SURNAME_1", False) - elseif retry_count = 1 then + assert("PERSON_EMPTY_SURNAME_1", False) + when 1 then create person.make("SOME_SURNAME", "SOME_FIRSTNAME") person.surname := "" - assert("CREATE_EDIT_PERSON_EMPTY_SURNAME_3", False) + assert("PERSON_EMPTY_SURNAME_3", False) + else end rescue if not (create {EXCEPTIONS}).is_developer_exception then @@ -46,18 +48,20 @@ feature -- Test routines end end - CREATE_EDIT_PERSON_EMPTY_FIRSTNAME + PERSON_EMPTY_FIRSTNAME local person: PERSON retry_count: INTEGER do - if retry_count = 0 then + inspect retry_count + when 0 then create person.make("SOME_SURNAME", "") - assert("CREATE_EDIT_PERSON_EMPTY_FIRSTNAME_1", False) - elseif retry_count = 1 then + assert("PERSON_EMPTY_FIRSTNAME_1", False) + when 1 then create person.make("SOME_SURNAME", "SOME_FIRSTNAME") person.firstname := "" - assert("CREATE_EDIT_PERSON_EMPTY_FIRSTNAME_3", False) + assert("PERSON_EMPTY_FIRSTNAME_3", False) + else end rescue if not (create {EXCEPTIONS}).is_developer_exception then -- cgit v1.2.3 From 4c7743e63274a67136d849dea75262262221a570 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 24 May 2011 18:04:21 +0200 Subject: adding bank example app (not fully implemented yet) --- bank-eiffel/application.e | 19 --- bank-eiffel/bank.e | 269 +++++++++++++++++++++++++++++++++++++-- bank-eiffel/bank.ecf | 14 +- bank-eiffel/tests/test_account.e | 1 - 4 files changed, 267 insertions(+), 36 deletions(-) delete mode 100644 bank-eiffel/application.e (limited to 'bank-eiffel') diff --git a/bank-eiffel/application.e b/bank-eiffel/application.e deleted file mode 100644 index 55b02d9..0000000 --- a/bank-eiffel/application.e +++ /dev/null @@ -1,19 +0,0 @@ -class - APPLICATION - -inherit - ARGUMENTS - -create - make - -feature {NONE} -- Initialization - - make - -- Run application. - do - --| Add your code here - print ("Hello Eiffel World!%N") - end - -end diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e index bad3bda..1f61c6e 100644 --- a/bank-eiffel/bank.e +++ b/bank-eiffel/bank.e @@ -2,34 +2,287 @@ class BANK create - make + run feature {NONE} -- Implementation - customers: ARRAYED_SET [PERSON] + persons: ARRAYED_SET [PERSON] -- Kunden accounts: ARRAYED_SET [ACCOUNT] -- Vorname + over: BOOLEAN + + last_error: STRING + feature {NONE} -- Initialization - make + run do - create customers.make(100) + create persons.make(100) create accounts.make(100) + create last_error.make_empty + session end feature -- Basic operations - get_customers: FINITE [PERSON] + session + do + from + until + over + loop + main_screen + end + end + + print_last_error do - Result := customers + if not last_error.is_empty then + print (last_error + "%N%N") + last_error := "" + end end - get_accounts: FINITE [ACCOUNT] + print_header do - Result := accounts + clear_screen + print ("**************************************%N") + print ("********* BANK of FOOP *********%N") + print ("**************************************%N") end + clear_screen + do + io.put_character ((0x1B).to_character_8) + io.put_string ("[2J") + io.put_character ((0x1B).to_character_8) + io.put_string ("[H") + end + + main_screen + do + print_header + print ("Operations:%N") + print (" p ...list/create/edit persons%N") + print (" a ...list/create/edit accounts%N") + print (" q ...quit%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character.lower + when 'p' then + persons_screen + when 'a' then + accounts_screen + when 'q' then + over := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + + persons_screen + local + back: BOOLEAN + do + from + until + back + loop + print_header + print ("Operations:%N") + print (" l ...list persons%N") + print (" c ...create person%N") + print (" e ...edit person%N") + print (" d ...delete person%N") + print (" b ...back%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character + when 'l' then + list_persons + when 'c' then + create_persons + when 'e' then + edit_person + when 'd' then + delete_person + when 'b' then + back := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + end + + accounts_screen + local + back: BOOLEAN + do + from + until + back + loop + print_header + print ("Operations:%N") + print (" l ...list accounts%N") + print (" c ...create accounts%N") + print (" e ...edit accounts%N") + print (" b ...back%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character + when 'l' then + when 'c' then + when 'e' then + when 'b' then + back := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + end + + list_persons + do + print ("%N") + print ("Persons: " + persons.count.out + "%N%N") + from + persons.start + until + persons.off + loop + print ("#" + persons.index.out + " " + persons.item.surname + ", " + persons.item.firstname) + if attached {RETIREE} persons.item then + print (" (RETIREE)") + elseif attached {STUDENT} persons.item then + print (" (STUDENT)") + end + print ("%N") + persons.forth + end + + print ("%N") + print ("Press to go back") + io.read_line + end + + create_persons + local + back: BOOLEAN + firstname: STRING + surname: STRING + do + from + until + back + loop + print_header + print ("Operations:%N") + print (" p ...create person%N") + print (" s ...create student%N") + print (" r ...create retiree%N") + print (" b ...back%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character + when 'p', 's', 'r' then + print ("Enter surname: ") + io.readline + surname := io.last_string.twin + + print ("Enter firstname: ") + io.readline + firstname := io.last_string.twin + + inspect io.last_character + when 'p' then + persons.put(create {PERSON}.make(surname, firstname)) + when 's' then + persons.put(create {STUDENT}.make(surname, firstname)) + when 'r' then + persons.put(create {RETIREE}.make(surname, firstname)) + else + end + last_error := "Person (#" + persons.count.out + ") created successfully" + back := True + when 'b' then + back := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + rescue + if not (create {EXCEPTIONS}).is_signal then + last_error := "Exception: " + (create {EXCEPTIONS}).tag_name + retry + end + end + + edit_person + local + firstname: STRING + surname: STRING + do + print ("%N") + print ("Enter person id (0 ...back): ") + io.read_integer + if io.last_integer > 0 then + if persons.valid_index (io.last_integer) then + persons.go_i_th (io.last_integer) + + print ("Enter surname [" + persons.item.surname + "]: ") + io.readline + if not io.last_string.is_empty then + persons.item.surname := io.last_string.twin + end + + print ("Enter firstname [" + persons.item.firstname + "]: ") + io.readline + if not io.last_string.is_empty then + persons.item.firstname := io.last_string.twin + end + else + last_error := "Invalid person id" + end + end + end + + delete_person + do + print ("%N") + print ("Enter person id (0 ...back): ") + io.read_integer + if io.last_integer > 0 then + if persons.valid_index (io.last_integer) then + persons.go_i_th (io.last_integer) + persons.remove + last_error := "Person (#" + io.last_integer.out + ") removed successfully" + else + last_error := "Invalid person id" + end + end + end end diff --git a/bank-eiffel/bank.ecf b/bank-eiffel/bank.ecf index 1eef831..404ab84 100644 --- a/bank-eiffel/bank.ecf +++ b/bank-eiffel/bank.ecf @@ -1,26 +1,24 @@ - FOOP Exercise #3 - + Bank of FOOP + - - + + + + /EIFGENs$ /CVS$ /.svn$ - - - - diff --git a/bank-eiffel/tests/test_account.e b/bank-eiffel/tests/test_account.e index 212ad6a..0b6ac46 100644 --- a/bank-eiffel/tests/test_account.e +++ b/bank-eiffel/tests/test_account.e @@ -104,7 +104,6 @@ feature -- Test routines person2: PERSON account2: ACCOUNT retry_count: INTEGER - i: INTEGER do create person1.make("PERSON1", "PERSON1") create person2.make("PERSON2", "PERSON2") -- cgit v1.2.3 From ccfe458b09dd900c12b0421f19abdf9887d5b912 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 26 May 2011 14:11:46 +0200 Subject: more bank example app: - add persistent store - implement ranges --- bank-eiffel/account.e | 8 +- bank-eiffel/bank.e | 206 +++++++++++++++++++++++++++++++++++++++-------- bank-eiffel/bank_store.e | 48 +++++++++++ 3 files changed, 225 insertions(+), 37 deletions(-) create mode 100644 bank-eiffel/bank_store.e (limited to 'bank-eiffel') diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index 7c127ec..fe9cc3b 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -23,13 +23,15 @@ feature -- Access feature {NONE} -- Implementation - creditline_range: TUPLE [min: like creditline; max: like creditline] + range: detachable TUPLE [min: REAL_64; max: REAL_64] + + creditline_range: attached like range -- min/max for creditline - interest_deposit_range: TUPLE [min: like interest_deposit; max: like interest_deposit] + interest_deposit_range: attached like range -- min/max for interest_deposit - interest_debit_range: TUPLE [min: like interest_debit; max: like interest_debit] + interest_debit_range: attached like range -- min/max for interest_debit authorized_signers: ARRAYED_SET [PERSON] diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e index 1f61c6e..f9390c7 100644 --- a/bank-eiffel/bank.e +++ b/bank-eiffel/bank.e @@ -6,24 +6,46 @@ create feature {NONE} -- Implementation - persons: ARRAYED_SET [PERSON] - -- Kunden - - accounts: ARRAYED_SET [ACCOUNT] - -- Vorname + store: BANK_STORE over: BOOLEAN last_error: STRING + data_file: RAW_FILE + + data_filename: STRING = "bank.data" + feature {NONE} -- Initialization run do - create persons.make(100) - create accounts.make(100) + create store.make(100) + store.ranges.account.creditline := [-1000.0, 0.0] + store.ranges.account.interest_deposit := [0.01, 0.04] + store.ranges.account.interest_debit := [0.02, 0.1] + store.ranges.studentaccount.creditline := [-300.0, 0.0] + store.ranges.studentaccount.interest_deposit := [0.02, 0.03] + store.ranges.studentaccount.interest_debit := [0.03, 0.06] + store.ranges.retireeaccount.creditline := [-300.0, 0.0] + store.ranges.retireeaccount.interest_deposit := [0.02, 0.03] + store.ranges.retireeaccount.interest_debit := [0.03, 0.06] create last_error.make_empty + + create data_file.make (data_filename) + if data_file.exists then + data_file.open_read + store ?= store.retrieved (data_file) + data_file.close + end + session + + if data_file.is_creatable then + data_file.open_write + store.independent_store (data_file) + data_file.close + end end feature -- Basic operations @@ -66,8 +88,9 @@ feature -- Basic operations do print_header print ("Operations:%N") - print (" p ...list/create/edit persons%N") - print (" a ...list/create/edit accounts%N") + print (" r ...list/edit global ranges%N") + print (" p ...list/create/edit/delete persons%N") + print (" a ...list/create/edit/delete accounts%N") print (" q ...quit%N") print ("%N") print_last_error @@ -76,6 +99,8 @@ feature -- Basic operations io.next_line inspect io.last_character.lower + when 'r' then + ranges_screen when 'p' then persons_screen when 'a' then @@ -88,6 +113,92 @@ feature -- Basic operations print ("%N%N") end + ranges_screen + local + back: BOOLEAN + do + from + until + back + loop + print_header + print ("Global Ranges:%N") + print (" Account:%N") + print_ranges(store.ranges.account) + print (" Student account:%N") + print_ranges(store.ranges.studentaccount) + print (" Retiree account:%N") + print_ranges(store.ranges.retireeaccount) + print ("%N") + print ("Operations:%N") + print (" a ...edit account ranges%N") + print (" s ...edit student account ranges%N") + print (" r ...edit retiree account ranges%N") + print (" b ...back%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character + when 'a' then + edit_ranges("account", store.ranges.account) + when 's' then + edit_ranges("student account", store.ranges.studentaccount) + when 'r' then + edit_ranges("retiree account", store.ranges.retireeaccount) + when 'b' then + back := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + end + + print_ranges(range: like {BANK_STORE}.account_range) + do + print (" - Creditline: " + print_range(range.creditline) + "%N") + print (" - Interest deposit: " + print_range(range.interest_deposit) + "%N") + print (" - Interest debit: " + print_range(range.interest_debit) + "%N") + end + + print_range(range: like {BANK_STORE}.range): STRING_8 + local + fd: FORMAT_DOUBLE + do + create fd.make(2, 2) + Result := "[" + fd.formatted(range.min) + ", " + fd.formatted(range.max) + "]" + end + + edit_ranges(type: STRING_8; range: like {BANK_STORE}.account_range) + do + print ("%N") + print ("Edit " + type + " range:%N") + edit_range("creditline", range.creditline) + edit_range("interest depost", range.interest_deposit) + edit_range("interest debit", range.interest_debit) + end + + edit_range(type: STRING_8; range: like {BANK_STORE}.range) + local + fd: FORMAT_DOUBLE + do + create fd.make(2, 2) + print ("Enter " + type + " minimum [" + fd.formatted(range.min) + "]: ") + io.readline + if io.last_string.is_double then + range.min := io.last_string.to_double + end + + print ("Enter " + type + " maximum [" + fd.formatted(range.max) + "]: ") + io.readline + if io.last_string.is_double then + range.max := io.last_string.to_double + end + end + persons_screen local back: BOOLEAN @@ -138,8 +249,9 @@ feature -- Basic operations print_header print ("Operations:%N") print (" l ...list accounts%N") - print (" c ...create accounts%N") - print (" e ...edit accounts%N") + print (" c ...create account%N") + print (" e ...edit account%N") + print (" d ...delete account%N") print (" b ...back%N") print ("%N") print_last_error @@ -149,8 +261,10 @@ feature -- Basic operations inspect io.last_character when 'l' then + list_accounts when 'c' then when 'e' then + when 'd' then when 'b' then back := True else @@ -163,20 +277,47 @@ feature -- Basic operations list_persons do print ("%N") - print ("Persons: " + persons.count.out + "%N%N") + print ("Persons: " + store.persons.count.out + "%N%N") from - persons.start + store.persons.start until - persons.off + store.persons.off loop - print ("#" + persons.index.out + " " + persons.item.surname + ", " + persons.item.firstname) - if attached {RETIREE} persons.item then + print ("#" + store.persons.index.out + " " + store.persons.item.surname + ", " + store.persons.item.firstname) + if attached {RETIREE} store.persons.item then print (" (RETIREE)") - elseif attached {STUDENT} persons.item then + elseif attached {STUDENT} store.persons.item then print (" (STUDENT)") end print ("%N") - persons.forth + store.persons.forth + end + + print ("%N") + print ("Press to go back") + io.read_line + end + + list_accounts + do + print ("%N") + print ("Accounts: " + store.accounts.count.out + "%N%N") + from + store.accounts.start + until + store.accounts.off + loop + --TODO + print ("#" + store.accounts.index.out + "%N") + print (" balance=" + store.accounts.item.balance.out + "%N") + print (" creditline=" + store.accounts.item.creditline.out + "%N") + if attached {RETIREEACCOUNT} store.accounts.item then + print (" (RETIREEACCOUNT)") + elseif attached {STUDENTACCOUNT} store.accounts.item then + print (" (STUDENTACCOUNT)") + end + print ("%N") + store.accounts.forth end print ("%N") @@ -218,14 +359,14 @@ feature -- Basic operations inspect io.last_character when 'p' then - persons.put(create {PERSON}.make(surname, firstname)) + store.persons.put(create {PERSON}.make(surname, firstname)) when 's' then - persons.put(create {STUDENT}.make(surname, firstname)) + store.persons.put(create {STUDENT}.make(surname, firstname)) when 'r' then - persons.put(create {RETIREE}.make(surname, firstname)) + store.persons.put(create {RETIREE}.make(surname, firstname)) else end - last_error := "Person (#" + persons.count.out + ") created successfully" + last_error := "Person (#" + store.persons.count.out + ") created successfully" back := True when 'b' then back := True @@ -242,27 +383,24 @@ feature -- Basic operations end edit_person - local - firstname: STRING - surname: STRING do print ("%N") print ("Enter person id (0 ...back): ") io.read_integer if io.last_integer > 0 then - if persons.valid_index (io.last_integer) then - persons.go_i_th (io.last_integer) + if store.persons.valid_index (io.last_integer) then + store.persons.go_i_th (io.last_integer) - print ("Enter surname [" + persons.item.surname + "]: ") + print ("Enter surname [" + store.persons.item.surname + "]: ") io.readline if not io.last_string.is_empty then - persons.item.surname := io.last_string.twin + store.persons.item.surname := io.last_string.twin end - print ("Enter firstname [" + persons.item.firstname + "]: ") + print ("Enter firstname [" + store.persons.item.firstname + "]: ") io.readline if not io.last_string.is_empty then - persons.item.firstname := io.last_string.twin + store.persons.item.firstname := io.last_string.twin end else last_error := "Invalid person id" @@ -276,9 +414,9 @@ feature -- Basic operations print ("Enter person id (0 ...back): ") io.read_integer if io.last_integer > 0 then - if persons.valid_index (io.last_integer) then - persons.go_i_th (io.last_integer) - persons.remove + if store.persons.valid_index (io.last_integer) then + store.persons.go_i_th (io.last_integer) + store.persons.remove last_error := "Person (#" + io.last_integer.out + ") removed successfully" else last_error := "Invalid person id" diff --git a/bank-eiffel/bank_store.e b/bank-eiffel/bank_store.e new file mode 100644 index 0000000..acc6f3a --- /dev/null +++ b/bank-eiffel/bank_store.e @@ -0,0 +1,48 @@ +class + BANK_STORE + +inherit + STORABLE + +create + make + +feature + + persons: ARRAYED_SET [PERSON] + + accounts: ARRAYED_SET [ACCOUNT] + + ranges: TUPLE [ + account: attached like account_range; + studentaccount: attached like account_range; + retireeaccount: attached like account_range + ] + +feature {NONE} -- Implementation + + account_range: detachable TUPLE [ + creditline: attached like range; + interest_deposit: attached like range; + interest_debit: attached like range + ] + + range: detachable like {ACCOUNT}.range + +feature {NONE} -- Initialization + + make(cap: INTEGER) + do + create persons.make(cap) + create accounts.make(cap) + create ranges + ranges.account := new_range + ranges.studentaccount := new_range + ranges.retireeaccount := new_range + end + + new_range: attached like account_range + do + create Result + end +end -- cgit v1.2.3 From 2da65ceefaf84437d21e7e4a5697d57af02501d3 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 26 May 2011 17:44:06 +0200 Subject: more bank example stuff last missing: edit account + account operations --- bank-eiffel/bank.e | 567 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 469 insertions(+), 98 deletions(-) (limited to 'bank-eiffel') diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e index f9390c7..523878b 100644 --- a/bank-eiffel/bank.e +++ b/bank-eiffel/bank.e @@ -16,20 +16,23 @@ feature {NONE} -- Implementation data_filename: STRING = "bank.data" + fd: FORMAT_DOUBLE + feature {NONE} -- Initialization run do + create fd.make(2, 2) create store.make(100) - store.ranges.account.creditline := [-1000.0, 0.0] store.ranges.account.interest_deposit := [0.01, 0.04] store.ranges.account.interest_debit := [0.02, 0.1] - store.ranges.studentaccount.creditline := [-300.0, 0.0] + store.ranges.account.creditline := [-1000.0, 0.0] store.ranges.studentaccount.interest_deposit := [0.02, 0.03] store.ranges.studentaccount.interest_debit := [0.03, 0.06] - store.ranges.retireeaccount.creditline := [-300.0, 0.0] + store.ranges.studentaccount.creditline := [-300.0, 0.0] store.ranges.retireeaccount.interest_deposit := [0.02, 0.03] store.ranges.retireeaccount.interest_debit := [0.03, 0.06] + store.ranges.retireeaccount.creditline := [-300.0, 0.0] create last_error.make_empty create data_file.make (data_filename) @@ -63,7 +66,7 @@ feature -- Basic operations print_last_error do if not last_error.is_empty then - print (last_error + "%N%N") + print ("Error: " + last_error + "%N%N") last_error := "" end end @@ -141,7 +144,7 @@ feature -- Basic operations io.read_character io.next_line - inspect io.last_character + inspect io.last_character.lower when 'a' then edit_ranges("account", store.ranges.account) when 's' then @@ -159,16 +162,13 @@ feature -- Basic operations print_ranges(range: like {BANK_STORE}.account_range) do - print (" - Creditline: " + print_range(range.creditline) + "%N") print (" - Interest deposit: " + print_range(range.interest_deposit) + "%N") print (" - Interest debit: " + print_range(range.interest_debit) + "%N") + print (" - Creditline: " + print_range(range.creditline) + "%N") end print_range(range: like {BANK_STORE}.range): STRING_8 - local - fd: FORMAT_DOUBLE do - create fd.make(2, 2) Result := "[" + fd.formatted(range.min) + ", " + fd.formatted(range.max) + "]" end @@ -176,16 +176,13 @@ feature -- Basic operations do print ("%N") print ("Edit " + type + " range:%N") - edit_range("creditline", range.creditline) edit_range("interest depost", range.interest_deposit) edit_range("interest debit", range.interest_debit) + edit_range("creditline", range.creditline) end edit_range(type: STRING_8; range: like {BANK_STORE}.range) - local - fd: FORMAT_DOUBLE do - create fd.make(2, 2) print ("Enter " + type + " minimum [" + fd.formatted(range.min) + "]: ") io.readline if io.last_string.is_double then @@ -220,9 +217,11 @@ feature -- Basic operations io.read_character io.next_line - inspect io.last_character + inspect io.last_character.lower when 'l' then list_persons + print ("Press to go back") + io.read_line when 'c' then create_persons when 'e' then @@ -238,9 +237,161 @@ feature -- Basic operations end end + list_persons + do + print ("%N") + print ("Persons: " + store.persons.count.out + "%N") + from + store.persons.start + until + store.persons.off + loop + print ("#" + store.persons.index.out + " " + store.persons.item.surname + ", " + store.persons.item.firstname) + if attached {RETIREE} store.persons.item then + print (" (RETIREE)") + elseif attached {STUDENT} store.persons.item then + print (" (STUDENT)") + end + print ("%N") + store.persons.forth + end + print ("%N") + end + + create_persons + local + back: BOOLEAN + firstname: STRING + surname: STRING + do + from + until + back + loop + print_header + print ("Operations:%N") + print (" p ...create person%N") + print (" s ...create student%N") + print (" r ...create retiree%N") + print (" b ...back%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character.lower + when 'p', 's', 'r' then + print ("Enter surname: ") + io.readline + surname := io.last_string.twin + + print ("Enter firstname: ") + io.readline + firstname := io.last_string.twin + + inspect io.last_character.lower + when 'p' then + store.persons.put(create {PERSON}.make(surname, firstname)) + when 's' then + store.persons.put(create {STUDENT}.make(surname, firstname)) + when 'r' then + store.persons.put(create {RETIREE}.make(surname, firstname)) + else + end + last_error := "Person (#" + store.persons.count.out + ") created successfully" + back := True + when 'b' then + back := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + rescue + if not (create {EXCEPTIONS}).is_signal then + last_error := "Exception: " + (create {EXCEPTIONS}).tag_name + retry + end + end + + edit_person + local + back: BOOLEAN + num: INTEGER + do + list_persons + from + until + back + loop + print_last_error + print ("Enter person id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + num := io.last_string.to_integer + if store.persons.valid_index (num) then + store.persons.go_i_th (num) + + print ("Enter surname [" + store.persons.item.surname + "]: ") + io.readline + if not io.last_string.is_empty then + store.persons.item.surname := io.last_string.twin + end + + print ("Enter firstname [" + store.persons.item.firstname + "]: ") + io.readline + if not io.last_string.is_empty then + store.persons.item.firstname := io.last_string.twin + end + last_error := "Person (#" + num.out + ") edited successfully" + back := True + else + last_error := "Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Not a number" + end + end + end + + delete_person + local + back: BOOLEAN + do + list_persons + from + until + back + loop + print_last_error + print ("Enter person id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th (io.last_string.to_integer) + store.persons.remove + last_error := "Person (#" + io.last_string + ") removed successfully" + back := True + else + last_error := "Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Not a number" + end + end + end + accounts_screen local back: BOOLEAN + done: BOOLEAN do from until @@ -259,12 +410,42 @@ feature -- Basic operations io.read_character io.next_line - inspect io.last_character + inspect io.last_character.lower when 'l' then list_accounts + + from + done := False + until + back or done + loop + print ("Enter account id for details (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.accounts.valid_index (io.last_string.to_integer) then + store.accounts.go_i_th (io.last_string.to_integer) + print ("%N") + print ("Account #" + store.accounts.index.out + ":%N") + list_account_details(store.accounts.item) + print ("Press to go back") + io.read_line + done := True + else + print ("Invalid account id%N%N") + end + elseif io.last_string.is_equal("b") then + done := True + else + print ("Not a number%N%N") + end + end when 'c' then + create_accounts when 'e' then + edit_accounts when 'd' then + delete_account when 'b' then back := True else @@ -274,62 +455,82 @@ feature -- Basic operations end end - list_persons + list_accounts + local + account: ACCOUNT + person: PERSON do print ("%N") - print ("Persons: " + store.persons.count.out + "%N%N") + print ("Accounts: " + store.accounts.count.out + "%N") from - store.persons.start + store.accounts.start until - store.persons.off + store.accounts.off loop - print ("#" + store.persons.index.out + " " + store.persons.item.surname + ", " + store.persons.item.firstname) - if attached {RETIREE} store.persons.item then - print (" (RETIREE)") - elseif attached {STUDENT} store.persons.item then - print (" (STUDENT)") + account := store.accounts.item + account.get_authorized_signers.linear_representation.start + person := account.get_authorized_signers.linear_representation.item + + print ("#" + store.accounts.index.out + " " + person.surname + ", " + person.firstname) + if attached {RETIREEACCOUNT} account then + print (" (RETIREE ACCOUNT)") + elseif attached {STUDENTACCOUNT} account then + print (" (STUDENT ACCOUNT)") end print ("%N") - store.persons.forth - end + store.accounts.forth + end print ("%N") - print ("Press to go back") - io.read_line end - list_accounts + list_account_details(account: ACCOUNT) + local + person: PERSON + range: like {BANK_STORE}.account_range do - print ("%N") - print ("Accounts: " + store.accounts.count.out + "%N%N") + range := store.ranges.account + if attached {RETIREEACCOUNT} account then + range := store.ranges.retireeaccount + elseif attached {STUDENTACCOUNT} account then + range := store.ranges.studentaccount + end + + print (" - Balance: " + fd.formatted(account.balance) + "%N") + print (" - Interest deposit: " + fd.formatted(account.interest_deposit) + " " + print_range(range.interest_deposit) + "%N") + print (" - Interest debit: " + fd.formatted(account.interest_debit) + " " + print_range(range.interest_debit) +"%N") + print (" - Creditline: " + fd.formatted(account.creditline) + " " + print_range(range.creditline) +"%N") + print (" - Authorized signers:%N") from - store.accounts.start + account.get_authorized_signers.linear_representation.start until - store.accounts.off + account.get_authorized_signers.linear_representation.off loop - --TODO - print ("#" + store.accounts.index.out + "%N") - print (" balance=" + store.accounts.item.balance.out + "%N") - print (" creditline=" + store.accounts.item.creditline.out + "%N") - if attached {RETIREEACCOUNT} store.accounts.item then - print (" (RETIREEACCOUNT)") - elseif attached {STUDENTACCOUNT} store.accounts.item then - print (" (STUDENTACCOUNT)") + person := account.get_authorized_signers.linear_representation.item + print (" - #" + account.get_authorized_signers.linear_representation.index.out + " " + person.surname + ", " + person.firstname) + if attached {RETIREE} person then + print (" (RETIREE)") + elseif attached {STUDENT} person then + print (" (STUDENT)") end print ("%N") - store.accounts.forth + account.get_authorized_signers.linear_representation.forth end - print ("%N") - print ("Press to go back") - io.read_line + print (" - Type: ") + if attached {RETIREEACCOUNT} account then + print ("Retiree account") + elseif attached {STUDENTACCOUNT} account then + print ("Student account") + else + print ("Account") + end + print ("%N%N") end - create_persons + create_accounts local back: BOOLEAN - firstname: STRING - surname: STRING do from until @@ -337,9 +538,9 @@ feature -- Basic operations loop print_header print ("Operations:%N") - print (" p ...create person%N") - print (" s ...create student%N") - print (" r ...create retiree%N") + print (" a ...create account%N") + print (" s ...create student account%N") + print (" r ...create retiree account%N") print (" b ...back%N") print ("%N") print_last_error @@ -347,27 +548,13 @@ feature -- Basic operations io.read_character io.next_line - inspect io.last_character - when 'p', 's', 'r' then - print ("Enter surname: ") - io.readline - surname := io.last_string.twin - - print ("Enter firstname: ") - io.readline - firstname := io.last_string.twin - - inspect io.last_character - when 'p' then - store.persons.put(create {PERSON}.make(surname, firstname)) - when 's' then - store.persons.put(create {STUDENT}.make(surname, firstname)) - when 'r' then - store.persons.put(create {RETIREE}.make(surname, firstname)) - else - end - last_error := "Person (#" + store.persons.count.out + ") created successfully" - back := True + inspect io.last_character.lower + when 'a' then + back := create_account('a', store.ranges.account) + when 's' then + back := create_account('s', store.ranges.studentaccount) + when 'r' then + back := create_account('r', store.ranges.retireeaccount) when 'b' then back := True else @@ -382,44 +569,228 @@ feature -- Basic operations end end - edit_person + create_account(type: CHARACTER; range: like {BANK_STORE}.account_range): BOOLEAN + local + back: BOOLEAN + next: BOOLEAN + interest_deposit: like {ACCOUNT}.interest_deposit + interest_debit: like {ACCOUNT}.interest_debit + creditline: like {ACCOUNT}.creditline do - print ("%N") - print ("Enter person id (0 ...back): ") - io.read_integer - if io.last_integer > 0 then - if store.persons.valid_index (io.last_integer) then - store.persons.go_i_th (io.last_integer) + Result := false + interest_deposit := (range.interest_deposit.min + range.interest_deposit.max) / 2 + interest_debit := (range.interest_debit.min + range.interest_debit.max) / 2 + creditline := (range.creditline.min + range.creditline.max) / 2 - print ("Enter surname [" + store.persons.item.surname + "]: ") - io.readline - if not io.last_string.is_empty then - store.persons.item.surname := io.last_string.twin + print_last_error + from + next := False + list_persons + until + back or next + loop + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th (io.last_string.to_integer) + next := True + else + print ("Invalid person id%N%N") end + elseif io.last_string.is_equal ("b") then + back := True + else + print ("Not a number%N%N") + end + end - print ("Enter firstname [" + store.persons.item.firstname + "]: ") - io.readline - if not io.last_string.is_empty then - store.persons.item.firstname := io.last_string.twin + from + next := False + until + back or next + loop + print ("Enter interest deposit " + print_range(range.interest_deposit) + " [" + fd.formatted(interest_deposit) + "] (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_empty then + next := True + elseif io.last_string.is_double then + interest_deposit := io.last_string.to_double + next := True + elseif io.last_string.is_equal ("b") then + back := True + else + print ("Invalid interest deposit number%N%N") + end + end + + from + next := False + until + back or next + loop + print ("Enter interest debit " + print_range(range.interest_debit) + " [" + fd.formatted(interest_debit) + "] (b ...back):") + io.readline + io.last_string.to_lower + if io.last_string.is_empty then + next := True + elseif io.last_string.is_double then + interest_debit := io.last_string.to_double + next := True + elseif io.last_string.is_equal ("b") then + back := True + else + print ("Invalid interest debit number%N%N") + end + end + + from + next := False + until + back or next + loop + print ("Enter creditline " + print_range(range.creditline) + " [" + fd.formatted(creditline) + "] (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_empty then + next := True + elseif io.last_string.is_double then + creditline := io.last_string.to_double + next := True + elseif io.last_string.is_equal ("b") then + back := True + else + print ("Invalid creditline number%N%N") + end + end + + if not back then + inspect type + when 'a' then + store.accounts.put(create {ACCOUNT}.make(store.persons.item, + interest_deposit, interest_debit, creditline, + range.interest_deposit, range.interest_debit, range.creditline)) + when 's' then + store.accounts.put(create {STUDENTACCOUNT}.make(store.persons.item, + interest_deposit, interest_debit, creditline, + range.interest_deposit, range.interest_debit, range.creditline)) + when 'r' then + store.accounts.put(create {RETIREEACCOUNT}.make(store.persons.item, + interest_deposit, interest_debit, creditline, + range.interest_deposit, range.interest_debit, range.creditline)) + else + end + last_error := "Account (#" + store.accounts.count.out + ") created successfully" + Result := true + back := True + end + end + + edit_accounts + local + back: BOOLEAN + do + list_accounts + from + until + back + loop + print_last_error + print ("Enter account id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.accounts.valid_index (io.last_string.to_integer) then + store.accounts.go_i_th (io.last_string.to_integer) + edit_account(store.accounts.index, store.accounts.item) + back := True + else + last_error := "Invalid account id" end + elseif io.last_string.is_equal ("b") then + back := True else - last_error := "Invalid person id" + last_error := "Not a number" end end end - delete_person + edit_account(index: INTEGER; account: ACCOUNT) + local + back: BOOLEAN do - print ("%N") - print ("Enter person id (0 ...back): ") - io.read_integer - if io.last_integer > 0 then - if store.persons.valid_index (io.last_integer) then - store.persons.go_i_th (io.last_integer) - store.persons.remove - last_error := "Person (#" + io.last_integer.out + ") removed successfully" + from + until + back + loop + print_header + print ("Edit account #" + index.out + ":%N") + list_account_details (account) + + print ("Operations:%N") + print (" 1 ...edit interest deposit%N") + print (" 2 ...edit interest debit%N") + print (" 3 ...edit creditline%N") + print (" 4 ...add authorized signer%N") + print (" 5 ...remove authorized signer%N") + print (" 6 ...deposit%N") + print (" 7 ...withdraw%N") + print (" 8 ...transfer%N") + print (" 9 ...advance%N") + print (" b ...back%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character.lower + when '1' then + when '2' then + when '3' then + when '4' then + when '5' then + when '6' then + when '7' then + when '8' then + when '9' then + when 'b' then + back := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + end + + delete_account + local + back: BOOLEAN + do + list_accounts + from + until + back + loop + print_last_error + print ("Enter account id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.accounts.valid_index (io.last_string.to_integer) then + store.accounts.go_i_th (io.last_string.to_integer) + store.accounts.remove + last_error := "Account (#" + io.last_string + ") removed successfully" + back := True + else + last_error := "Invalid account id" + end + elseif io.last_string.is_equal ("b") then + back := True else - last_error := "Invalid person id" + last_error := "Not a number" end end end -- cgit v1.2.3 From cf31e1f2788869624a9a363f7579838ddae369a2 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 26 May 2011 19:55:22 +0200 Subject: finall commit hopefully --- bank-eiffel/account.e | 13 +- bank-eiffel/bank.e | 387 +++++++++++++++++++++++++++++++++++++++---- bank-eiffel/retireeaccount.e | 13 +- bank-eiffel/studentaccount.e | 13 +- 4 files changed, 388 insertions(+), 38 deletions(-) (limited to 'bank-eiffel') diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index fe9cc3b..a6e30ef 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -81,16 +81,19 @@ feature -- Basic operations require an_authorized_signer_authorized: get_authorized_signers.has (an_authorized_signer) transfer_minamount_ok: an_amount >= transfer_minamount + balance_beneath_creditline: balance - an_amount >= creditline do balance := balance - an_amount ensure + balance_beneath_creditline: balance >= creditline balance_decreased: balance < old balance withdrawed: balance = old balance - an_amount - balance_beneath_creditline: balance >= creditline end transfer(an_amount: like transfer_minamount; an_authorized_signer: PERSON; an_account: like Current; another_authorized_signer: PERSON) + require + recipient_account_not_same: Current /= an_account do withdraw (an_amount, an_authorized_signer) an_account.deposit (an_amount, another_authorized_signer) @@ -107,12 +110,10 @@ feature -- Basic operations remove_authorized_signer (an_authorized_signer: PERSON) require - authorized_signers_never_empty: (get_authorized_signers.has (an_authorized_signer) - and get_authorized_signers.count >= 2) or True + authorized_signer_exists: (get_authorized_signers.has (an_authorized_signer)) + authorized_signers_not_empty: get_authorized_signers.count >= 2 do - if authorized_signers.has (an_authorized_signer) then - authorized_signers.prune (an_authorized_signer) - end + authorized_signers.prune (an_authorized_signer) ensure authorized_signers_assigned: not authorized_signers.has (an_authorized_signer) end diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e index 523878b..223f60f 100644 --- a/bank-eiffel/bank.e +++ b/bank-eiffel/bank.e @@ -66,7 +66,7 @@ feature -- Basic operations print_last_error do if not last_error.is_empty then - print ("Error: " + last_error + "%N%N") + print (last_error + "%N%N") last_error := "" end end @@ -182,17 +182,41 @@ feature -- Basic operations end edit_range(type: STRING_8; range: like {BANK_STORE}.range) + local + back: BOOLEAN do - print ("Enter " + type + " minimum [" + fd.formatted(range.min) + "]: ") - io.readline - if io.last_string.is_double then - range.min := io.last_string.to_double + from + back := False + until + back + loop + print ("Enter " + type + " minimum [" + fd.formatted(range.min) + "]: ") + io.readline + if io.last_string.is_double then + range.min := io.last_string.to_double + back := True + elseif io.last_string.is_empty then + back := True + else + print ("Invalid value%N") + end end - print ("Enter " + type + " maximum [" + fd.formatted(range.max) + "]: ") - io.readline - if io.last_string.is_double then - range.max := io.last_string.to_double + from + back := False + until + back + loop + print ("Enter " + type + " maximum [" + fd.formatted(range.max) + "]: ") + io.readline + if io.last_string.is_double then + range.max := io.last_string.to_double + back := True + elseif io.last_string.is_empty then + back := True + else + print ("Invalid value%N") + end end end @@ -348,12 +372,12 @@ feature -- Basic operations last_error := "Person (#" + num.out + ") edited successfully" back := True else - last_error := "Invalid person id" + last_error := "Error: Invalid person id" end elseif io.last_string.is_equal ("b") then back := True else - last_error := "Not a number" + last_error := "Error: Not a number" end end end @@ -378,12 +402,12 @@ feature -- Basic operations last_error := "Person (#" + io.last_string + ") removed successfully" back := True else - last_error := "Invalid person id" + last_error := "Error: Invalid person id" end elseif io.last_string.is_equal ("b") then back := True else - last_error := "Not a number" + last_error := "Error: Not a number" end end end @@ -432,12 +456,12 @@ feature -- Basic operations io.read_line done := True else - print ("Invalid account id%N%N") + print ("Error: Invalid account id%N%N") end elseif io.last_string.is_equal("b") then done := True else - print ("Not a number%N%N") + print ("Error: Not a number%N%N") end end when 'c' then @@ -500,6 +524,7 @@ feature -- Basic operations print (" - Interest deposit: " + fd.formatted(account.interest_deposit) + " " + print_range(range.interest_deposit) + "%N") print (" - Interest debit: " + fd.formatted(account.interest_debit) + " " + print_range(range.interest_debit) +"%N") print (" - Creditline: " + fd.formatted(account.creditline) + " " + print_range(range.creditline) +"%N") + print (" - Minimum transfer amount: " + fd.formatted(account.transfer_minamount) +"%N") print (" - Authorized signers:%N") from account.get_authorized_signers.linear_representation.start @@ -597,12 +622,12 @@ feature -- Basic operations store.persons.go_i_th (io.last_string.to_integer) next := True else - print ("Invalid person id%N%N") + print ("Error: Invalid person id%N%N") end elseif io.last_string.is_equal ("b") then back := True else - print ("Not a number%N%N") + print ("Error: Not a number%N%N") end end @@ -622,7 +647,7 @@ feature -- Basic operations elseif io.last_string.is_equal ("b") then back := True else - print ("Invalid interest deposit number%N%N") + print ("Error: Invalid interest deposit number%N%N") end end @@ -642,7 +667,7 @@ feature -- Basic operations elseif io.last_string.is_equal ("b") then back := True else - print ("Invalid interest debit number%N%N") + print ("Error: Invalid interest debit number%N%N") end end @@ -662,7 +687,7 @@ feature -- Basic operations elseif io.last_string.is_equal ("b") then back := True else - print ("Invalid creditline number%N%N") + print ("Error: Invalid creditline number%N%N") end end @@ -707,12 +732,12 @@ feature -- Basic operations edit_account(store.accounts.index, store.accounts.item) back := True else - last_error := "Invalid account id" + last_error := "Error: Invalid account id" end elseif io.last_string.is_equal ("b") then back := True else - last_error := "Not a number" + last_error := "Error: Not a number" end end end @@ -733,12 +758,13 @@ feature -- Basic operations print (" 1 ...edit interest deposit%N") print (" 2 ...edit interest debit%N") print (" 3 ...edit creditline%N") - print (" 4 ...add authorized signer%N") - print (" 5 ...remove authorized signer%N") - print (" 6 ...deposit%N") - print (" 7 ...withdraw%N") - print (" 8 ...transfer%N") - print (" 9 ...advance%N") + print (" 4 ...edit minimum transfer amount%N") + print (" 5 ...add authorized signer%N") + print (" 6 ...remove authorized signer%N") + print (" 7 ...deposit%N") + print (" 8 ...withdraw%N") + print (" 9 ...transfer%N") + print (" 0 ...advance%N") print (" b ...back%N") print ("%N") print_last_error @@ -748,14 +774,40 @@ feature -- Basic operations inspect io.last_character.lower when '1' then + account.interest_deposit := edit_account_detail_double("interest deposit", account.interest_deposit) + last_error := "Interest deposit changed successfully" when '2' then + account.interest_debit := edit_account_detail_double("interest debit", account.interest_debit) + last_error := "Interest debit changed successfully" when '3' then + account.creditline := edit_account_detail_double("creditline", account.creditline) + last_error := "Creditline changed successfully" when '4' then + account.transfer_minamount := edit_account_detail_double("transfer miniumum amount", account.transfer_minamount) + last_error := "Transfer minimum amount changed successfully" when '5' then + if edit_account_add_asigner (account) then + last_error := "Authorized signer added successfully" + end when '6' then + if edit_account_remove_asigner (account) then + last_error := "Authorized signer removed successfully" + end when '7' then + if edit_account_deposit (account) then + last_error := "Deposit successfully" + end when '8' then + if edit_account_withdraw (account) then + last_error := "Widthdraw successfully" + end when '9' then + if edit_account_transfer (account) then + last_error := "Transfer successfully" + end + when '0' then + account.advance + last_error := "Account advanced successfully" when 'b' then back := True else @@ -763,6 +815,281 @@ feature -- Basic operations end print ("%N%N") end + rescue + if not (create {EXCEPTIONS}).is_signal then + last_error := "Exception: " + (create {EXCEPTIONS}).tag_name + retry + end + end + + edit_account_detail_double(type: STRING_8; val: REAL_64): REAL_64 + local + back: BOOLEAN + do + Result := val + from + until + back + loop + print ("Enter " + type + " [" + fd.formatted(val) + "]: ") + io.readline + if io.last_string.is_double then + Result := io.last_string.to_double + back := True + elseif io.last_string.is_empty then + back := True + else + print ("Error: Invalid value%N") + end + end + end + + edit_account_add_asigner(account: ACCOUNT): BOOLEAN + local + back: BOOLEAN + do + Result := False + from + list_persons + until + back + loop + print_last_error + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + account.add_authorized_signer (store.persons.item) + Result := True + back := True + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + end + + edit_account_remove_asigner(account: ACCOUNT): BOOLEAN + local + back: BOOLEAN + do + Result := False + from + list_persons + until + back + loop + print_last_error + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + account.remove_authorized_signer (store.persons.item) + Result := True + back := True + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + end + + edit_account_deposit(account: ACCOUNT): BOOLEAN + local + back: BOOLEAN + amount: like {ACCOUNT}.balance + do + Result := False + from + until + back + loop + print_last_error + + if amount = 0.0 and last_error.is_empty and not back then + print ("Enter deposit amount (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_double and io.last_string.to_double > 0.0 then + amount := io.last_string.to_double + elseif io.last_string.is_equal("b") then + back := True + else + last_error := "Error: Invalid value" + end + end + + if last_error.is_empty and not back then + list_persons + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + account.deposit (amount, store.persons.item) + Result := True + back := True + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + end + end + + edit_account_withdraw(account: ACCOUNT): BOOLEAN + local + back: BOOLEAN + amount: like {ACCOUNT}.balance + do + Result := False + from + until + back + loop + print_last_error + + if amount = 0.0 and last_error.is_empty and not back then + print ("Enter withdraw amount (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_double and io.last_string.to_double > 0.0 then + amount := io.last_string.to_double + elseif io.last_string.is_equal("b") then + back := True + else + last_error := "Error: Invalid value" + end + end + + if last_error.is_empty and not back then + list_persons + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + account.withdraw (amount, store.persons.item) + Result := True + back := True + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + end + end + + edit_account_transfer(account: ACCOUNT): BOOLEAN + local + back: BOOLEAN + amount: like {ACCOUNT}.balance + signer: PERSON + recipient: ACCOUNT + do + Result := False + from + until + back + loop + print_last_error + + if amount = 0.0 and last_error.is_empty and not back then + print ("Enter transfer amount (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_double and io.last_string.to_double > 0.0 then + amount := io.last_string.to_double + elseif io.last_string.is_equal("b") then + back := True + else + last_error := "Error: Invalid value" + end + end + + print (signer) + if signer = Void and last_error.is_empty and not back then + list_persons + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + signer := store.persons.item + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + + print (recipient) + if recipient = Void and last_error.is_empty and not back then + list_accounts + print ("Enter recipient account id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.accounts.valid_index (io.last_string.to_integer) then + store.accounts.go_i_th(io.last_string.to_integer) + recipient := store.accounts.item + else + last_error := "Error: Invalid account id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + + if last_error.is_empty and not back then + list_persons + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + account.transfer (amount, signer, recipient, store.persons.item) + Result := True + back := True + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + end end delete_account @@ -785,12 +1112,12 @@ feature -- Basic operations last_error := "Account (#" + io.last_string + ") removed successfully" back := True else - last_error := "Invalid account id" + last_error := "Error: Invalid account id" end elseif io.last_string.is_equal ("b") then back := True else - last_error := "Not a number" + last_error := "Error: Not a number" end end end diff --git a/bank-eiffel/retireeaccount.e b/bank-eiffel/retireeaccount.e index 3db0cd4..24ae004 100644 --- a/bank-eiffel/retireeaccount.e +++ b/bank-eiffel/retireeaccount.e @@ -4,12 +4,23 @@ class inherit ACCOUNT redefine + add_authorized_signer, set_default_transfer_minamount end - + create make +feature -- Basic operations + + add_authorized_signer (an_authorized_signer: PERSON) + do + check + authorized_signers_only_one: get_authorized_signers.count = 0 + end + Precursor (an_authorized_signer) + end + feature {NONE} -- Implementation set_default_transfer_minamount diff --git a/bank-eiffel/studentaccount.e b/bank-eiffel/studentaccount.e index 04a9e31..abbb070 100644 --- a/bank-eiffel/studentaccount.e +++ b/bank-eiffel/studentaccount.e @@ -4,12 +4,23 @@ class inherit ACCOUNT redefine - set_default_transfer_minamount + set_default_transfer_minamount, + add_authorized_signer end create make +feature -- Basic operations + + add_authorized_signer (an_authorized_signer: PERSON) + do + check + authorized_signers_only_one: get_authorized_signers.count = 0 + end + Precursor (an_authorized_signer) + end + feature {NONE} -- Implementation set_default_transfer_minamount -- cgit v1.2.3