File tree Expand file tree Collapse file tree 3 files changed +53
-3
lines changed
Expand file tree Collapse file tree 3 files changed +53
-3
lines changed Original file line number Diff line number Diff line change 1+ from survey import AnonymousSurvey
2+
3+ question = "What language did you first learn to speak ? "
4+ my_survey = AnonymousSurvey (question )
5+
6+ my_survey .show_question ()
7+ print ("Enter 'q' to quit it." )
8+
9+ while True :
10+ response = input ("Language: " )
11+ if response == 'q' :
12+ break
13+ my_survey .store_response (response )
14+
15+ print ("Thank you for participating in the survey " )
16+ my_survey .show_results ()
Original file line number Diff line number Diff line change @@ -4,11 +4,18 @@ class AnonymousSurvey:
44 def __init__ (self , question ):
55 """ Store a qiestion and prepare to store the response """
66 self .question = question
7- self .response = []
8-
7+ self .responses = []
8+
99 def show_question (self ):
1010 """ to show the question of the survey """
1111 print (self .question )
1212
13+ def store_response (self , new_response ):
14+ """ storing the responses from the input """
15+ self .responses .append (new_response )
1316
14-
17+ def show_results (self ):
18+ """ Showing the result """
19+ print ("Survey results: " )
20+ for response in self .responses :
21+ print (f"- { response } " )
Original file line number Diff line number Diff line change 1+ import unittest
2+ from survey import AnonymousSurvey
3+
4+
5+ class TestAnonymousSurvey (unittest .TestCase ):
6+ """Tests for the class Anonymous Survey"""
7+
8+ def setUp (self ):
9+ """ set up survey and responses for further uses """
10+ question = "What language did you first learn to speak ?"
11+ self .my_survey = AnonymousSurvey (question )
12+ self .responses = ['English' , 'Spanish' , 'Mandarin' ]
13+
14+ def test_store_single_responses (self ):
15+ """ Single response testing """
16+ self .my_survey .store_response (self .responses [0 ])
17+ self .assertIn (self .responses [0 ], self .my_survey .responses )
18+
19+ def test_store_triple_responses (self ):
20+ """ Triple response testing """
21+ for response in self .responses :
22+ self .my_survey .store_response (response )
23+ self .assertIn (response , self .my_survey .responses )
24+
25+
26+ if __name__ == "__main__" :
27+ unittest .main ()
You can’t perform that action at this time.
0 commit comments