I am currently learning how to use the unittest module. I have a minesweeper like board as an object in the form of the class below:
class Grid:
''' class to represent grid sizes. '''
def __init__(self, width: int, height: int, margin: int, rows: int, columns: int):
'''
width: int, in pixels
height: int, in pixels
margin: int, in pixels
row: number of squares along y axis
columns: number of square along x axis
'''
self.width = width
self.height = height
self.margin = margin
self.rows = rows
self.columns = columns
self.grid = [[0 for _ in range(self.columns)] for _ in range(self.rows)]
def gridDraw(self):
'''draws the grid for the game board'''
for row in range(self.rows):
for column in range(self.columns):
color = white.rgb()
if self.grid[row][column] == 1:
color = green.rgb()
pygame.draw.rect(screen,
color,
[(self.margin + self.width) * column + self.margin,
(self.margin + self.height) * row + self.margin,
self.width,
self.height])
def size(self):
'''returns width, height, margin values '''
return(self.width, self.height, self.margin, self.rows, self.columns)
def gridVal(self):
'''returns grid value'''
return(self.grid)
My question is, how could I go about doing unit tests on this gridDraw method? It doesn't really fall under how I would normally test outputs with assertEqual() functions and the like. My test class is as follows thus far:
class GridTest(unit.TestCase):
def test_gridDraw(self):
def test_size(self):
def test_gridVal(self):
Aucun commentaire:
Enregistrer un commentaire