#include #include #include #include #include #include "Currency.h" #include "BankAccount.h" #include "Bill.h" #include "CashFactory.h" #include "Bank.h" std::default_random_engine generator(static_cast(time(nullptr))); std::uniform_int_distribution distribution(-100, 500); std::string currency_to_string(CurrencyValue value) { if (value == CurrencyValue::USD) return "US Dollar"; if (value == CurrencyValue::EUR) return "Euro"; if (value == CurrencyValue::GPD) return "British Pound"; return "Say what ?"; } std::ostream &operator<<(std::ostream &os, Currency currency) { os << currency_to_string(currency.getValue()); return os; } std::ostream &operator<<(std::ostream &os, std::shared_ptr const& bill) { os << bill->getValue() << " " << bill->getCurrency() << " " << bill->getSerial(); return os; } std::ostream &operator<<(std::ostream &os, std::shared_ptr const& cash) { os << cash->getValue() << " " << cash->getCurrency(); return os; } std::ostream &operator<<(std::ostream &os, std::shared_ptr const& money) { os << money->getValue() << " " << money->getCurrency(); return os; } std::ostream &operator<<(std::ostream &os, std::shared_ptr const& person) { os << person->getName(); return os; } std::ostream &operator<<(std::ostream &os, BankAccount* bankAccount) { os << bankAccount->getName() << " " << ": " << bankAccount->getMoney(); return os; } std::set> banks; std::set> owners; CashFactory *cashFactory; void setup() { //FIXME: das hier könnte das Problem sein // http://www.cplusplus.com/forum/beginner/74320/ std::shared_ptr bank1 = std::make_shared(new Bank("Bank 1")); std::shared_ptr bank2 = std::make_shared(new Bank("Bank 2")); std::shared_ptr bank3 = std::make_shared(new Bank("Bank 3")); std::shared_ptr max = std::make_shared(new Person("Max Müller")); std::shared_ptr marius = std::make_shared(new Person("Marius Müller")); std::shared_ptr alex = std::make_shared(new Person("Alex Maier")); owners.insert(max); owners.insert(marius); owners.insert(alex); bank1->addAccount(std::make_shared(new BankAccount(max, "Konto 1"))); bank2->addAccount(std::make_shared(new BankAccount(max, "Konto 2"))); bank3->addAccount(std::make_shared(new BankAccount(alex, "privat"))); bank1->addAccount(std::make_shared(new BankAccount(alex, "geschäftlich 1"))); bank2->addAccount(std::make_shared(new BankAccount(alex, "geschäftlich 2"))); bank3->addAccount(std::make_shared(new BankAccount(alex, "geschäftlich 3"))); bank1->addAccount(std::make_shared(new BankAccount(marius, "Konto 1"))); bank2->addAccount(std::make_shared(new BankAccount(marius, "Konto 2"))); bank3->addAccount(std::make_shared(new BankAccount(marius, "Konto 3"))); banks.insert(std::move(bank1)); banks.insert(std::move(bank2)); banks.insert(std::move(bank3)); cashFactory = new CashFactory(); } void simulate() { for(auto && bank : banks) { std::cout << std::endl; std::cout << "======================== " << bank->getName() << " ========================" << std::endl; std::cout << std::endl; for(auto && bankAccount : bank->getAccounts()) { for (int i = 0; i < 10000; ++i) { int rnd = distribution(generator); std::cout << rnd << std::endl; std::shared_ptr bill = cashFactory->printBill(rnd, CurrencyValue::USD); std::shared_ptr coin = cashFactory->printCoin(rnd, CurrencyValue::USD); if (bill != nullptr) { bankAccount->operator+(bill); } if (coin != nullptr) { bankAccount->operator+(coin); } std::shared_ptr fee = bankAccount->operator-(10); } std::cout << "Test2" << std::endl; std::cout << bankAccount.get() << std::endl; } } } void tearDown() { } int main(int argc, char **argv) { std::cout << "+++++++++++++++++++++++++ " << "setup()" << " +++++++++++++++++++++++++" << std::endl; setup(); std::cout << "+++++++++++++++++++++++++ " << "simulate()" << " +++++++++++++++++++++++++" << std::endl; simulate(); std::cout << "+++++++++++++++++++++++++ " << "tearDown()" << " +++++++++++++++++++++++++" << std::endl; tearDown(); HeapObject::assertionsHold(); return 0; }