예제 #1
0
bool test_copy()
{
    piece p = new_piece_rh(0, 0, true, true);
    bool result = true;

    //the first one (set_up_1()) is with new_piece_rh (int x, int y, bool small, bool horizontal)
    set_up_1();
    for (int i = 0; i < NB_PIECES; i++) {
        copy_piece(pieces[i], p);
        result = result && test_equality_int(get_height(pieces[i]), get_height(p), "copy get_height");
        result = result && test_equality_int(get_width(pieces[i]), get_width(p), "copy get_width");
        result = result && test_equality_int(get_x(pieces[i]), get_x(p), "copy get_x");
        result = result && test_equality_int(get_y(pieces[i]), get_y(p), "copy get_y");
        result = result && test_equality_bool(is_horizontal(pieces[i]), is_horizontal(p), "copy is_horizontal");
        result = result && test_equality_bool(can_move_x(pieces[i]), can_move_x(p), "copy can_move_x");
        result = result && test_equality_bool(can_move_y(pieces[i]), can_move_y(p), "copy can_move_y");
    }
    tear_down();

    //the second one (set_up_2()) is with new_piece(int x, int y, int width, int height, bool move_x, bool move_y)
    set_up_2();
    for (int i = 0; i < NB_PIECES; i++) {
        copy_piece(pieces[i], p);
        result = result && test_equality_int(get_height(pieces[i]), get_height(p), "copy get_height");
        result = result && test_equality_int(get_width(pieces[i]), get_width(p), "copy get_width");
        result = result && test_equality_int(get_x(pieces[i]), get_x(p), "copy get_x");
        result = result && test_equality_int(get_y(pieces[i]), get_y(p), "copy get_y");
        result = result && test_equality_bool(is_horizontal(pieces[i]), is_horizontal(p), "copy is_horizontal");
        result = result && test_equality_bool(can_move_x(pieces[i]), can_move_x(p), "copy can_move_x");
        result = result && test_equality_bool(can_move_y(pieces[i]), can_move_y(p), "copy can_move_y");
    }
    tear_down();
    delete_piece(p);
    return result;
}
예제 #2
0
bool test_move() {
  bool result = true;
  piece p = new_piece_rh(0, 0, true, true);
  set_up();
  for (int dist = 1; dist < NB_PIECES; dist++)
    for (int i=0; i < NB_PIECES; i++) {
      copy_piece(pieces[i],p);
      move_piece(p, LEFT, dist);
      if (is_horizontal(pieces[i]))
        result = result && test_equality_int(get_x(pieces[i])-dist,get_x(p),"move LEFT");
      else
        result = result && test_equality_int(get_x(pieces[i]),get_x(p),"move LEFT");
      copy_piece(pieces[i],p);
      move_piece(p, RIGHT, dist);
      if (is_horizontal(pieces[i]))
        result = result && test_equality_int(get_x(pieces[i])+dist,get_x(p),"move RIGHT");
      else
        result = result && test_equality_int(get_x(pieces[i]),get_x(p),"move RIGHT");
      copy_piece(pieces[i],p);
      move_piece(p, UP, dist);
      if (!is_horizontal(pieces[i]))
        result = result && test_equality_int(get_y(pieces[i])+dist,get_y(p),"move UP");
      else
        result = result && test_equality_int(get_y(pieces[i]),get_y(p),"move UP");
      copy_piece(pieces[i],p);
      move_piece(p, DOWN, dist);
      if (!is_horizontal(pieces[i]))
        result = result && test_equality_int(get_y(pieces[i])-dist,get_y(p),"move DOWN");
      else
        result = result && test_equality_int(get_y(pieces[i]),get_y(p),"move DOWN");
    }
  tear_down();
  delete_piece(p);
  return result;
}
예제 #3
0
bool test_copy() {
  piece p = new_piece_rh(0, 0, true, true);
  bool result = true;
  set_up();
  for (int i = 0 ; i < NB_PIECES; i++) {
    copy_piece(pieces[i],p);
    result = result && test_equality_int(get_height(pieces[i]), get_height(p), "copy get_height");
    result = result && test_equality_int(get_width(pieces[i]), get_width(p), "copy get_width");
    result = result && test_equality_int(get_x(pieces[i]), get_x(p), "copy get_x");
    result = result && test_equality_int(get_y(pieces[i]), get_y(p), "copy get_y");
    result = result && test_equality_bool(is_horizontal(pieces[i]), is_horizontal(p), "copy is_horizontal");
  }
  tear_down();
  delete_piece(p);
  return result;
}
예제 #4
0
bool test_move() {
  bool result = true;
  
  piece p = new_piece(0, 0, 2, 1, true, false); //move_x-> TRUE, move_y->FALSE
  set_up();
  
  for (int dist = 1; dist < NB_PIECES; dist++)
    for (int i=0; i < NB_PIECES; i++) {

      // Test move LEFT
      copy_piece(pieces[i],p);
      move_piece(p, LEFT, dist);

      if (can_move_x(pieces[i]))
        result = result && test_equality_int(get_x(pieces[i])-dist,get_x(p),"move LEFT");
      else
        result = result && test_equality_int(get_x(pieces[i]),get_x(p),"move LEFT");

      // Test move RIGHT
      copy_piece(pieces[i],p);
      move_piece(p, RIGHT, dist);
      
      if (can_move_x(pieces[i]))
        result = result && test_equality_int(get_x(pieces[i])+dist,get_x(p),"move RIGHT");
      else
        result = result && test_equality_int(get_x(pieces[i]),get_x(p),"move RIGHT");

      // Test move UP
      copy_piece(pieces[i],p);
      move_piece(p, UP, dist);
      
      if (can_move_y(pieces[i]))
        result = result && test_equality_int(get_y(pieces[i])+dist,get_y(p),"move UP");
      else
        result = result && test_equality_int(get_y(pieces[i]),get_y(p),"move UP");

      // Test move DOWN
      copy_piece(pieces[i],p);
      move_piece(p, DOWN, dist);
      
      if (can_move_y(pieces[i]))
        result = result && test_equality_int(get_y(pieces[i])-dist,get_y(p),"move DOWN");
      else
        result = result && test_equality_int(get_y(pieces[i]),get_y(p),"move DOWN");

    }
  
  tear_down();
  delete_piece(p);
  
  return result;
}
예제 #5
0
bool test_copy() {
  bool result = true;
  
  piece p = new_piece(0, 0, 2, 1, true, false);

  set_up();
  for (int i = 0 ; i < NB_PIECES; i++) {
    copy_piece(pieces[i],p);
    result = result && test_equality_int(get_height(pieces[i]), get_height(p), "copy get_height");
    result = result && test_equality_int(get_width(pieces[i]), get_width(p), "copy get_width");
    result = result && test_equality_int(get_x(pieces[i]), get_x(p), "copy get_x");
    result = result && test_equality_int(get_y(pieces[i]), get_y(p), "copy get_y");
    result = result && test_equality_bool(can_move_x(pieces[i]), can_move_x(p), "copy can_move_x");
    result = result && test_equality_bool(can_move_y(pieces[i]), can_move_y(p), "copy can_move_y");
  }
  
  tear_down();
  delete_piece(p);
  
  return result;
}
예제 #6
0
bool test_new_piece_rh() {
  bool result = true;
  for (int x= 0 ; x < 5; x++)
    for (int y= 0 ; y < 5; y++)
      for (bool small=false; !small ; small= !small)
        for (bool horizontal=false; !horizontal ; horizontal= !horizontal) {
          if((y>=4 && !horizontal && !small) || (x>=4 && horizontal && !small)){
            break; 
            /**
             * without this condition and the break, 
             * the program is going to create pieces outside of the board. 
             * It would activate a security in the function new_piece_rh
             */
          }
          int size;
          if (small)
            size = 2;
          else
            size = 3;
          piece p = new_piece_rh(x, y, small, horizontal);
          result = result && test_equality_int(x, get_x(p),"get_x");
          result = result && test_equality_int(y, get_y(p),"get_y");

          if (horizontal) {
            result = result && test_equality_int(1, get_height(p), "get_height");
            result = result && test_equality_int(size, get_width(p), "get_width");
          }
          else {
            result = result && test_equality_int(size, get_height(p), "get_height");
            result = result && test_equality_int(1, get_width(p), "get_width");
          }
          delete_piece(p);
        }
  return result;
}
예제 #7
0
bool test_new_piece() {
  bool result = true;
  for (int x= 0 ; x < 5; x++)
    for (int y= 0 ; y < 5; y++)
      for (bool small=false; !small ; small= !small)
        for (bool horizontal=false; !horizontal ; horizontal= !horizontal) {
          int size;
          if (small)
            size = 2;
          else
            size = 3;
          piece p = new_piece_rh(x, y, small, horizontal);
          result = result && test_equality_int(x, get_x(p),"get_x");
          result = result && test_equality_int(y, get_y(p),"get_y");
          if (horizontal) {
            result = result && test_equality_int(1, get_height(p), "get_height");
            result = result && test_equality_int(size, get_width(p), "get_width");
          }
          else {
            result = result && test_equality_int(size, get_height(p), "get_height");
            result = result && test_equality_int(1, get_width(p), "get_width");
          }
          delete_piece(p);
        }
  return result;
}
예제 #8
0
bool test_new_piece() {
  bool result = true;

  for(int y = 0; y < 5; y++){
    for(int x = 0; x < 5; x++){

      for(bool move_y = false; !move_y; move_y = !move_y){
	for(bool move_x = false; !move_x; move_x = !move_x){

	  int sizeX = 5 - x;
	  int sizeY = 5 - y;

	  piece p = new_piece(x, y, sizeX, sizeY, move_x, move_y);

	  // Test coordonnées de p
	  result = result && test_equality_int(x, get_x(p), "get_x");
	  result = result && test_equality_int(y, get_y(p), "get_y");

	  // Test hauteur/largeur de p
	  result = result && test_equality_int(sizeY, get_height(p), "get_height");
          result = result && test_equality_int(sizeX, get_width(p), "get_width");

	  // Test mouvement sur x
	  result = result && test_equality_bool(move_x, can_move_x(p), "move_x");

	  // Test mouvement sur y
	  result = result && test_equality_bool(move_y, can_move_y(p), "move_y");

	  delete_piece(p);
	}
      }
      
    }
  }
  return result;
}
예제 #9
0
int main(int argc, char *argv[])
{
    bool result = true;
    piece no_piece = NULL;

    printf("result of test error\n");
    test_equality_int(0, 1, "error test_equality_int ");
    test_equality_bool(true, false, "error test_equality_bool ");
    test_failure_piece(no_piece);
    printf("----------------------------------------------------------\n");
    delete_piece(no_piece);
    result = result && test_equality_bool(true, test_new_piece(), "new_piece");
    result = result && test_equality_bool(true, test_intersect(), "intersect");
    result = result && test_equality_bool(true, test_move(), "move");
    result = result && test_equality_bool(true, test_copy(), "copy");


    if (result) {
        printf("Youpi !\n");
        return EXIT_SUCCESS;
    } else
        return EXIT_FAILURE;
}
예제 #10
0
bool test_new_piece()
{
    bool result = true;
    for (int x = 0; x < 5; x++) {
        for (int y = 0; y < 5; y++) {
            for (int compt_small = 0; compt_small < 2; ++compt_small) {
                for (int compt_horizontal = 0; compt_horizontal < 2; ++compt_horizontal) {
                    int size;
                    bool small;
                    bool horizontal;

                    if (compt_small == 0) {
                        small = true;
                        size = 2;
                    } else {
                        small = false;
                        size = 3;
                    }

                    if (compt_horizontal == 0)
                        horizontal = true;
                    else
                        horizontal = false;

                    piece p = new_piece_rh(x, y, small, horizontal);
                    result = result && test_equality_int(x, get_x(p), "get_x");
                    result = result && test_equality_int(y, get_y(p), "get_y");
                    if (horizontal) {
                        result = result && test_equality_int(1, get_height(p), "get_height");
                        result = result && test_equality_int(size, get_width(p), "get_width");
                        result = result && test_equality_bool(true, can_move_x(p), "can_move_x");
                        result = result && test_equality_bool(false, can_move_y(p), "can_move_y");
                    } else {
                        result = result && test_equality_int(size, get_height(p), "get_height");
                        result = result && test_equality_int(1, get_width(p), "get_width");
                        result = result && test_equality_bool(false, can_move_x(p), "can_move_x");
                        result = result && test_equality_bool(true, can_move_y(p), "can_move_y");
                    }
                    delete_piece(p);
                }
            }
            for (int width = 1; width < 4; width++) {
                for (int height = 1; height < 4; height++) {
                    for (int compt_move_x = 0; compt_move_x < 2; ++compt_move_x) {
                        for (int compt_move_y = 0; compt_move_y < 2; ++compt_move_y) {
                            bool move_x;
                            bool move_y;

                            if (compt_move_x == 0)
                                move_x = true;
                            else
                                move_x = false;

                            if (compt_move_y == 0)
                                move_y = true;
                            else
                                move_y = false;

                            piece p = new_piece(x, y, width, height, move_x, move_y);

                            result = result && test_equality_int(x, get_x(p), "get_x");
                            result = result && test_equality_int(y, get_y(p), "get_y");
                            result = result && test_equality_int(height, get_height(p), "get_height");
                            result = result && test_equality_int(width, get_width(p), "get_width");
                            if (move_x)
                                result = result && test_equality_bool(true, can_move_x(p), "can_move_x");
                            else
                                result = result && test_equality_bool(false, can_move_x(p), "not can_move_x");
                            if (move_y)
                                result = result && test_equality_bool(true, can_move_y(p), "can_move_y");
                            else
                                result = result && test_equality_bool(false, can_move_y(p), "not can_move_y");

                            delete_piece(p);
                        }
                    }
                }
            }
        }
    }
    return result;
}
예제 #11
0
bool test_move()
{
    bool result = true;
    piece p = new_piece_rh(0, 0, true, true);

    //the first one (set_up_1()) is with new_piece_rh (int x, int y, bool small, bool horizontal)
    set_up_1();
    for (int dist = 1; dist < NB_PIECES; dist++)
        for (int i = 0; i < NB_PIECES; i++) {
            copy_piece(pieces[i], p);
            move_piece(p, LEFT, dist);
            if (is_horizontal(pieces[i]))
                result = result && test_equality_int(get_x(pieces[i]) - dist, get_x(p), "move LEFT");
            else
                result = result && test_equality_int(get_x(pieces[i]), get_x(p), "move LEFT");
            copy_piece(pieces[i], p);
            move_piece(p, RIGHT, dist);
            if (is_horizontal(pieces[i]))
                result = result && test_equality_int(get_x(pieces[i]) + dist, get_x(p), "move RIGHT");
            else
                result = result && test_equality_int(get_x(pieces[i]), get_x(p), "move RIGHT");
            copy_piece(pieces[i], p);
            move_piece(p, UP, dist);
            if (!is_horizontal(pieces[i]))
                result = result && test_equality_int(get_y(pieces[i]) + dist, get_y(p), "move UP");
            else
                result = result && test_equality_int(get_y(pieces[i]), get_y(p), "move UP");
            copy_piece(pieces[i], p);
            move_piece(p, DOWN, dist);
            if (!is_horizontal(pieces[i]))
                result = result && test_equality_int(get_y(pieces[i]) - dist, get_y(p), "move DOWN");
            else
                result = result && test_equality_int(get_y(pieces[i]), get_y(p), "move DOWN");
        }
    tear_down();

    //the second one (set_up_2()) is with new_piece(int x, int y, int width, int height, bool move_x, bool move_y)
    set_up_2();
    for (int dist = 1; dist < NB_PIECES; dist++)
        for (int i = 0; i < NB_PIECES; i++) {
            copy_piece(pieces[i], p);
            move_piece(p, LEFT, dist);
            if (is_horizontal(pieces[i]))
                result = result && test_equality_int(get_x(pieces[i]) - dist, get_x(p), "move LEFT");
            else
                result = result && test_equality_int(get_x(pieces[i]), get_x(p), "move LEFT");
            copy_piece(pieces[i], p);
            move_piece(p, RIGHT, dist);
            if (is_horizontal(pieces[i]))
                result = result && test_equality_int(get_x(pieces[i]) + dist, get_x(p), "move RIGHT");
            else
                result = result && test_equality_int(get_x(pieces[i]), get_x(p), "move RIGHT");
            copy_piece(pieces[i], p);
            move_piece(p, UP, dist);
            if (!is_horizontal(pieces[i]))
                result = result && test_equality_int(get_y(pieces[i]) + dist, get_y(p), "move UP");
            else
                result = result && test_equality_int(get_y(pieces[i]), get_y(p), "move UP");
            copy_piece(pieces[i], p);
            move_piece(p, DOWN, dist);
            if (!is_horizontal(pieces[i]))
                result = result && test_equality_int(get_y(pieces[i]) - dist, get_y(p), "move DOWN");
            else
                result = result && test_equality_int(get_y(pieces[i]), get_y(p), "move DOWN");
        }
    tear_down();

    delete_piece(p);
    return result;
    return false;
}