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(-) 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