Skip to content

Commit

Permalink
Feat: Create test_decide_difficulty with different contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
SverreNystad committed Sep 18, 2023
1 parent 4361bfe commit d7951fe
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/test_referee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pytest
from src.referee import Difficulty, decide_difficulty

@pytest.fixture
def TRIVIAL_CONTEXT():
return """
You are trying to walk down the street.
It is good weather and you are wearing comfortable shoes.
The street is flat and there are no obstacles in your way.
"""

@pytest.fixture
def VERY_EASY_CONTEXT():
return """
You try to throw a ball into a basket a few meters away, but the sun is shining in your eyes.
"""

@pytest.fixture
def EASY_CONTEXT():
return """
An easy task.
"""

@pytest.fixture
def MEDIUM_CONTEXT():
return "You are trying to climb a tree. The tree is not very tall and has many branches."

@pytest.fixture
def HARD_CONTEXT():
return "You are trying to climb a tree. The tree is very tall and has few branches."

@pytest.fixture
def NEARLY_IMPOSSIBLE_CONTEXT():
return """
You are trying to climb a tree. In a storm. The tree is very tall and no branches.
The tree is also covered in oil. And you are wearing a heavy backpack.
"""

contexts = [
(TRIVIAL_CONTEXT, Difficulty.TRIVIAL.value, Difficulty.VERY_EASY.value),
(VERY_EASY_CONTEXT, Difficulty.TRIVIAL.value, Difficulty.EASY.value),
(EASY_CONTEXT, Difficulty.VERY_EASY.value, Difficulty.MEDIUM.value),
(MEDIUM_CONTEXT, Difficulty.EASY.value, Difficulty.HARD.value),
(HARD_CONTEXT, Difficulty.MEDIUM.value, Difficulty.NEARLY_IMPOSSIBLE.value)
]

@pytest.mark.apitest
@pytest.mark.parametrize("context, expected_min_difficulty, expected_max_difficulty", contexts)
def test_decide_difficulty(context, expected_min_difficulty, expected_max_difficulty):
# Arrange (already done by the parameters)
# Act
difficulty = decide_difficulty(context)
# Assert
assert difficulty >= expected_min_difficulty, "Difficulty was lower than the minimum"
assert difficulty <= expected_max_difficulty, "Difficulty was higher then the maximum"

0 comments on commit d7951fe

Please sign in to comment.