10_PITF: Assertions behoben

This commit is contained in:
Johannes Theiner 2019-01-04 19:48:05 +01:00
parent e81be0cf84
commit 9b5e4fb7bf
7 changed files with 38 additions and 15 deletions

View File

@ -1,3 +1 @@
<img src="https://teamcity.joethei.xyz/app/rest/builds/aggregated/strob:(branch:(buildType:(id:Studium_Programmierung_CC),policy:active_history_and_active_vcs_branches),locator:(buildType:(id:Studium_Programmierung_CC)))/statusIcon.svg"> <img src="https://teamcity.joethei.xyz/app/rest/builds/aggregated/strob:(branch:(buildType:(id:Studium_Programmierung_CC),policy:active_history_and_active_vcs_branches),locator:(buildType:(id:Studium_Programmierung_CC)))/statusIcon.svg">
[Dokumentation](https://files.joethei.space/documentation/Studium/C_CPP/)

View File

@ -1,5 +1,6 @@
#include <utility> #include <utility>
#include <set> #include <set>
#include <iostream>
#include "Bank.h" #include "Bank.h"
@ -11,6 +12,11 @@ void Bank::addAccount(BankAccount * account) {
accounts.insert(std::move(std::make_unique<BankAccount>(account))); accounts.insert(std::move(std::make_unique<BankAccount>(account)));
} }
void Bank::moveMoney(std::shared_ptr<Bank> bank, int amount) {
money -= amount;
bank->money -= amount;
}
std::set<std::shared_ptr<BankAccount>> Bank::getAccounts() { std::set<std::shared_ptr<BankAccount>> Bank::getAccounts() {
return accounts; return accounts;
} }

View File

@ -13,6 +13,7 @@ public:
explicit Bank(std::string name); explicit Bank(std::string name);
explicit Bank(Bank* bank); explicit Bank(Bank* bank);
void addAccount(BankAccount * account); void addAccount(BankAccount * account);
void moveMoney(std::shared_ptr<Bank> bank, int amount);
std::set<std::shared_ptr<BankAccount>> getAccounts(); std::set<std::shared_ptr<BankAccount>> getAccounts();
std::string getName(); std::string getName();
}; };

View File

@ -2,6 +2,7 @@
#include <utility> #include <utility>
#include <random> #include <random>
#include <ctime>
#include "BankAccount.h" #include "BankAccount.h"
#include "CashFactory.h" #include "CashFactory.h"

View File

@ -3,6 +3,4 @@
#include "Cash.h" #include "Cash.h"
Cash::Cash(int value, Currency currency) : Money(value, currency) { Cash::Cash(int value, Currency currency) : Money(value, currency) {}
}

View File

@ -12,6 +12,9 @@ void* HeapObject::operator new (size_t size){
return new char[size]; return new char[size];
} }
HeapObject::HeapObject(){ HeapObject::HeapObject(){
ctorCount++; ctorCount++;
} }
@ -22,6 +25,7 @@ HeapObject::~HeapObject(){
bool HeapObject::assertionsHold(){ bool HeapObject::assertionsHold(){
//assert(ctorCount == newCount); // all objects have been allocated on heap //assert(ctorCount == newCount); // all objects have been allocated on heap
std::cout << ctorCount << " : " << dtorCount << std::endl;
assert(ctorCount == dtorCount); // all objects have been deleted assert(ctorCount == dtorCount); // all objects have been deleted
return true; return true;
} }

View File

@ -89,21 +89,34 @@ void simulate() {
std::shared_ptr<Bill> bill = cashFactory->printBill(rnd, CurrencyValue::USD); std::shared_ptr<Bill> bill = cashFactory->printBill(rnd, CurrencyValue::USD);
std::shared_ptr<Coin> coin = cashFactory->printCoin(rnd, CurrencyValue::USD); std::shared_ptr<Coin> coin = cashFactory->printCoin(rnd, CurrencyValue::USD);
if (bill != nullptr) { if (bill != nullptr) {
*bankAccount + bill.get(); //*bankAccount + bill.get();
moneyVector.push_back(std::static_pointer_cast<Money, Bill>(bill)); moneyVector.push_back(std::static_pointer_cast<Money, Bill>(bill));
} }
if (coin != nullptr) { if (coin != nullptr) {
*bankAccount + coin.get(); //*bankAccount + coin.get();
moneyVector.push_back(std::static_pointer_cast<Money, Coin>(coin)); moneyVector.push_back(std::static_pointer_cast<Money, Coin>(coin));
} }
Money *fee = *bankAccount - 10; Money *fee = *bankAccount - 10;
delete fee;
} }
//FIXME: Das hier mag er nicht
// std::cout << bankAccount->getOwner()->getName();
std::cout << bankAccount->getName() << ": "; std::cout << bankAccount->getName() << ": ";
std::cout << bankAccount->getMoney()->getValue() << " "; /*
std::cout << bankAccount->getMoney()->getCurrency().getValue() << std::endl; * FIXME: Das hier mag er nicht
* std::cout << bankAccount->getMoney()->getValue() << " ";
* std::cout << bankAccount->getMoney()->getCurrency().getValue() << std::endl;
*/
}
}
for(auto && bank1 : banks) {
for(auto && bank2 : banks) {
if(bank1 != bank2) {
for (int i = 0; i < 10000; ++i) {
int rnd = distribution(generator);
bank1->moveMoney(bank2, rnd);
}
}
} }
} }
@ -113,10 +126,14 @@ void simulate() {
std::cout << money->getValue() << ", "; std::cout << money->getValue() << ", ";
} }
std::cout << std::endl; std::cout << std::endl;
} }
void tearDown() { void tearDown() {
for(auto && bank : banks) {
}
} }
@ -128,7 +145,5 @@ int main(int argc, char **argv) {
std::cout << "+++++++++++++++++++++++++ " << "tearDown()" << " +++++++++++++++++++++++++" << std::endl; std::cout << "+++++++++++++++++++++++++ " << "tearDown()" << " +++++++++++++++++++++++++" << std::endl;
tearDown(); tearDown();
HeapObject::assertionsHold();
return 0; return 0;
} }