Skip to content

Commit

Permalink
#2 Test unitaire
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdiberriri committed Sep 24, 2018
1 parent 0b968be commit f562a5b
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/BotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ public void play() throws Exception {
/*On test d'abord s'il y a une parcelle au point p2 */
assertFalse(pla.getMap().containsKey(p2));


j.play(pla,p1);

/*Maintenant on regarde si la parcelle a été posée au bon endroit*/
assertEquals(par1.toString(),pla.getParcelle(p2).toString());

assertTrue(pla.getMap().containsKey(p2));
}

}
139 changes: 138 additions & 1 deletion test/PlateauTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,154 @@ void getParcelleVoisineLibre() {
/*Recuperer la liste des emplacements voisins libres*/
ArrayList<Point3D> list = pla.getParcelleVoisineLibre(p1);

/*Creer la liste des enplacements voisins libres*/
/*Creer la liste des emplacements voisins libres*/
ArrayList<Point3D> list2 = new ArrayList<>();
list2.add(new Point3D(1.0,-1.0,0.0));
list2.add(new Point3D(0.0,1.0,-1.0));

for (int i = 0 ; i < list.size(); i++){
assertEquals(list.get(i),list2.get(i));
}
}

@Test
void getParcelleVoisineLibre2() {

pla.poser(par1,p1);
pla.poser(par1,new Point3D(1,1,-2));
pla.poser(par1,new Point3D(2,0,-2));
pla.poser(par1,new Point3D(2,-1,-1));
pla.poser(par1,new Point3D(1,-1,0));
pla.poser(par1,new Point3D(0.0,1.0,-1.0));

/*Recuperer la liste des emplacements voisins libres*/
ArrayList<Point3D> list = pla.getParcelleVoisineLibre(p1);

/*Creer la liste des emplacements voisins libres*/
ArrayList<Point3D> list2 = new ArrayList<>();

for (int i = 0 ; i < list.size(); i++){
assertEquals(list.get(i),list2.get(i));
}
}

@Test
void getParcelleVoisineLibre3() {


/*Recuperer la liste des emplacements voisins libres*/
ArrayList<Point3D> list = pla.getParcelleVoisineLibre(p);

/*Creer la liste des emplacements voisins libres*/
ArrayList<Point3D> list2 = new ArrayList<>();
list2.add(new Point3D(0.0,1.0,-1.0));
list2.add(new Point3D(1.0,0.0,-1.0));
list2.add(new Point3D(1.0,-1.0,0.0));
list2.add(new Point3D(0.0,-1.0,1.0));
list2.add(new Point3D(-1.0,0.0,1.0));
list2.add(new Point3D(-1.0,1.0,0.0));

for (int i = 0 ; i < list.size(); i++){
assertEquals(list.get(i),list2.get(i));
}
}

@Test
void getParcelleVoisineOccupe() {

Point3D p1=new Point3D(0,0,0);

/*Recuperer la liste des emplacements voisins occupees*/
ArrayList<Point3D> list = pla.getParcelleVoisineOccupe(p1);
assertEquals(list.size(),0);


/*Creer la liste des emplacements voisins occupees*/
pla.poser(par1,new Point3D(0,1,-1));
list = pla.getParcelleVoisineOccupe(p1);
assertEquals(list.size(),1);

/*On ajoute des parcelles adjacentes*/
pla.poser(par1,new Point3D(1,0,-1));
pla.poser(par1,new Point3D(1,-1,0));
list = pla.getParcelleVoisineOccupe(p1);
assertEquals(list.size(),3);

/*On ajoute des parcelles adjacentes*/
pla.poser(par1,new Point3D(0,-1,1));
pla.poser(par1,new Point3D(-1,0,1));
pla.poser(par1,new Point3D(-1,1,0));
list = pla.getParcelleVoisineOccupe(p1);
assertEquals(list.size(),6);

ArrayList<Point3D> list2 = new ArrayList<>();
list2.add(new Point3D(0.0,1.0,-1.0));
list2.add(new Point3D(1.0,0.0,-1.0));
list2.add(new Point3D(1.0,-1.0,0.0));
list2.add(new Point3D(0.0,-1.0,1.0));
list2.add(new Point3D(-1.0,0.0,1.0));
list2.add(new Point3D(-1.0,1.0,0.0));

for (int i = 0 ; i < list.size(); i++){
assertEquals(list.get(i),list2.get(i));
}
}

@Test
void isEmplacementAutorise() {
//il n'y a que la parcelle de départ sur le plateau
boolean autorisation;

// on vérifie si on peut poser à coté de la parcelle de départ
autorisation = pla.isEmplacementAutorise(new Point3D(0,1,-1));

assertTrue(autorisation);

//on ajoute 2 parcelles adjacentes entres elles et adjacentes à la parcelle de départ
pla.poser(par1,new Point3D(1,0,-1));
pla.poser(par1,new Point3D(1,-1,0));

//on vérifie si on peut poser en étant adjacent aux 2 nouvelles parcelles posées
autorisation = pla.isEmplacementAutorise(new Point3D(2,-1,-1));

assertTrue(autorisation);

//on vérifie si on peut poser en étant adjacant à une seule parcelle qui n'est pas celle de départ
autorisation = pla.isEmplacementAutorise(new Point3D(1,1,-2));

assertFalse(autorisation);

//on vérifie si on peut poser à un endroit adjacent à aucune parcelle
autorisation = pla.isEmplacementAutorise(new Point3D(0,-2,2));

assertFalse(autorisation);
}

@Test
void emplacementAutorise(){

ArrayList<Point3D> list = pla.emplacementsAutorise();
assertEquals(list.size(),6);

ArrayList<Point3D> list2 = new ArrayList<>();
list2.add(new Point3D(0.0,1.0,-1.0));
list2.add(new Point3D(1.0,0.0,-1.0));
list2.add(new Point3D(1.0,-1.0,0.0));
list2.add(new Point3D(0.0,-1.0,1.0));
list2.add(new Point3D(-1.0,0.0,1.0));
list2.add(new Point3D(-1.0,1.0,0.0));

for (int i = 0 ; i < list.size(); i++){
assertEquals(list.get(i),list2.get(i));
}

pla.poser(par1,new Point3D(0.0,1.0,-1.0));
list2.remove(0);
list = pla.emplacementsAutorise();

for (int i = 0 ; i < list.size(); i++){
assertEquals(list.get(i),list2.get(i));
}
}

}

0 comments on commit f562a5b

Please sign in to comment.