d04 ex01 ok change affichage + delete brain + constructors with default arguments

This commit is contained in:
hugogogo
2022-02-26 19:20:49 +01:00
parent 12f4c72e77
commit ed2bbc7fd2
8 changed files with 116 additions and 29 deletions

View File

@@ -6,9 +6,10 @@
#include <string>
#include "color.h"
#define N_TEST "7"
int main() {
std::cout << B_YELLOW "\n1rst test :" RESET "\n";
std::cout << B_YELLOW "\n[1/" N_TEST "] test subject :" RESET "\n";
{
const Animal* j = new Dog();
const Animal* i = new Cat();
@@ -16,7 +17,7 @@ int main() {
delete i;
}
std::cout << B_YELLOW "\n2nd test :" RESET "\n";
std::cout << B_YELLOW "\n[2/" N_TEST "] test with brain :" RESET "\n";
{
Dog * dog;
Cat * cat1;
@@ -24,42 +25,46 @@ int main() {
Brain * brain1 = new Brain();
Brain * brain2 = new Brain();
std::cout << B_BLUE "fill brain1 with \"giraffe\" :" RESET "\n";
std::cout << B_BLUE "fill brain1 with \"giraffe\" :" RESET "\n";
brain1->putIdeas("giraffe");
std::cout << B_BLUE "print brain1 :" RESET "\n";
std::cout << B_BLUE "print brain1 :" RESET "\n";
brain1->printIdeas();
std::cout << B_BLUE "print brain2 :" RESET "\n";
std::cout << B_BLUE "print brain2 :" RESET "\n";
brain2->printIdeas();
std::cout << B_BLUE "brain2 copy brain1 :" RESET "\n";
std::cout << B_BLUE "brain2 copy brain1 :" RESET "\n";
*brain2 = *brain1;
std::cout << B_BLUE "fill brain1 with \"hippopotamus\" :" RESET "\n";
std::cout << B_BLUE "fill brain1 with \"hippopotamus\" :" RESET "\n";
brain1->putIdeas("hippopotamus");
std::cout << B_BLUE "print brain1 :" RESET "\n";
std::cout << B_BLUE "print brain1 :" RESET "\n";
brain1->printIdeas();
std::cout << B_BLUE "print brain2 :" RESET "\n";
std::cout << B_BLUE "print brain2 :" RESET "\n";
brain2->printIdeas();
std::cout << B_BLUE "create new dog with brain1 :" RESET "\n";
std::cout << B_BLUE "create new dog with brain1 :" RESET "\n";
dog = new Dog(brain1);
std::cout << B_BLUE "create new cat with brain1 :" RESET "\n";
std::cout << B_BLUE "create new cat with brain1 :" RESET "\n";
cat1 = new Cat(brain1);
std::cout << B_BLUE "cat2 copy cat1 :" RESET "\n";
std::cout << B_BLUE "cat2 copy cat1 :" RESET "\n";
cat2 = *cat1;
std::cout << B_BLUE "fill brain1 with \"zebra\" :" RESET "\n";
std::cout << B_BLUE "fill brain1 with \"zebra\" :" RESET "\n";
brain1->putIdeas("zebra");
std::cout << B_BLUE "print cat1 :" RESET "\n";
std::cout << B_BLUE "print cat1 :" RESET "\n";
cat1->printBrain();
std::cout << B_BLUE "print cat2 :" RESET "\n";
std::cout << B_BLUE "print cat2 :" RESET "\n";
cat2.printBrain();
std::cout << B_BLUE "delete dog :" RESET "\n";
delete dog;
std::cout << B_BLUE "delete cat1 :" RESET "\n";
delete cat1;
std::cout << B_BLUE "delete brain1 :" RESET "\n";
delete brain1;
std::cout << B_BLUE "delete brain2 :" RESET "\n";
delete brain2;
}
std::cout << B_YELLOW "\narray animal test :" RESET "\n";
std::cout << B_YELLOW "\n[3/" N_TEST "] array animal test :" RESET "\n";
{
Animal *animals[10];
int i;
@@ -74,7 +79,7 @@ int main() {
delete animals[i];
}
std::cout << B_YELLOW "\ncopy constructor test1 :" RESET "\n";
std::cout << B_YELLOW "\n[4/" N_TEST "] copy constructor test1/2 :" RESET "\n";
{
std::cout << B_BLUE "Cat a_cat :" RESET "\n";
Cat a_cat;
@@ -82,7 +87,7 @@ int main() {
Cat a_cpy_cat(a_cat);
}
std::cout << B_YELLOW "\ncopy constructor test2 :" RESET "\n";
std::cout << B_YELLOW "\n[5/" N_TEST "] copy constructor test2/2 :" RESET "\n";
{
std::cout << B_BLUE "Cat a_cat :" RESET "\n";
Cat a_cat;
@@ -90,7 +95,7 @@ int main() {
Cat a_cpy_cat = a_cat;
}
std::cout << B_YELLOW "\nassignation operator test1 :" RESET "\n";
std::cout << B_YELLOW "\n[6/" N_TEST "] assignation operator test1 :" RESET "\n";
{
std::cout << B_BLUE "Cat a_cat :" RESET "\n";
Cat a_cat;
@@ -100,7 +105,7 @@ int main() {
a_cpy_cat = a_cat;
}
std::cout << B_YELLOW "\nassignation operator test2 :" RESET "\n";
std::cout << B_YELLOW "\n[7/" N_TEST "] assignation operator test2 :" RESET "\n";
{
std::cout << B_BLUE "const Cat *a_cat :" RESET "\n";
const Cat *a_cat = new Cat();