-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_project.py
More file actions
43 lines (35 loc) · 1.13 KB
/
test_project.py
File metadata and controls
43 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from project import calculate_new_head_position, generate_new_food_position, update_game
import pytest
from unittest.mock import patch
def test_update_game():
# Arrange
with patch('module_where_function_is.calculate_new_head_position', return_value=(10, 10)):
global food_position
food_position = (10, 10)
# Act
update_game()
# Assert
# Check that a new food position was generated
assert food_position != (10, 10)
def test_generate_new_food_position():
# Act
position = generate_new_food_position()
# Assert
# Check that a tuple was returned
assert isinstance(position, tuple)
# Check that the tuple has two elements
assert len(position) == 2
# Check that the elements are within the expected range
assert 0 <= position[0] < 40
assert 0 <= position[1] < 30
def test_calculate_new_head_position():
# Arrange
global direction
direction = 'up'
global snake
snake = [(10, 10)]
# Act
position = calculate_new_head_position()
# Assert
# Check that the y-coordinate decreased by 1
assert position == (10, 9)