1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
void assrt(bool e, const char* m) {
if (!e) {
std::cout << "Assertion failed : " << m << std::endl;
}
}
void test1() {
Sheep w{"white", 125, 23}; //color, weight, price per kg
Sheep b{"black", 120, 25.5};
assrt(0==strcmp("white", w.color()), "Wrong color");
assrt(0==strcmp("black", b.color()), "Wrong color");
}
void test2() {
Sheep w{"white", 125, 23}; //color, weight, price per kg
Sheep b{"black", 120, 25.5};
assrt(0==strcmp("white", w.color()), "Wrong color");
assrt(1==w.id(), "Wrong id");
assrt(0==strcmp("black", b.color()), "Wrong color");
assrt(2==b.id(), "Wrong id");
}
void test3() {
Sheep w{"white", 125, 23};
{
Sheep* ps = new Sheep{w};
ps->setColor("black");
assrt(0==strcmp("black", ps->color()), "Wrong color");
assrt(2==ps->id(), "Wrong id");
delete ps;
}
assrt(0==strcmp("white", w.color()), "Wrong color");
assrt(1==w.id(), "Wrong id");
}
|