10_PITF: weniger Fehlermeldungen
This commit is contained in:
parent
86ba4d1500
commit
5d1a567415
@ -10,11 +10,11 @@ BankAccount::BankAccount(std::shared_ptr<Person> owner, std::string name) : name
|
||||
}
|
||||
|
||||
std::unique_ptr<BankAccount> BankAccount::operator+(Money* money) {
|
||||
std::unique_ptr<Money> ptr = std::make_unique<Money>(new Money(money->getValue() + getMoney()->getValue(), money->getCurrency()));
|
||||
std::unique_ptr<Money> ptr = std::make_unique<Money>(Money(money->getValue() + getMoney()->getValue(), money->getCurrency()));
|
||||
|
||||
BankAccount::money.swap(ptr);
|
||||
ptr.release();
|
||||
return std::make_unique<BankAccount>(this);
|
||||
|
||||
return std::make_unique<BankAccount>(*this);
|
||||
}
|
||||
|
||||
std::unique_ptr<Money> BankAccount::operator-(int value) {
|
||||
@ -26,6 +26,3 @@ std::unique_ptr<Money> BankAccount::operator-(int value) {
|
||||
bool BankAccount::operator<(std::unique_ptr<BankAccount> bankAccount) {
|
||||
return money->getValue() < bankAccount->getMoney()->getValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -4,38 +4,32 @@ Money::Money(int value, Currency currency) : value(value), currency(currency) {
|
||||
|
||||
}
|
||||
|
||||
Money& Money::operator=(Money money) {
|
||||
std::unique_ptr<Money> Money::operator=(Money money) {
|
||||
value = money.getValue();
|
||||
currency = money.getCurrency();
|
||||
return *this;
|
||||
return std::make_unique<Money>(*this);
|
||||
}
|
||||
|
||||
Money &Money::operator=(Money *money) {
|
||||
value = money->getValue();
|
||||
currency = money->getCurrency();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Money Money::operator+(Money &a) {
|
||||
std::unique_ptr<Money> Money::operator+(Money &a) {
|
||||
if(currency == a.currency) {
|
||||
return Money(value + a.value);
|
||||
}else return Money(-1, Currency(CurrencyValue::USD));
|
||||
return std::make_unique<Money>(Money(value + a.value));
|
||||
}else return std::make_unique<Money>(Money(-1, Currency(CurrencyValue::USD)));
|
||||
}
|
||||
|
||||
Money Money::operator-(Money &a) {
|
||||
std::unique_ptr<Money> Money::operator-(Money &a) {
|
||||
if(currency == a.currency) {
|
||||
return Money(value - a.value);
|
||||
}else return Money(-1, Currency(CurrencyValue::USD));
|
||||
return std::make_unique<Money>(Money(value - a.value));
|
||||
}else return std::make_unique<Money>(Money(-1, Currency(CurrencyValue::USD)));
|
||||
}
|
||||
|
||||
const std::unique_ptr<Money> Money::operator++(int) {
|
||||
value++;
|
||||
return std::make_unique<Money>(this);
|
||||
return std::make_unique<Money>(*this);
|
||||
}
|
||||
|
||||
const std::unique_ptr<Money> Money::operator--(int) {
|
||||
value--;
|
||||
return std::make_unique<Money>(this);
|
||||
return std::make_unique<Money>(*this);
|
||||
}
|
||||
|
||||
int Money::getValue() {
|
||||
@ -45,21 +39,3 @@ int Money::getValue() {
|
||||
Currency Money::getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
std::unique_ptr<Money> Money::operator+(std::unique_ptr<Money> &a) {
|
||||
if(currency == a->getCurrency()) {
|
||||
return std::make_unique<Money>(Money(value + a->getValue()));
|
||||
}else return std::make_unique<Money>(Money(-1, Currency(CurrencyValue::USD)));
|
||||
}
|
||||
|
||||
std::unique_ptr<Money> Money::operator-(std::unique_ptr<Money> &a) {
|
||||
if(currency == a->getCurrency()) {
|
||||
return std::make_unique<Money>(Money(value - a->getValue()));
|
||||
}else return std::make_unique<Money>(Money(-1, Currency(CurrencyValue::USD)));
|
||||
}
|
||||
|
||||
std::unique_ptr<Money> Money::operator=(std::unique_ptr<Money> money) {
|
||||
value = money->getValue();
|
||||
currency = money->getCurrency();
|
||||
return std::make_unique<Money>(Money(value, currency));
|
||||
}
|
||||
|
@ -12,9 +12,8 @@ private:
|
||||
public:
|
||||
explicit Money(int value = 0, Currency currency = CurrencyValue::USD);
|
||||
std::unique_ptr<Money> operator=(Money money);
|
||||
std::unique_ptr<Money> operator=(std::unique_ptr<Money> money);
|
||||
std::unique_ptr<Money> operator+(std::unique_ptr<Money> &a);
|
||||
std::unique_ptr<Money> operator-(std::unique_ptr<Money> &a);
|
||||
std::unique_ptr<Money> operator+(Money &a);
|
||||
std::unique_ptr<Money> operator-(Money &a);
|
||||
const std::unique_ptr<Money> operator++(int);
|
||||
const std::unique_ptr<Money> operator--(int);
|
||||
|
||||
|
@ -55,81 +55,63 @@ CashFactory *cashFactory;
|
||||
|
||||
void setup() {
|
||||
|
||||
std::unique_ptr<Bank> bank1 = std::make_unique<Bank>(Bank("Bank 1"));
|
||||
std::unique_ptr<Bank> bank2 = std::make_unique<Bank>(Bank("Bank 2"));
|
||||
std::unique_ptr<Bank> bank3 = std::make_unique<Bank>(Bank("Bank 3"));
|
||||
|
||||
std::unique_ptr<Bank> bank1 = std::make_unique<Bank>(new Bank("Bank 1"));
|
||||
std::unique_ptr<Bank> bank2 = std::make_unique<Bank>(new Bank("Bank 2"));
|
||||
std::unique_ptr<Bank> bank3 = std::make_unique<Bank>(new Bank("Bank 3"));
|
||||
|
||||
std::shared_ptr<Person> max = std::make_shared<Person>(new Person("Max Müller"));
|
||||
std::shared_ptr<Person> marius = std::make_shared<Person>(new Person("Marius Müller"));
|
||||
std::shared_ptr<Person> alex = std::make_shared<Person>(new Person("Alex Maier"));
|
||||
std::shared_ptr<Person> max = std::make_shared<Person>(Person("Max Müller"));
|
||||
std::shared_ptr<Person> marius = std::make_shared<Person>(Person("Marius Müller"));
|
||||
std::shared_ptr<Person> alex = std::make_shared<Person>(Person("Alex Maier"));
|
||||
|
||||
owners.insert(max);
|
||||
owners.insert(marius);
|
||||
owners.insert(alex);
|
||||
|
||||
|
||||
bank1->addAccount(std::make_unique<BankAccount>(new BankAccount(max, "Konto 1")));
|
||||
bank2->addAccount(std::make_unique<BankAccount>(new BankAccount(max, "Konto 2")));
|
||||
bank1->addAccount(std::make_unique<BankAccount>(new BankAccount(alex, "privat")));
|
||||
bank3->addAccount(std::make_unique<BankAccount>(new BankAccount(alex, "geschäftlich 1")));
|
||||
bank2->addAccount(std::make_unique<BankAccount>(new BankAccount(alex, "geschäftlich 2")));
|
||||
bank1->addAccount(std::make_unique<BankAccount>(new BankAccount(alex, "geschäftlich 3")));
|
||||
bank2->addAccount(std::make_unique<BankAccount>(new BankAccount(marius, "Konto 1")));
|
||||
bank1->addAccount(std::make_unique<BankAccount>(new BankAccount(marius, "Konto 2")));
|
||||
bank3->addAccount(std::make_unique<BankAccount>(new BankAccount(marius, "Konto 3")));
|
||||
bank1->addAccount(std::make_unique<BankAccount>(BankAccount(max, "Konto 1")));
|
||||
bank2->addAccount(std::make_unique<BankAccount>(BankAccount(max, "Konto 2")));
|
||||
bank3->addAccount(std::make_unique<BankAccount>(BankAccount(alex, "privat")));
|
||||
bank1->addAccount(std::make_unique<BankAccount>(BankAccount(alex, "geschäftlich 1")));
|
||||
bank2->addAccount(std::make_unique<BankAccount>(BankAccount(alex, "geschäftlich 2")));
|
||||
bank3->addAccount(std::make_unique<BankAccount>(BankAccount(alex, "geschäftlich 3")));
|
||||
bank1->addAccount(std::make_unique<BankAccount>(BankAccount(marius, "Konto 1")));
|
||||
bank2->addAccount(std::make_unique<BankAccount>(BankAccount(marius, "Konto 2")));
|
||||
bank3->addAccount(std::make_unique<BankAccount>(BankAccount(marius, "Konto 3")));
|
||||
|
||||
banks.insert(bank1);
|
||||
banks.insert(bank2);
|
||||
banks.insert(bank3);
|
||||
banks.insert(std::move(bank1));
|
||||
banks.insert(std::move(bank2));
|
||||
banks.insert(std::move(bank3));
|
||||
|
||||
cashFactory = new CashFactory();
|
||||
}
|
||||
|
||||
void forBankAccount(std::unique_ptr<BankAccount> bankAccount) {
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
int rnd = distribution(generator);
|
||||
std::unique_ptr<Bill> bill = cashFactory->printBill(rnd, CurrencyValue::USD);
|
||||
std::unique_ptr<Coin> coin = cashFactory->printCoin(rnd, CurrencyValue::USD);
|
||||
if (bill != nullptr) {
|
||||
bankAccount->operator+(bill.get());
|
||||
}
|
||||
if (coin != nullptr) {
|
||||
bankAccount->operator+(coin.get());
|
||||
}
|
||||
|
||||
std::unique_ptr<Money> fee = bankAccount->operator-(10);
|
||||
}
|
||||
std::cout << bankAccount.get() << std::endl;
|
||||
}
|
||||
|
||||
void forBank(std::unique_ptr<Bank> bank) {
|
||||
std::cout << std::endl;
|
||||
std::cout << "======================== " << bank->getName() << " ========================" << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::set<std::unique_ptr<BankAccount>> bankAccounts = bank->getAccounts();
|
||||
|
||||
std::for_each(bankAccounts.begin(), bankAccounts.end(), forBankAccount);
|
||||
|
||||
}
|
||||
|
||||
void simulate() {
|
||||
std::for_each(banks.begin(), banks.end(), forBank);
|
||||
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::unique_ptr<Bill> bill = cashFactory->printBill(rnd, CurrencyValue::USD);
|
||||
std::unique_ptr<Coin> coin = cashFactory->printCoin(rnd, CurrencyValue::USD);
|
||||
if (bill != nullptr) {
|
||||
bankAccount->operator+(bill.get());
|
||||
}
|
||||
if (coin != nullptr) {
|
||||
bankAccount->operator+(coin.get());
|
||||
}
|
||||
|
||||
std::unique_ptr<Money> fee = bankAccount->operator-(10);
|
||||
}
|
||||
std::cout << bankAccount.get() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void tearDown() {
|
||||
std::for_each(banks.begin(), banks.end(), [] (std::unique_ptr<Bank> bank) {
|
||||
std::set<std::unique_ptr<BankAccount>> bankAccounts = bank->getAccounts();
|
||||
std::for_each(bankAccounts.begin(), bankAccounts.end(), [] (std::unique_ptr<BankAccount> bankAccount){
|
||||
*bankAccount.release();
|
||||
});
|
||||
*bank.release();
|
||||
});
|
||||
|
||||
std::for_each(owners.begin(), owners.end(), [] (std::shared_ptr<Person> person) {
|
||||
*person.release();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user