Package tests

Source Code of tests.TestAttributionPlaces

/**
*
*/
package tests;

import java.util.ArrayList;
import java.util.Iterator;

import junit.framework.Assert;
import junit.framework.TestCase;
import metier.reservations.AttributionPlaces;
import data.theatre.Place;
import data.theatre.Rangee;
import data.theatre.Zone;
import exceptions.metier.NombreTotalPlacesInsuffisantException;

/**
* @author matej
*
*/
public class TestAttributionPlaces extends TestCase {

  private Zone z;
  private Zone z3;
  private int RANGEES = 4;
  private int PLACESPARRANGEE = 15;

  /**
   * @throws java.lang.Exception
   */
 
  protected void setUp() throws Exception {
    System.out.println("SETUP DEBUT");
    z = new Zone("Premiere");
   

    /*
     * remplissage de la zone Z Premiere
     */
    for(int i = 1; i <= RANGEES; i++){
      Rangee r = new Rangee("R"+i);
      for(int j = 1; j <= PLACESPARRANGEE; j++){
        Place p = new Place(j);
        r.addPlace(p);
      }
      z.addRangee(r);
    }
   
    // remplissage de la zone Z3 = Balcon
    reInitZ3();
   
    System.out.println("SETUP FIN");
  }

  /**
   * Test des nombres d'elements dans zone et dans rangee
   *
   */
  /*
  public void testNbres(){
    System.out.println("TEST NBRES DEBUT");
    for(Iterator it = this.z.getLesRangees().iterator(); it.hasNext();){
      Rangee r = (Rangee)it.next();
      System.out.println("TEST TESTNBRES : Rangees existantes: "+r.toString());
    }

    Assert.assertEquals(RANGEES, z.getNbRangees());
    Assert.assertEquals(PLACESPARRANGEE*RANGEES, z.getNbFauteuils());
    System.out.println(z3.toString() + z.toString());
    System.out.println("TEST NBRES FIN\n" +
    "\n");
  }
  */
  /**
   * Test de verification si une rangee possede
   * un nombre suffisant de places
   */
  /*
  public void testAttributionRangee1HasConsecutive(){
    System.out.println("TEST HAS_CONSECUTIVE DEBUT (sur rangee 1)");
    Assert.assertTrue(new AttributionPlaces().rangeeHasConsecutive(z.getRangee(1), PLACESPARRANGEE));
    Assert.assertTrue(new AttributionPlaces().rangeeHasConsecutive(z.getRangee(1), 14));

    Assert.assertFalse(new AttributionPlaces().rangeeHasConsecutive(z.getRangee(1), PLACESPARRANGEE+3));

    Assert.assertTrue(new AttributionPlaces().rangeeHasConsecutive(z.getRangee(1), 0));
    System.out.println("TEST HAS_CONSECUTIVE FIN\n\n");
  }
  */


  /*
  public void testAttributionHasNotConsecutive(){

    System.out.println("TEST HAS_NOT_CONSECUTIVE DEBUT");
    Zone z2 = new Zone("Seconde");
    Rangee r = new Rangee("RG5");
    for(int i = 1; i <= 100; i++){
      switch (i) {
      case 4:

        break;
      case 9:

        break;
      case 15:

        break;
      case 22:

        break;
      case 30:

        break;
      case 39:

        break;
      case 50:
        break;

      default:
        r.addPlace(new Place(i));
      break;
      }

    }
    z2.addRangee(r);

    for(Iterator it = z2.getLesRangees().iterator(); it.hasNext(); ){
      Rangee rg = (Rangee)it.next();
      System.out.println("TAP: Rangee traitee: "+rg.toString()+"\n");


      for(int i = 0; i <= 11; i++){
        System.out.println("TEST pour trouver "+i+" places consecutives");
        Assert.assertTrue(new AttributionPlaces().rangeeHasConsecutive(rg, i));
        System.out.println("TEST TERMINE pour trouver "+i+" places consecutives\n\n");
      }
      System.out.println("TEST pour trouver 51 places consecutives parmi les "+rg.getNbPlaces());
      Assert.assertFalse(new AttributionPlaces().rangeeHasConsecutive(rg, 51));
      System.out.println("TEST TERMINE pour trouver 51 places consecutives (echec)");

      System.out.println("TEST HAS_NOT_CONSECUTIVE FIN");
    }
  }
  */


