Browse Source

Test detect not valid tile

remotes/origin/David
David Moeller 11 months ago
parent
commit
1997f08482
  1. 11
      src/main/c/Minesweeper/minesweeper_start.c
  2. 4
      src/main/c/Minesweeper/minesweeper_start.h
  3. 24
      test/Minesweeper/test_is_Valid_tile.c

11
src/main/c/Minesweeper/minesweeper_start.c

@ -247,16 +247,17 @@ void open_empty_space(Minesweeper_Board *board, int tile, int index){
}
}
int is_Valid_tile(Minesweeper_Board *board, int tile, int i){
//0 = up-left, 1 = down-left, 2 = mid-left, 3 = up-mid, 4 = down-mid, 5 = mid-right, 6 = up-right, 7 = down-right
int is_Valid_tile(Minesweeper_Board *board, int tile, int direction){
int check_tile = tile;
if(i < 3){if(tile % board->width == 0){return -1;}
if(direction < 3){if(tile % board->width == 0){return -1;}
else{check_tile -= 1;}}
if(i > 4){if(tile % board->width + 1 == board->width){return -1;}
if(direction > 4){if(tile % board->width + 1 == board->width){return -1;}
else{check_tile += 1;}}
if(i % 3 == 0){if(tile / board->width == 0){return -1;}
if(direction % 3 == 0){if(tile / board->width == 0){return -1;}
else{check_tile -= board->width;}}
if(i % 3 == 1){if(tile / board->width + 1 == height){return -1;}
if(direction % 3 == 1){if(tile / board->width + 1 == height){return -1;}
else{check_tile += board->width;}}
return check_tile;

4
src/main/c/Minesweeper/minesweeper_start.h

@ -1,5 +1,6 @@
#ifndef MINESWEEPER_START_H
#define MINESWEEPER_START_H
#include <stdbool.h>
typedef struct Minesweeper_Board{
unsigned int width;
@ -10,11 +11,10 @@ typedef struct Minesweeper_Board{
int *bombs;
}Minesweeper_Board;
void minesweeper_start();
Minesweeper_Board initialize_minesweeper();
bool array_contains_value(int *array, int bomb, int length);
int number_of_bombs(Minesweeper_Board *board, int tile);
int is_Valid_tile(Minesweeper_Board *board, int tile, int direction);
#endif // MINESWEEPER_START_H

24
test/Minesweeper/test_is_Valid_tile.c

@ -0,0 +1,24 @@
#ifdef TEST
#include "unity.h"
#include "../../src/main/c/Minesweeper/minesweeper_start.h"
void setUp(void){}
void tearDown(void){}
void test_detect_not_valid_tile(void){
/* arrange */
Minesweeper_Board board = initialize_minesweeper();
int tile = 0;
int direction = 1;
int result;
/* act */
result = is_Valid_tile(&board, tile, direction);
/* assert */
TEST_ASSERT_EQUAL_INT(-1, result);//not valid tile
}
#endif // TEST
Loading…
Cancel
Save