-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstRoundTests.py
More file actions
60 lines (51 loc) · 2.95 KB
/
Copy pathFirstRoundTests.py
File metadata and controls
60 lines (51 loc) · 2.95 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from Constants import TERMINATED,VALID,SKIPPED
from FirstRound import FirstRound
from Player import Player
from Button import Button
import pygame
import unittest
pygame.init()
class TestFirstRound(unittest.TestCase):
def setUp(self):
self.first_round=FirstRound(Player())
def test_create_interface(self):
self.first_round.random_question = self.first_round._choose_random_question(self.first_round.loaded_data)
self.first_round.correct_answers = self.first_round.random_question["answer(s)"]
original_generated_questions = self.first_round.generated_questions
self.first_round._create_interface()
expected_attributes_for_singleplayer = {
'objects' : [self.first_round.choices_A,self.first_round.choices_B,self.first_round.choices_C,self.first_round.choices_D,self.first_round.skip_button,self.first_round.question_text],
'found_answer' : None,
'generated_questions':original_generated_questions+1
}
for object in self.first_round.objects:
self.assertIsInstance(object,Button)
instance_attributes = vars(self.first_round)
for attr_name, expected_value in expected_attributes_for_singleplayer.items():
self.assertTrue(attr_name in instance_attributes)
self.assertEqual(instance_attributes[attr_name], expected_value)
def test_check_for_correct_answer(self):
self.first_round.found_answer=None
self.assertFalse(self.first_round._check_for_correct_answer())
self.first_round.found_answer=False
self.assertTrue(self.first_round._check_for_correct_answer())
def test_handle_events(self):
self.first_round.random_question=self.first_round._choose_random_question(self.first_round.loaded_data)
quit_event = pygame.event.Event(pygame.QUIT)
self.assertEqual(TERMINATED,self.first_round._handle_events([quit_event]))
pygame.init()
skip_event = pygame.event.Event(pygame.MOUSEBUTTONDOWN)
skip_event.button = 1
self.first_round._create_interface()
skip_event.pos = self.first_round.skip_button.rect.topleft
self.assertEqual(SKIPPED,self.first_round._handle_events([skip_event]))
choice_event = pygame.event.Event(pygame.MOUSEBUTTONDOWN)
choice_event.button=1
choice_event.pos = self.first_round.choices_A.rect.topleft
self.assertEqual(VALID,self.first_round._handle_events([choice_event]))
random_event_1 = pygame.event.Event(pygame.APP_DIDENTERFOREGROUND)
random_event_2 = pygame.event.Event(pygame.CONTROLLER_AXIS_LEFTY)
self.assertEqual(VALID,self.first_round._handle_events([random_event_1,random_event_2]))
self.assertEqual(VALID,self.first_round._handle_events([]))
if __name__ == '__main__':
unittest.main()