  /* 
  public void testAttributionHasConsecutivePlaces(){

    System.out.println("TEST HAS_CONSECUTIVE_PLACES DEBUT");
    Zone z2 = new Zone("Seconde");
    Rangee r = new Rangee("RG5");
    for(int i = 1; i <= 100; i++){
      switch (i) {
      case 4:

        break;
      case 9:

        break;
      case 15:

        break;
      case 22:

        break;
      case 30:

        break;
      case 39:

        break;
      case 50:
        break;

      default:
        r.addPlace(new Place(i));
      break;
      }

    }
    z2.addRangee(r);

    for(Iterator it = z2.getLesRangees().iterator(); it.hasNext(); ){
      Rangee rg = (Rangee)it.next();
      System.out.println("TAP: Rangee traitee: "+rg.toString()+"\n");


      for(int i = 0; i <= 11; i++){
        System.out.println("TEST pour trouver "+i+" places consecutives");
        ArrayList l = (ArrayList)new AttributionPlaces().getConsecutiveDsRangee(rg, i);
        Assert.assertNotSame(new ArrayList(), l);
        System.out.println(l.toString());
        System.out.println("TEST TERMINE pour trouver "+i+" places consecutives\n\n");
      }
      System.out.println("TEST pour trouver 51 places consecutives parmi les "+rg.getNbPlaces());
      ArrayList l = (ArrayList)new AttributionPlaces().getConsecutiveDsRangee(rg, 51);
      Assert.assertNotSame(new ArrayList(), l);
      //System.out.println(l.toString());
      System.out.println("TEST TERMINE pour trouver 51 places consecutives (echec)");

      System.out.println("TEST HAS_CONSECUTIVE_PLACES FIN");
    }
  }
  */


  public void testPlacesDsZone(){

    System.out.println("TEST PLACES_DANS_ZONE DEBUT");
   
    reInitZ3();


    for(int i = 15; i <= 1; i--){
      System.out.println("\nTEST NO "+i
          +"\nBUT: Recherche de "+i
          +" places consecutives (parmi les "
          +z3.getNbFauteuils()+" places restantes)");
      try{
        System.out.println(new AttributionPlaces().getConsecutiveDsZone(z3, i));
      }catch(NombreTotalPlacesInsuffisantException e){
        e.printStackTrace();
      }
      System.out.println("\nRESULTAT: Zone z3 (reste "+z3.getNbFauteuils()+"): \n"+z3.toString());
    }
    try{
      System.out.println(new AttributionPlaces().getConsecutiveDsZone(z3, 2));
    }catch(NombreTotalPlacesInsuffisantException e){
      e.printStackTrace();
    }
    System.out.println("\nRESULTAT: Zone z3 (reste "+z3.getNbFauteuils()+"): \n"+z3.toString());
  }
 
  public void testProposePlaces(){
    ArrayList proposition;
    try{
      System.out.println("\n\nTEST PROPOSE PLACES\nZ3 (avec "+z3.getNbFauteuils()+" places restantes) au depart: "+ z3.toString());
     
      reInitZ3();
     
      proposition = (ArrayList)new AttributionPlaces().proposePlaces(z3, 64);
      System.out.println("TEST DECOUPAGE 1\n" +z3.toString()+"\n\nResultat:\n"+proposition.toString());
    }catch(NombreTotalPlacesInsuffisantException ntpie){
      ntpie.printStackTrace();
    }
    try{
//      reInitZ3();
      System.out.println("TEST DECOUPAGE");
      proposition = (ArrayList)new AttributionPlaces().proposePlaces(z, 15);
      System.out.println("TEST DECOUPAGE TERMINE:\n"+z.toString()+"\nResultat:\n"+proposition.toString());
     
    }catch(NombreTotalPlacesInsuffisantException ntpie){
      ntpie.printStackTrace();
    }
    try{
//      reInitZ3();
      System.out.println("TEST DECOUPAGE \n"+z.toString()+"\n\n");
      proposition = (ArrayList)new AttributionPlaces().proposePlaces(z, 16);
      System.out.println("Resultat:\n"+proposition.toString());
     
    }catch(NombreTotalPlacesInsuffisantException ntpie){
      ntpie.printStackTrace();
    }
   
  }
 
  public void testProposeFauteuils(){
    try{
      reInitZ3();
      System.out.println(z3.toString());
      System.out.println("Test propose Fauteuils");
      ArrayList proposition = (ArrayList)new AttributionPlaces().proposeFauteuils(z3, 2);
      System.out.println("Resultat:\n"+proposition.toString());
      System.out.println("Situation apres\n"+z3.toString());
    }catch(Exception e){
      e.printStackTrace();
    }
  }
 
 
  private void reInitZ3(){
    z3 = new Zone("BalconDeTest");
   
    for(int j = 1; j <= 4; j++){
      Rangee r = new Rangee("Rg"+(j));
      switch (j) {
      case 1:
        for(int i = 1; i <= 8; i++){
          if(i != 4){
            Place p = new Place(i);
            r.addPlace(p);
          }
        }
        break;
      case 2:
        for(int i = 1; i <= 12; i++){
          if(i != 6){
            Place p = new Place(i);
            r.addPlace(p);
          }
        }
        break;
      case 3:
        for(int i = 1; i <= 16; i++){
          if(i != 8){
            Place p = new Place(i);
            r.addPlace(p);
          }
        }
        break;
      case 4:
        for(int i = 1; i <= 31; i++){
          if(i != 11){
            Place p = new Place(i);
            r.addPlace(p);
          }
        }
        break;
      default:
        break;
      }
      z3.addRangee(r);
    }
//    System.out.println("Zone "+z3.getIdZone()+" est remplie:");
//    System.out.println(z3.toString());
  }

} // fin testcase
TOP

Related Classes of tests.TestAttributionPlaces

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.