72 lines
2.6 KiB
C++
72 lines
2.6 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* main.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/11/08 17:43:10 by hadi #+# #+# */
|
|
/* Updated: 2025/11/10 20:40:42 by aortigos ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "Animal/Animal.hpp"
|
|
#include "Dog/Dog.hpp"
|
|
#include "Cat/Cat.hpp"
|
|
|
|
int main()
|
|
{
|
|
std::cout << "=== Basic Test ===" << std::endl;
|
|
const Animal* j = new Dog();
|
|
const Animal* i = new Cat();
|
|
|
|
delete j;
|
|
delete i;
|
|
|
|
std::cout << "\n=== Array Test ===" << std::endl;
|
|
const int arraySize = 6;
|
|
Animal* animals[arraySize];
|
|
|
|
// Fill half with Dogs, half with Cats
|
|
for (int i = 0; i < arraySize / 2; i++)
|
|
animals[i] = new Dog();
|
|
for (int i = arraySize / 2; i < arraySize; i++)
|
|
animals[i] = new Cat();
|
|
|
|
std::cout << "\n=== Making Sounds ===" << std::endl;
|
|
for (int i = 0; i < arraySize; i++)
|
|
{
|
|
std::cout << "Animal " << i << " (" << animals[i]->getType() << "): ";
|
|
animals[i]->makeSound();
|
|
}
|
|
|
|
std::cout << "\n=== Deleting Array ===" << std::endl;
|
|
for (int i = 0; i < arraySize; i++)
|
|
delete animals[i];
|
|
|
|
std::cout << "\n=== Deep Copy Test ===" << std::endl;
|
|
Dog originalDog;
|
|
originalDog.getBrain()->setIdea(0, "I love bones!");
|
|
|
|
Dog copiedDog = originalDog;
|
|
copiedDog.getBrain()->setIdea(0, "I love balls!");
|
|
|
|
std::cout << "Original dog idea: " << originalDog.getBrain()->getIdea(0) << std::endl;
|
|
std::cout << "Copied dog idea: " << copiedDog.getBrain()->getIdea(0) << std::endl;
|
|
|
|
std::cout << "\n=== Testing Brain Independence ===" << std::endl;
|
|
Cat* cat1 = new Cat();
|
|
cat1->getBrain()->setIdea(0, "Chase mice");
|
|
|
|
Cat* cat2 = new Cat(*cat1); // Copy constructor
|
|
cat2->getBrain()->setIdea(0, "Sleep all day");
|
|
|
|
std::cout << "Cat1 idea: " << cat1->getBrain()->getIdea(0) << std::endl;
|
|
std::cout << "Cat2 idea: " << cat2->getBrain()->getIdea(0) << std::endl;
|
|
|
|
delete cat1;
|
|
delete cat2;
|
|
|
|
return 0;
|
|
}
|