08_PTRN & 10_PITF: Testate bestanden

This commit is contained in:
Johannes Theiner 2019-01-08 11:09:46 +01:00
parent 808bb073bb
commit b1f037826c
6 changed files with 8 additions and 8 deletions

View File

@ -8,6 +8,7 @@ this->owner = owner;
BankAccount * BankAccount::operator+(Money * money) { BankAccount * BankAccount::operator+(Money * money) {
BankAccount::money = new Money(money->getValue() + getMoney().getValue()); BankAccount::money = new Money(money->getValue() + getMoney().getValue());
return this; return this;
} }

View File

@ -94,7 +94,8 @@ int main(int argc, char **argv) {
*bankAccount + coin; *bankAccount + coin;
} }
Money * fee = * bankAccount - 10; Money * fee = *bankAccount - 10;
delete fee;
} }
std::cout << *bankAccount << std::endl; std::cout << *bankAccount << std::endl;
} }

View File

@ -4,7 +4,7 @@
using namespace banking; using namespace banking;
Bill::Bill(int value, Currency currency, std::string serial) : Cash(value, currency), serial(std::move(serial)){ Bill::Bill(int value, Currency currency, std::string &serial) : Cash(value, currency), serial(std::move(serial)){
} }

View File

@ -18,7 +18,7 @@ namespace banking {
private: private:
std::string serial; std::string serial;
public: public:
explicit Bill(int value, Currency currency, std::string serial); explicit Bill(int value, Currency currency, std::string &serial);
explicit Bill(Bill *bill); explicit Bill(Bill *bill);
std::string getSerial(); std::string getSerial();
int getValue() override; int getValue() override;

View File

@ -22,8 +22,6 @@ 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 << std::endl;
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

@ -35,17 +35,17 @@ std::ostream &operator<<(std::ostream &os, Cash cash) {
return os; return os;
} }
std::ostream &operator<<(std::ostream &os, std::shared_ptr<Money> money) { std::ostream &operator<<(std::ostream &os, const std::shared_ptr<Money> &money) {
os << money->getValue() << " " << money->getCurrency(); os << money->getValue() << " " << money->getCurrency();
return os; return os;
} }
std::ostream &operator<<(std::ostream &os, std::shared_ptr<Person> person) { std::ostream &operator<<(std::ostream &os, const std::shared_ptr<Person> &person) {
os << person->getName(); os << person->getName();
return os; return os;
} }
std::ostream &operator<<(std::ostream &os, std::shared_ptr<BankAccount> bankAccount) { std::ostream &operator<<(std::ostream &os, const std::shared_ptr<BankAccount> &bankAccount) {
os << bankAccount->getOwner() << " " << bankAccount->getName() << ": " << bankAccount->getMoney(); os << bankAccount->getOwner() << " " << bankAccount->getName() << ": " << bankAccount->getMoney();
return os; return os;
} }