Skip to content

Commit 43d5be6

Browse files
committed
unit test, refactored validation logic
1 parent c54a03c commit 43d5be6

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

GAMES/Hacktoberfest Quiz/hacktoberfest-quiz.py renamed to GAMES/Hacktoberfest Quiz/hacktoberfest_quiz.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,40 +61,57 @@ def ask_question(self):
6161
def get_score(self):
6262
return self.score
6363

64-
def evaluate(self):
65-
self.score = 0
66-
67-
question_one_value = question_one.get()
64+
def validate_question_one(self, question_one_value = ''):
6865
if question_one_value.lower()=='python':
6966
self.score += 1
7067
print('correct')
7168
else:
7269
print('Wrong Answer1')
7370
print('correct answer is python ')
74-
75-
question_two_value = question_two.get()
71+
return True if question_one_value.lower()=='python' else False
72+
73+
def validate_question_two(self, question_two_value):
7674
if question_two_value.lower()=='yes':
7775
self.score += 1
7876
print('correct')
7977
else:
8078
print('Wrong Answer2')
8179
print('correct answer is yes ')
80+
return True if question_two_value.lower()=='yes' else False
8281

83-
question_three_value = question_three.get()
82+
def validate_question_three(self, question_three_value):
8483
if question_three_value.lower()=='no':
8584
self.score += 1
8685
print('correct')
8786
else:
88-
print('Wrong Answer3')
89-
print('correct answer is no ')
87+
print('Wrong Answer2')
88+
print('correct answer is no')
89+
return True if question_three_value.lower()=='no' else False
9090

91-
question_four_value = question_four.get()
91+
def validate_question_four(self, question_four_value):
9292
if question_four_value.lower()=='yes':
9393
self.score += 1
9494
print('correct')
9595
else:
96-
print('Wrong Answer4')
97-
print('correct answer is yes ')
96+
print('Wrong Answer2')
97+
print('correct answer is yes')
98+
return True if question_four_value.lower()=='yes' else False
99+
100+
def evaluate(self):
101+
self.score = 0
102+
103+
question_one_value = question_one.get()
104+
self.validate_question_one(question_one_value=question_one_value)
105+
106+
question_two_value = question_two.get()
107+
self.validate_question_two(question_two_value=question_two_value)
108+
109+
question_three_value = question_three.get()
110+
self.validate_question_three(question_three_value=question_three_value)
111+
112+
question_four_value = question_four.get()
113+
self.validate_question_four(question_three_value=question_four_value)
114+
98115

99116
print('Thankyou for Playing the Hacktoberfest quiz game, you attempted',self.score,"questions correctly!")
100117
mark=(self.score/self.total_questions)*100
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest
2+
from hacktoberfest_quiz import Quiz
3+
4+
class TestQuiz(unittest.TestCase):
5+
def test_correct_answer_to_question_one(self):
6+
quiz = Quiz()
7+
self.assertTrue(quiz.validate_question_one('python'))
8+
9+
def test_correct_answer_to_question_two(self):
10+
quiz = Quiz()
11+
self.assertTrue(quiz.validate_question_two('yes'))
12+
13+
def test_correct_answer_to_question_three(self):
14+
quiz = Quiz()
15+
self.assertTrue(quiz.validate_question_three('no'))
16+
17+
def test_correct_answer_to_question_four(self):
18+
quiz = Quiz()
19+
self.assertTrue(quiz.validate_question_four('yes'))
20+
21+
def test_correct_score(self):
22+
pass
23+
24+
if __name__ == "__main__":
25+
unittest.main()

0 commit comments

Comments
 (0)