Skip to content

Commit

Permalink
done for the night
Browse files Browse the repository at this point in the history
  • Loading branch information
BenHollamby committed Apr 2, 2021
1 parent 832208f commit dd9879d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Chapter 11/Class Testing/language_survey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#to show that the class works, here is a program
from survey import AnonymousSurvey

question = "What language did you first learn to speak? "
my_survey = AnonymousSurvey(question)

my_survey.show_question()
print("Press enter to quit.\n")
while True:
response = input("Language: ")
if response == '':
break
my_survey.store_response(response)

print("\nThank you for participating!")
my_survey.show_results()
18 changes: 18 additions & 0 deletions Chapter 11/Class Testing/survey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#testing classes
#here is a class that helps administer anonymous serveys
class AnonymousSurvey:

def __init__(self, question):
self.question = question
self.responses = []

def show_question(self):
print(self.question)

def store_response(self, new_response):
self.responses.append(new_response)

def show_results(self):
print("Survey results:")
for response in self.responses:
print(f"- {response}")
25 changes: 25 additions & 0 deletions Chapter 11/Class Testing/test_survey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest
from survey import AnonymousSurvey

class TestAnonymousSurvey(unittest.TestCase):

def test_store_singele_response(self):
question = "What language did you first learn?"
my_survey = AnonymousSurvey(question)
my_survey.store_response('English')
self.assertIn('English', my_survey.responses)

def test_store_three_responses(self):
question = "What language did you first learn?"
my_survey = AnonymousSurvey(question)
responses = ['English', 'Spanish', 'Python']
for response in responses:
my_survey.store_response(response)

for response in responses:
self.assertIn(response, my_survey.responses)

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

#continue on page 297

0 comments on commit dd9879d

Please sign in to comment.