예제 #1
0
void test_piece_move_to_bottom()
{
  TrnPiece expectedBottomPiece = trn_piece_create(TRN_TETROMINO_I,6,3,TRN_ANGLE_0);
  
  TrnPiece piece = trn_piece_create(TRN_TETROMINO_I,5,3,TRN_ANGLE_0);
  trn_piece_move_to_bottom(&piece);
  
  CU_ASSERT( trn_piece_equal(piece,expectedBottomPiece) );
}
예제 #2
0
void test_piece_move_to_right()
{
  TrnPiece expectedRightPiece = trn_piece_create(TRN_TETROMINO_I,5,3,TRN_ANGLE_0);
  
  TrnPiece piece = trn_piece_create(TRN_TETROMINO_I,5,2,TRN_ANGLE_0);
  trn_piece_move_to_right(&piece);
  
  CU_ASSERT( trn_piece_equal(piece,expectedRightPiece) );
}
예제 #3
0
void test_grid_set_cells_with_piece()
{
    // Create a grid.
    int numberOfRows = 10;
    int numberOfColumns = 10;
    TrnGrid* grid = trn_grid_new(numberOfRows, numberOfColumns);

    // Create a piece;
    TrnPiece piece = trn_piece_create(TRN_TETROMINO_I,2,3,TRN_ANGLE_90);
    
    trn_grid_set_cells_with_piece(grid, &piece, piece.type);

    // Create expected grid
    TrnGrid* expected_grid = trn_grid_new(numberOfRows, 
                                          numberOfColumns);
    TrnPositionInGrid pos = {2,5};
    trn_grid_set_cell(expected_grid, pos, TRN_TETROMINO_I);
    pos.rowIndex = 3;
    pos.columnIndex = 5;
    trn_grid_set_cell(expected_grid, pos, TRN_TETROMINO_I);
    pos.rowIndex = 4;
    pos.columnIndex = 5;
    trn_grid_set_cell(expected_grid, pos, TRN_TETROMINO_I);
    pos.rowIndex = 5;
    pos.columnIndex = 5;
    trn_grid_set_cell(expected_grid, pos, TRN_TETROMINO_I);
    
	// Compare grids
	CU_ASSERT_TRUE(trn_grid_equal(grid, expected_grid));
}
예제 #4
0
void test_piece_rotate_clockwise()
{
  TrnPiece expectedPiece0 = trn_piece_create(TRN_TETROMINO_I,5,3,TRN_ANGLE_0);
  TrnPiece expectedPiece90 = trn_piece_create(TRN_TETROMINO_I,5,3,TRN_ANGLE_90);
  TrnPiece expectedPiece180 = trn_piece_create(TRN_TETROMINO_I,5,3,TRN_ANGLE_180);
  TrnPiece expectedPiece270 = trn_piece_create(TRN_TETROMINO_I,5,3,TRN_ANGLE_270);
  
  TrnPiece piece = trn_piece_create(TRN_TETROMINO_I,5,3,TRN_ANGLE_0);

  trn_piece_rotate_clockwise(&piece);
  CU_ASSERT( trn_piece_equal(piece,expectedPiece90) );

  trn_piece_rotate_clockwise(&piece);
  CU_ASSERT( trn_piece_equal(piece,expectedPiece180) );

  trn_piece_rotate_clockwise(&piece);
  CU_ASSERT( trn_piece_equal(piece,expectedPiece270) );

  trn_piece_rotate_clockwise(&piece);
  CU_ASSERT( trn_piece_equal(piece,expectedPiece0) );
}
예제 #5
0
void test_grid_set_cells_with_piece()
{
    // Create a grid.
    int numberOfRows = 10;
    int numberOfColumns = 10;
    TrnGrid* grid = trn_grid_new(numberOfRows, numberOfColumns);

    // Create a piece;
    TrnPiece piece = trn_piece_create(TRN_TETROMINO_I,2,3,TRN_ANGLE_90);

    trn_grid_set_cells_with_piece(grid, &piece, piece.type);

    // The piece position in grid.
    TrnPositionInGrid pos0 = {2,5};
    TrnPositionInGrid pos1 = {3,5};
    TrnPositionInGrid pos2 = {4,5};
    TrnPositionInGrid pos3 = {5,5};
    TrnPositionInGrid pos;

    TrnTetrominoType type;
    TrnTetrominoType expectedType;

    int rowIndex;
    int columnIndex;
    for (rowIndex = 0 ; rowIndex < grid->numberOfRows; rowIndex++) {
        for (columnIndex = 0 ; columnIndex < grid->numberOfColumns ; columnIndex++) {
            pos.rowIndex = rowIndex;
            pos.columnIndex = columnIndex;
            if (trn_position_in_grid_equal(pos, pos0) ||
                trn_position_in_grid_equal(pos, pos1) ||
                trn_position_in_grid_equal(pos, pos2) ||
                trn_position_in_grid_equal(pos, pos3))
            {
                expectedType = TRN_TETROMINO_I;
            } else {
                expectedType = TRN_TETROMINO_VOID;
            }
            type = trn_grid_get_cell(grid,pos);
            CU_ASSERT_EQUAL(type,expectedType);
        }
    }
}
예제 #6
0
void test_piece_position_in_grid()
{
    // Create a piece;
    TrnPiece piece = trn_piece_create(TRN_TETROMINO_I,2,3,TRN_ANGLE_90);

    // Expected result
    TrnPositionInGrid expectedPos0 = {2,5};
    TrnPositionInGrid expectedPos1 = {3,5};
    TrnPositionInGrid expectedPos2 = {4,5};
    TrnPositionInGrid expectedPos3 = {5,5};

    // Actual results
    TrnPositionInGrid pos0 = trn_piece_position_in_grid(&piece,0);
    TrnPositionInGrid pos1 = trn_piece_position_in_grid(&piece,1);
    TrnPositionInGrid pos2 = trn_piece_position_in_grid(&piece,2);
    TrnPositionInGrid pos3 = trn_piece_position_in_grid(&piece,3);

    // Check actual results versus expected.
    CU_ASSERT( trn_position_in_grid_equal(pos0, expectedPos0) );
    CU_ASSERT( trn_position_in_grid_equal(pos1, expectedPos1) );
    CU_ASSERT( trn_position_in_grid_equal(pos2, expectedPos2) );
    CU_ASSERT( trn_position_in_grid_equal(pos3, expectedPos3) );
}
예제 #7
0
void TestGridCanSetCellsWithPiece()
{

    /* Reminder on tetromino_srs_i at TRN_ANGLE_0 and TRN_ANGLE_90:

    T---+---+---+---+
    |   |   |  9|   |   T: topLeftCorner position in grid
    +---+---+---+---+   0: tetromino cells a TRN_ANGLE_0
    | 0 | 0 | 01| 0 |   9: tetromino cells a TRN_ANGLE_90
    +---+---+---+---+
    |   |   |  9|   |
    +---+---+---+---+
    |   |   |  9|   |
    +---+---+---+---+
    */

    // Create a grid.
    int numberOfRows = 10;
    int numberOfColumns = 10;
    TrnGrid* grid = trn_grid_new(numberOfRows, numberOfColumns);

    // For now, the grid has only void cells.

    // Ok, in grid and void.
    TrnPiece piece0 = trn_piece_create(TRN_TETROMINO_I,0,0,TRN_ANGLE_0);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece0) )

    // Ok, still in grid (in the first row).
    TrnPiece piece1 = trn_piece_create(TRN_TETROMINO_I,-1,0,TRN_ANGLE_0);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece1) )

    // No more in grid.
    TrnPiece piece2 = trn_piece_create(TRN_TETROMINO_I,-2,0,TRN_ANGLE_0);
    CU_ASSERT_FALSE( trn_grid_can_set_cells_with_piece(grid, &piece2) )

    // Ok, in grid and void.
    TrnPiece piece3 = trn_piece_create(TRN_TETROMINO_I,5,0,TRN_ANGLE_90);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece3) )

    // Ok, still in grid (in the first column).
    TrnPiece piece4 = trn_piece_create(TRN_TETROMINO_I,5,-2,TRN_ANGLE_90);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece4) )

    // No more in grid.
    TrnPiece piece5 = trn_piece_create(TRN_TETROMINO_I,5,-3,TRN_ANGLE_90);
    CU_ASSERT_FALSE( trn_grid_can_set_cells_with_piece(grid, &piece5) )

    // Now, fill the last grid row with non-void tetrominos.
    TrnPositionInGrid pos;
    int columnIndex;
    pos.rowIndex = numberOfRows-1 ;
    for (columnIndex = 0 ; columnIndex < grid->numberOfColumns ; columnIndex++) {
        pos.columnIndex = columnIndex;
        trn_grid_set_cell(grid, pos, TRN_TETROMINO_I);
    }

    // Ok, in grid and void.
    TrnPiece piece6 = trn_piece_create(TRN_TETROMINO_I,0,0,TRN_ANGLE_90);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece6) )

    // Still in grid and void, just above the non-void row.
    TrnPiece piece7 = trn_piece_create(TRN_TETROMINO_I,numberOfRows-5,0,TRN_ANGLE_90);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece7) )

    // In grid, but last cell of piece overlap a non-void cell of the grid.
    TrnPiece piece8 = trn_piece_create(TRN_TETROMINO_I,numberOfRows-4,0,TRN_ANGLE_90);
    CU_ASSERT_FALSE( trn_grid_can_set_cells_with_piece(grid, &piece8) )
}