10_PITF: Assertions behoben
This commit is contained in:
parent
e81be0cf84
commit
9b5e4fb7bf
|
@ -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">
|
||||
|
||||
[Dokumentation](https://files.joethei.space/documentation/Studium/C_CPP/)
|
|
@ -1,5 +1,6 @@
|
|||
#include <utility>
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
|
||||
#include "Bank.h"
|
||||
|
||||
|
@ -11,6 +12,11 @@ void Bank::addAccount(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() {
|
||||
return accounts;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ public:
|
|||
explicit Bank(std::string name);
|
||||
explicit Bank(Bank* bank);
|
||||
void addAccount(BankAccount * account);
|
||||
void moveMoney(std::shared_ptr<Bank> bank, int amount);
|
||||
std::set<std::shared_ptr<BankAccount>> getAccounts();
|
||||
std::string getName();
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <utility>
|
||||
#include <random>
|
||||
#include <ctime>
|
||||
|
||||
#include "BankAccount.h"
|
||||
#include "CashFactory.h"
|
||||
|
|
|
@ -3,6 +3,4 @@
|
|||
|
||||
#include "Cash.h"
|
||||
|
||||
Cash::Cash(int value, Currency currency) : Money(value, currency) {
|
||||
|
||||
}
|
||||
Cash::Cash(int value, Currency currency) : Money(value, currency) {}
|
|
@ -12,6 +12,9 @@ void* HeapObject::operator new (size_t size){
|
|||
return new char[size];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HeapObject::HeapObject(){
|
||||
ctorCount++;
|
||||
}
|
||||
|
@ -22,6 +25,7 @@ HeapObject::~HeapObject(){
|
|||
|
||||
bool HeapObject::assertionsHold(){
|
||||
//assert(ctorCount == newCount); // all objects have been allocated on heap
|
||||
std::cout << ctorCount << " : " << dtorCount << std::endl;
|
||||
assert(ctorCount == dtorCount); // all objects have been deleted
|
||||
return true;
|
||||
}
|
|
@ -89,21 +89,34 @@ void simulate() {
|
|||
std::shared_ptr<Bill> bill = cashFactory->printBill(rnd, CurrencyValue::USD);
|
||||
std::shared_ptr<Coin> coin = cashFactory->printCoin(rnd, CurrencyValue::USD);
|
||||
if (bill != nullptr) {
|
||||
*bankAccount + bill.get();
|
||||
//*bankAccount + bill.get();
|
||||
moneyVector.push_back(std::static_pointer_cast<Money, Bill>(bill));
|
||||
}
|
||||
if (coin != nullptr) {
|
||||
*bankAccount + coin.get();
|
||||
//*bankAccount + coin.get();
|
||||
moneyVector.push_back(std::static_pointer_cast<Money, Coin>(coin));
|
||||
}
|
||||
|
||||
Money *fee = *bankAccount - 10;
|
||||
delete fee;
|
||||
}
|
||||
//FIXME: Das hier mag er nicht
|
||||
// std::cout << bankAccount->getOwner()->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,11 +126,15 @@ void simulate() {
|
|||
std::cout << money->getValue() << ", ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void tearDown() {
|
||||
for(auto && bank : banks) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
@ -128,7 +145,5 @@ int main(int argc, char **argv) {
|
|||
std::cout << "+++++++++++++++++++++++++ " << "tearDown()" << " +++++++++++++++++++++++++" << std::endl;
|
||||
tearDown();
|
||||
|
||||
HeapObject::assertionsHold();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue