-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
116 lines (85 loc) · 3.49 KB
/
main.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpoveda- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/16 13:22:05 by dpoveda- #+# #+# */
/* Updated: 2022/02/18 12:37:24 by dpoveda- ### ########.fr */
/* */
/* ************************************************************************** */
#include "Animal.hpp"
#include "Dog.hpp"
#include "Cat.hpp"
#include "Human.hpp"
#include <iostream>
#define N_ANIMALS 10
int main() {
std::cout << "================== SHITY TEST ==================\n" << std::endl;
std::cout << "================== BASIC TEST ==================\n" << std::endl;
Dog *dog = new Dog();
Cat *cat = new Cat();
Human *human = new Human();
std::cout << std::endl;
std::cout << dog->getType() << std::endl;
std::cout << cat->getType() << std::endl;
std::cout << human->getType() << std::endl;
std::cout << std::endl;
dog->makeSound();
cat->makeSound();
human->makeSound();
std::cout << std::endl;
// TEST DEEP COPY
std::cout << "================== TEST DEEP COPY ==================\n" << std::endl;
cat->getBrain()->ideas[0] = "I like potatoes";
cat->getBrain()->ideas[1] = "I like ice cream";
std::cout << "Cat ideas:" << std::endl;
for (int i = 0; i < 2; i++) std::cout << "Idea: " << cat->getBrain()->ideas[i] << std::endl;
std::cout << std::endl;
std::cout << "Create cat2" << std::endl;
Cat *cat2 = new Cat();
std::cout << std::endl;
std::cout << "Cat2 ideas" << std::endl;
for (int i = 0; i < 2; i++) std::cout << "Idea: " << cat2->getBrain()->ideas[i] << std::endl;
std::cout << std::endl;
std::cout << "Cat2 = Cat" << std::endl;
*cat2 = *cat;
std::cout << std::endl;
std::cout << "Cat ideas:" << std::endl;
for (int i = 0; i < 2; i++) std::cout << "Idea: " << cat->getBrain()->ideas[i] << std::endl;
std::cout << std::endl;
std::cout << "Cat2 ideas" << std::endl;
for (int i = 0; i < 2; i++) std::cout << "Idea: " << cat2->getBrain()->ideas[i] << std::endl;
std::cout << std::endl;
std::cout << "Cat ideas (now he hates ice cream)" << std::endl;
cat->getBrain()->ideas[1] = "I hate ice cream";
for (int i = 0; i < 2; i++) std::cout << "Idea: " << cat->getBrain()->ideas[i] << std::endl;
std::cout << std::endl;
std::cout << "Cat2 ideas" << std::endl;
for (int i = 0; i < 2; i++) std::cout << "Idea: " << cat2->getBrain()->ideas[i] << std::endl;
std::cout << std::endl;
std::cout << "================== CLEAN ALL ==================\n" << std::endl;
delete dog;
delete cat;
delete cat2;
delete human;
std::cout << std::endl;
std::cout << "================ SUBJECT ARRAY TEST ================\n" << std::endl;
Animal *animals[N_ANIMALS];
for (int i = 0; i < N_ANIMALS; i++) {
if (i < N_ANIMALS / 2) {
animals[i] = new Cat();
} else {
animals[i] = new Dog();
}
}
std::cout << std::endl;
for (int i = 0; i < N_ANIMALS; i++) {
animals[i]->makeSound();
}
std::cout << std::endl;
for (int i = 0; i < N_ANIMALS; i++) {
delete animals[i];
}
}