Skip to content

Commit

Permalink
added first unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
K0ntr4 committed Apr 10, 2024
1 parent 44c4d6f commit cda1ebb
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/game_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
nltk.download('punkt', quiet=True)
nltk.download('averaged_perceptron_tagger', quiet=True)

CURRENT_YEAR = int(time.strftime('%Y', time.gmtime(time.time())))
DATE_RECENCY = {
'newest': (2021, int(time.strftime('%Y', time.gmtime(time.time())))),
'recent': (2018, 2020),
Expand Down
76 changes: 76 additions & 0 deletions tests/test_game_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import time
import unittest
from unittest.mock import patch, MagicMock
import sys
import os

# Add the src directory to the Python path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../src')))

# Import the module to be tested
from game_info import GameInfo, get_year_recency, get_summary_keywords, is_relevant_adjective


class TestGameInfo(unittest.TestCase):
def setUp(self):
self.game_info = GameInfo()

def test_authenticate(self):
self.game_info.authenticate()
self.assertIsNotNone(self.game_info.token)
self.assertIsNotNone(self.game_info.authentication_time)
self.assertTrue(time.time() - self.game_info.authentication_time < self.game_info.token['expires_in'])

def test_get_game_info(self):
# Call the method under test
game_data = self.game_info.get_game_info('Tekken 7')

# Assertions
self.assertIsNotNone(game_data)
self.assertEqual(game_data['name'], 'Tekken 7')
self.assertEqual(game_data['first_release_date'], 1424217600)
self.assertEqual(game_data['genres'], [4])
self.assertEqual(game_data['summary'], 'Experience the epic conclusion of the Mishima clan and unravel the '
'reasons behind each step of their ceaseless fight. Powered by Unreal '
'Engine 4, Tekken 7 features stunning story-driven cinematic battles '
'and intense duels that can be enjoyed with friends and rivals alike '
'through innovative fight mechanics.')

def test_get_genres(self):
genres = self.game_info.get_genres([4])
self.assertEqual(genres, ['Fighting'])

def test_get_game_keywords(self):
keywords = self.game_info.get_game_keywords('Tekken 7')
self.assertIsNotNone(keywords)
self.assertEqual(keywords[0], 'mid')
# The order of the keywords may vary
self.assertIn('Fighting', keywords[1])

def test_get_year_recency(self):
# right now
self.assertEqual(get_year_recency(time.time()), 'newest')
# 4 years ago
self.assertEqual(get_year_recency(time.time() - 4 * 365 * 24 * 60 * 60), 'recent')
# 7 years ago
self.assertEqual(get_year_recency(time.time() - 7 * 365 * 24 * 60 * 60), 'mid')
# 10 years ago
self.assertEqual(get_year_recency(time.time() - 10 * 365 * 24 * 60 * 60), 'early')
# 15 years ago
self.assertEqual(get_year_recency(time.time() - 15 * 365 * 24 * 60 * 60), 'oldest')

def test_get_summary_keywords(self):
keywords = get_summary_keywords('Experience the epic conclusion of the Mishima clan and unravel the reasons '
'behind each step of their ceaseless fight. Powered by Unreal Engine 4, Tekken 7 '
'features stunning story-driven cinematic battles and intense duels that can be '
'enjoyed with friends and rivals alike through innovative fight mechanics.')
self.assertEqual(keywords,
['Experience', 'epic', 'conclusion', 'clan', 'reasons'])

def test_is_relevant_adjective(self):
self.assertTrue(is_relevant_adjective('epic'))
self.assertFalse(is_relevant_adjective('the'))


if __name__ == '__main__':
unittest.main()

0 comments on commit cda1ebb

Please sign in to comment.