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/tests/test_account.e | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'bank-eiffel/tests') 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.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/tests') 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.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/tests') 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.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/tests') 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.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/tests') 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.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/tests') 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.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/tests') 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.3