Skip to content
Snippets Groups Projects
Commit b871e110 authored by Aymeric berthoumieu's avatar Aymeric berthoumieu
Browse files

correction of Aymeric's test files

parent 7adfc4dc
No related branches found
No related tags found
1 merge request!21correction of Aymeric's test files
......@@ -16,9 +16,13 @@ int main(){
int windowHeight = 800; //480
int delay = 30;
int startingNbPets = 100;
map<string, float> animalsDistribution = {{KamikazeBehaviour::getBehaviourInstance()->getBehaviourName(), 10}, {FearfulBehaviour::getBehaviourInstance()->getBehaviourName(), 30}, {GregariousBehaviour::getBehaviourInstance()->getBehaviourName(), 40}, {"b_multiple", 20}};
map<string, float> animalsDistribution = {{KamikazeBehaviour::getBehaviourInstance()->getBehaviourName(), 10},
{FearfulBehaviour::getBehaviourInstance()->getBehaviourName(), 30},
{GregariousBehaviour::getBehaviourInstance()->getBehaviourName(), 40},
{"b_multiple", 20}};
Aquarium ecosystem(windowWidth, windowHeight, delay, startingNbPets, animalsDistribution);
ecosystem.run();
return 0;}
return 0;
}
SRCDIR := src/
TESTSDIR := tests/
testCollision : $(TESTSDIR)testCollision.cpp Aquarium.o Pet.o Environment.o Animal.o
g++ -Wall -std=c++11 -o testCollision $(TESTSDIR)testCollision.cpp Aquarium.o Pet.o Environment.o Animal.o -I $(SRCDIR) -lX11 -lpthread
testCollision : $(TESTSDIR)testCollision.cpp Aquarium.o Pet.o Environment.o Animal.o GregariousBehaviour.o FearfulBehaviour.o KamikazeBehaviour.o Fin.o Eyes.o PetFactory.o Statistics.o MoveUtils.o
g++ -Wall -std=c++11 -o testCollision $(TESTSDIR)testCollision.cpp Aquarium.o Pet.o Environment.o Animal.o GregariousBehaviour.o FearfulBehaviour.o KamikazeBehaviour.o Fin.o Eyes.o PetFactory.o Statistics.o MoveUtils.o -I $(SRCDIR) -lX11 -lpthread
Aquarium.o : $(SRCDIR)Aquarium.h $(SRCDIR)Aquarium.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Aquarium.cpp -I $(SRCDIR)
......@@ -15,3 +15,28 @@ Animal.o : $(SRCDIR)Animal.h $(SRCDIR)Animal.cpp
Environment.o : $(SRCDIR)Environment.h $(SRCDIR)Environment.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Environment.cpp -I $(SRCDIR)
MoveUtils.o : $(SRCDIR)MoveUtils.h $(SRCDIR)MoveUtils.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)MoveUtils.cpp -I $(SRCDIR)
GregariousBehaviour.o : $(SRCDIR)BehaviourStrategy.h $(SRCDIR)GregariousBehaviour.h $(SRCDIR)GregariousBehaviour.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)GregariousBehaviour.cpp -I $(SRCDIR)
FearfulBehaviour.o : $(SRCDIR)BehaviourStrategy.h $(SRCDIR)FearfulBehaviour.h $(SRCDIR)FearfulBehaviour.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)FearfulBehaviour.cpp -I $(SRCDIR)
KamikazeBehaviour.o : $(SRCDIR)BehaviourStrategy.h $(SRCDIR)KamikazeBehaviour.h $(SRCDIR)KamikazeBehaviour.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)KamikazeBehaviour.cpp -I $(SRCDIR)
Statistics.o : $(SRCDIR)Statistics.h $(SRCDIR)Statistics.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Statistics.cpp -I $(SRCDIR)
Fin.o : $(SRCDIR)Fin.h $(SRCDIR)Fin.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Fin.cpp -I $(SRCDIR)
Eyes.o : $(SRCDIR)Eyes.h $(SRCDIR)Eyes.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Eyes.cpp -I $(SRCDIR)
PetFactory.o : $(SRCDIR)PetFactory.h $(SRCDIR)PetFactory.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)PetFactory.cpp -I $(SRCDIR)
SRCDIR := src/
TESTSDIR := tests/
testDeath1 : $(TESTSDIR)testDeath1.cpp Aquarium.o Pet.o Environment.o Animal.o
g++ -Wall -std=c++11 -o testDeath1 $(TESTSDIR)testDeath1.cpp Aquarium.o Pet.o Environment.o Animal.o -I $(SRCDIR) -lX11 -lpthread
testCollision : $(TESTSDIR)testDeath1.cpp Aquarium.o Pet.o Environment.o Animal.o GregariousBehaviour.o FearfulBehaviour.o KamikazeBehaviour.o Fin.o Eyes.o PetFactory.o Statistics.o MoveUtils.o
g++ -Wall -std=c++11 -o testDeath1 $(TESTSDIR)testDeath1.cpp Aquarium.o Pet.o Environment.o Animal.o GregariousBehaviour.o FearfulBehaviour.o KamikazeBehaviour.o Fin.o Eyes.o PetFactory.o Statistics.o MoveUtils.o -I $(SRCDIR) -lX11 -lpthread
Aquarium.o : $(SRCDIR)Aquarium.h $(SRCDIR)Aquarium.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Aquarium.cpp -I $(SRCDIR)
......@@ -15,3 +15,28 @@ Animal.o : $(SRCDIR)Animal.h $(SRCDIR)Animal.cpp
Environment.o : $(SRCDIR)Environment.h $(SRCDIR)Environment.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Environment.cpp -I $(SRCDIR)
MoveUtils.o : $(SRCDIR)MoveUtils.h $(SRCDIR)MoveUtils.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)MoveUtils.cpp -I $(SRCDIR)
GregariousBehaviour.o : $(SRCDIR)BehaviourStrategy.h $(SRCDIR)GregariousBehaviour.h $(SRCDIR)GregariousBehaviour.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)GregariousBehaviour.cpp -I $(SRCDIR)
FearfulBehaviour.o : $(SRCDIR)BehaviourStrategy.h $(SRCDIR)FearfulBehaviour.h $(SRCDIR)FearfulBehaviour.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)FearfulBehaviour.cpp -I $(SRCDIR)
KamikazeBehaviour.o : $(SRCDIR)BehaviourStrategy.h $(SRCDIR)KamikazeBehaviour.h $(SRCDIR)KamikazeBehaviour.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)KamikazeBehaviour.cpp -I $(SRCDIR)
Statistics.o : $(SRCDIR)Statistics.h $(SRCDIR)Statistics.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Statistics.cpp -I $(SRCDIR)
Fin.o : $(SRCDIR)Fin.h $(SRCDIR)Fin.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Fin.cpp -I $(SRCDIR)
Eyes.o : $(SRCDIR)Eyes.h $(SRCDIR)Eyes.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Eyes.cpp -I $(SRCDIR)
PetFactory.o : $(SRCDIR)PetFactory.h $(SRCDIR)PetFactory.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)PetFactory.cpp -I $(SRCDIR)
SRCDIR := src/
TESTSDIR := tests/
testDeath2 : $(TESTSDIR)testDeath2.cpp Aquarium.o Pet.o Environment.o Animal.o
g++ -Wall -std=c++11 -o testDeath2 $(TESTSDIR)testDeath2.cpp Aquarium.o Pet.o Environment.o Animal.o -I $(SRCDIR) -lX11 -lpthread
testCollision : $(TESTSDIR)testDeath2.cpp Aquarium.o Pet.o Environment.o Animal.o GregariousBehaviour.o FearfulBehaviour.o KamikazeBehaviour.o Fin.o Eyes.o PetFactory.o Statistics.o MoveUtils.o
g++ -Wall -std=c++11 -o testDeath2 $(TESTSDIR)testDeath2.cpp Aquarium.o Pet.o Environment.o Animal.o GregariousBehaviour.o FearfulBehaviour.o KamikazeBehaviour.o Fin.o Eyes.o PetFactory.o Statistics.o MoveUtils.o -I $(SRCDIR) -lX11 -lpthread
Aquarium.o : $(SRCDIR)Aquarium.h $(SRCDIR)Aquarium.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Aquarium.cpp -I $(SRCDIR)
......@@ -15,3 +15,28 @@ Animal.o : $(SRCDIR)Animal.h $(SRCDIR)Animal.cpp
Environment.o : $(SRCDIR)Environment.h $(SRCDIR)Environment.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Environment.cpp -I $(SRCDIR)
MoveUtils.o : $(SRCDIR)MoveUtils.h $(SRCDIR)MoveUtils.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)MoveUtils.cpp -I $(SRCDIR)
GregariousBehaviour.o : $(SRCDIR)BehaviourStrategy.h $(SRCDIR)GregariousBehaviour.h $(SRCDIR)GregariousBehaviour.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)GregariousBehaviour.cpp -I $(SRCDIR)
FearfulBehaviour.o : $(SRCDIR)BehaviourStrategy.h $(SRCDIR)FearfulBehaviour.h $(SRCDIR)FearfulBehaviour.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)FearfulBehaviour.cpp -I $(SRCDIR)
KamikazeBehaviour.o : $(SRCDIR)BehaviourStrategy.h $(SRCDIR)KamikazeBehaviour.h $(SRCDIR)KamikazeBehaviour.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)KamikazeBehaviour.cpp -I $(SRCDIR)
Statistics.o : $(SRCDIR)Statistics.h $(SRCDIR)Statistics.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Statistics.cpp -I $(SRCDIR)
Fin.o : $(SRCDIR)Fin.h $(SRCDIR)Fin.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Fin.cpp -I $(SRCDIR)
Eyes.o : $(SRCDIR)Eyes.h $(SRCDIR)Eyes.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)Eyes.cpp -I $(SRCDIR)
PetFactory.o : $(SRCDIR)PetFactory.h $(SRCDIR)PetFactory.cpp
g++ -Wall -std=c++11 -c $(SRCDIR)PetFactory.cpp -I $(SRCDIR)
......@@ -41,6 +41,7 @@ int Environment::getHeight() const {
void Environment::step() {
++nb_steps; // increment the number of steps
cout << "[" << nb_steps << "]" << endl;
statistics.saveData(); // save statistics of the previous step before doing the new one
cimg_forXY(*this, x, y)
......@@ -66,7 +67,9 @@ void Environment::addMember(Animal* a) {
bool mustDie(Animal * p) {
// return true if the p has a life < 0. It means p must die at the end of the step
return p->getLife() <= 0;
bool ret = p->getLife() <= 0;
if (ret){delete p;} // the animal must be deleted
return ret;
}
......
......@@ -110,7 +110,6 @@ vector<Animal*> PetFactory::initializePopulation(int number){
for (const auto &nbPetsPerBehaviourPair : toCreate) {
createdNumber = createdNumber + static_cast<int>(nbPetsPerBehaviourPair.second);
for (int _i=0; _i<nbPetsPerBehaviourPair.second; _i++) {
cout << " " << nbPetsPerBehaviourPair.first << endl;
createdPets.push_back(this->createMember(nbPetsPerBehaviourPair.first));
}
// in case the rounding, while casting to int, results in a lower number of created pets than requested
......
......@@ -3,21 +3,26 @@
//
#include "Aquarium.h"
#include "Environment.h"
#include "Animal.h"
#include "Pet.h"
#include "KamikazeBehaviour.h"
#include <iostream>
using namespace std;
int main() {
Aquarium ecosystem(100, 100, 30);
int life = 1000;
cout << "[TEST] the pets should have a collision." << endl;
for (int i = 1; i <= 2; ++i)
ecosystem.getEnvironment().addMember(Pet());
ecosystem.getEnvironment().setLife(life); // fixing life of the pet
int nb_animals = 2; // two animals
int life = 100000000;
string behaviour = KamikazeBehaviour::getBehaviourInstance()->getBehaviourName();
map<string, float> animalsDistribution = {{behaviour, 100}}; // all kamikaze in order to have collision
Aquarium ecosystem(80, 80, 30, nb_animals, animalsDistribution);
ecosystem.getEnvironment().setLife(life); // fixing life of the animals
ecosystem.run(); // launch simulation
return 0;
......
......@@ -3,21 +3,26 @@
//
#include "Aquarium.h"
#include "Environment.h"
#include "Animal.h"
#include "Pet.h"
#include "FearfulBehaviour.h"
#include <iostream>
using namespace std;
int main() {
Aquarium ecosystem(640, 480, 30);
cout << "[TEST] the pet must die after " << life << " steps." << endl;
int nb_animals = 1; // two animals
string behaviour = FearfulBehaviour::getBehaviourInstance()->getBehaviourName();
int life = 10;
cout << "[TEST] the pet must die after " << life << " steps." << endl;
for (int i = 1; i <= 1; ++i)
ecosystem.getEnvironment().addMember(Pet());
ecosystem.getEnvironment().setLife(life); // fixing life of the pet
map<string, float> animalsDistribution = {{behaviour, 100}};
Aquarium ecosystem(100, 100, 30, nb_animals, animalsDistribution);
ecosystem.getEnvironment().setLife(life); // fixing life of the animals
ecosystem.run(); // launch simulation
return 0;
......
......@@ -3,19 +3,27 @@
//
#include "Aquarium.h"
#include "Environment.h"
#include "Animal.h"
#include "Pet.h"
#include "GregariousBehaviour.h"
#include "FearfulBehaviour.h"
#include "KamikazeBehaviour.h"
#include <iostream>
using namespace std;
int main() {
Aquarium ecosystem(640, 480, 30);
cout << "[TEST] the pets must die at different steps." << endl;
for (int i = 1; i <= 5; ++i)
ecosystem.getEnvironment().addMember(Pet());
int startingNbPets = 10;
map<string, float> animalsDistribution = {{KamikazeBehaviour::getBehaviourInstance()->getBehaviourName(), 10},
{FearfulBehaviour::getBehaviourInstance()->getBehaviourName(), 30},
{GregariousBehaviour::getBehaviourInstance()->getBehaviourName(), 40},
{"b_multiple", 20}};
Aquarium ecosystem(1200, 800, 30, startingNbPets, animalsDistribution);
ecosystem.run(); // launch simulation
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment