tests.cpp
1 // ************************************************************************** // 2 // // 3 // tests.cpp for GlobalBanksters United // 4 // Created on : Thu Nov 20 23:45:02 1989 // 5 // Last update : Wed Jan 04 09:23:52 1992 // 6 // Made by : Brad "Buddy" McLane <bm@gbu.com> // 7 // // 8 // ************************************************************************** // 9 10 #include <vector> 11 #include <algorithm> 12 #include <functional> 13 #include "Account.hpp" 14 15 16 int main( void ) { 17 18 typedef std::vector<Account::t> accounts_t; 19 typedef std::vector<int> ints_t; 20 typedef std::pair<accounts_t::iterator, ints_t::iterator> acc_int_t; 21 22 int const amounts[] = { 42, 54, 957, 432, 1234, 0, 754, 16576 }; 23 size_t const amounts_size( sizeof(amounts) / sizeof(int) ); 24 accounts_t accounts( amounts, amounts + amounts_size ); 25 accounts_t::iterator acc_begin = accounts.begin(); 26 accounts_t::iterator acc_end = accounts.end(); 27 28 int const d[] = { 5, 765, 564, 2, 87, 23, 9, 20 }; 29 size_t const d_size( sizeof(d) / sizeof(int) ); 30 ints_t deposits( d, d + d_size ); 31 ints_t::iterator dep_begin = deposits.begin(); 32 ints_t::iterator dep_end = deposits.end(); 33 34 int const w[] = { 321, 34, 657, 4, 76, 275, 657, 7654 }; 35 size_t const w_size( sizeof(w) / sizeof(int) ); 36 ints_t withdrawals( w, w + w_size ); 37 ints_t::iterator wit_begin = withdrawals.begin(); 38 ints_t::iterator wit_end = withdrawals.end(); 39 40 Account::displayAccountsInfos(); 41 std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) ); 42 43 for ( acc_int_t it( acc_begin, dep_begin ); 44 it.first != acc_end && it.second != dep_end; 45 ++(it.first), ++(it.second) ) { 46 47 (*(it.first)).makeDeposit( *(it.second) ); 48 } 49 50 Account::displayAccountsInfos(); 51 std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) ); 52 53 for ( acc_int_t it( acc_begin, wit_begin ); 54 it.first != acc_end && it.second != wit_end; 55 ++(it.first), ++(it.second) ) { 56 57 (*(it.first)).makeWithdrawal( *(it.second) ); 58 } 59 60 Account::displayAccountsInfos(); 61 std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) ); 62 63 return 0; 64 } 65 66 67 // ************************************************************************** // 68 // vim: set ts=4 sw=4 tw=80 noexpandtab: // 69 // -*- indent-tabs-mode:t; -*- 70 // -*- mode: c++-mode; -*- 71 // -*- fill-column: 75; comment-column: 75; -*- 72 // ************************************************************************** //