Permalink
Browse files

userInterface.py now takes a question object as its parameter. userIn…

…terfaceUnitTest.py has been modified to reflect the change.
  • Loading branch information...
2 parents 4e13c5e + 9b0a2df commit e77dfba81de350bbad5b7b00c8a7f128f742c6a7 @humphriesaj humphriesaj committed Sep 23, 2012
Showing with 76 additions and 13 deletions.
  1. +26 −1 userInterface.py
  2. BIN userInterface.zip
  3. +50 −12 userInterfaceUnitTest.py
View
@@ -5,12 +5,15 @@
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
=======
import dummyQuiz
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
=======
import dummyQuiz
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+>>>>>>> master
import string
class UserInterface:
@@ -21,6 +24,7 @@ class UserInterface:
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
def __init__(self, Question):
# Set _questionObj to the question object passed in.
self._questionObj = Question
@@ -35,14 +39,22 @@ def __init__(self, Quiz):
# there being no questions remaining and that the interface
# was just initialized.
self._questionObj = 1
+=======
+ def __init__(self, Question):
+ # Set _questionObj to the question object passed in.
+ self._questionObj = Question
+>>>>>>> master
# This is an index of the alphabet when set.
- self._userAnswer = -1
+ self._userAnswer = None
self._alphabet = string.ascii_lowercase
+<<<<<<< HEAD
self._quiz = Quiz
<<<<<<< HEAD
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
=======
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+>>>>>>> master
def _formatChoice(self, choiceIndex, choiceText):
"""Returns a string with the appropriate letter and formatting
@@ -54,6 +66,7 @@ def _formatChoice(self, choiceIndex, choiceText):
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
def _updateQuestion(self, newQuestion):
"""Updates self._questionObj to be the next question object
from the quiz. This new question is passed as a parameter
@@ -70,12 +83,20 @@ def _updateQuestion(self):
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
=======
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+ def _updateQuestion(self, newQuestion):
+ """Updates self._questionObj to be the next question object
+ from the quiz. This new question is passed as a parameter
+ which is a question object."""
+ self._questionObj = newQuestion
+>>>>>>> master
# This is to prevent the same answer from being submitted
# without the user specifying so.
self._userAnswer = None
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
def updateQuestion(self, newQuestion):
self._updateQuestion(newQuestion)
=======
@@ -86,6 +107,10 @@ def updateQuestion(self):
def updateQuestion(self):
self._updateQuestion()
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+ def updateQuestion(self, newQuestion):
+ self._updateQuestion(newQuestion)
+>>>>>>> master
def welcome(self):
"""Welcomes the user to the quiz."""
View
Binary file not shown.
View
@@ -9,10 +9,14 @@ class Question:
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
+=======
+>>>>>>> master
def __init__(self, questionText, choices, answer):
self._questionText = questionText
self._choices = choices
self._answer = answer
+<<<<<<< HEAD
def getQuestionText(self):
return self._questionText
@@ -27,24 +31,17 @@ def getAnswer(self):
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
def __init__(self, questionIndx):
self._questionIndx = questionIndx
+=======
+>>>>>>> master
def getQuestionText(self):
- if self._questionIndx == 0:
- return "This is my dummy question. How are you?"
- elif self._questionIndx == 1:
- return "How much is a Diet Coke in the vending machine in the student lounge of Olin?"
- elif self._questionIndx == 2:
- return "What is the name of the supercomputer that two Wofford students who graduated in the past two years work on now?"
+ return self._questionText
def getChoices(self):
- if self._questionIndx == 0:
- return ("Very well. I thank you.", "Not well. Call tomorrow.", "Alright, I guess.", "That's trash.")
- elif self._questionIndx == 1:
- return ("$1.50", "$1.00", "$1.35", "$1.45", "$1.75")
- elif self._questionIndx == 2:
- return ("Kraken", "Sequoia", "Jaguar")
+ return self._choices
def getAnswer(self):
+<<<<<<< HEAD
if self._questionIndx == 0:
# The answer is "That's trash"
return 3
@@ -59,6 +56,9 @@ def getAnswer(self):
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
=======
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+ return self._answer
+>>>>>>> master
class Quiz:
"""A dummy Quiz object used for testing userInterface.py"""
@@ -87,6 +87,9 @@ def getQuestion(self):
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
+=======
+>>>>>>> master
def _makeQuestion(indx):
"""This is used to make a new question to pass to the interface. The
code here does not reflect the functions behind creating new
@@ -111,6 +114,7 @@ def _makeQuestion(indx):
# Make the Question object.
_questionObj = _makeQuestion(indx)
+<<<<<<< HEAD
# Make the interface object.
_interfaceObj = userInterface.UserInterface(_questionObj)
=======
@@ -124,6 +128,10 @@ def _makeQuestion(indx):
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
=======
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+# Make the interface object.
+_interfaceObj = userInterface.UserInterface(_questionObj)
+>>>>>>> master
# My own alphabet string for testing.
_alphabet = "abcdefghijklmnopqrstuvwxyz"
@@ -132,6 +140,7 @@ def initTest():
properly."""
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
assert type(_interfaceObj._questionObj) == type(_makeQuestion(indx))
assert _interfaceObj._userAnswer == None
assert _interfaceObj._alphabet == _alphabet
@@ -146,6 +155,11 @@ def initTest():
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
=======
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+ assert type(_interfaceObj._questionObj) == type(_makeQuestion(indx))
+ assert _interfaceObj._userAnswer == None
+ assert _interfaceObj._alphabet == _alphabet
+>>>>>>> master
print("initTest() ran successfully")
def formatChoiceTest():
@@ -174,6 +188,7 @@ def interfaceTest():
_interfaceObj.welcome()
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
# Update the question.
_interfaceObj.updateQuestion(_makeQuestion(indx))
# Assert that there is a question object in the interface object's
@@ -192,6 +207,14 @@ def interfaceTest():
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
=======
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+ # Update the question.
+ _interfaceObj.updateQuestion(_makeQuestion(indx))
+ # Assert that there is a question object in the interface object's
+ # class variables.
+ assert type(_interfaceObj._questionObj) == \
+ type(_makeQuestion(indx))
+>>>>>>> master
# We have 3 test quesitons
for i in range(3):
_interfaceObj.displayQuestion()
@@ -209,12 +232,16 @@ def interfaceTest():
"for your response.")
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
+=======
+>>>>>>> master
# Update the question for the next test. TODO: This needs to
# be changed.
# This is only for testing purposes.
global indx
indx += 1
_interfaceObj.updateQuestion(_makeQuestion(indx))
+<<<<<<< HEAD
=======
# Update the question for the next test.
_interfaceObj.updateQuestion()
@@ -223,6 +250,8 @@ def interfaceTest():
# Update the question for the next test.
_interfaceObj.updateQuestion()
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+>>>>>>> master
# Call the function indicating that the quiz is over.
_interfaceObj.endOfQuiz()
print("interfaceTest() ran successfully")
@@ -232,6 +261,7 @@ def resetGlobals():
initialized to be."""
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
global _questionObj
global _interfaceObj
global indx
@@ -249,6 +279,14 @@ def resetGlobals():
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
=======
>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+ global _questionObj
+ global _interfaceObj
+ global indx
+ indx = 0
+ _questionObj = _makeQuestion(indx)
+ _interfaceObj = userInterface.UserInterface(_questionObj)
+>>>>>>> master
# The _alphabet variable should never have changed.
def runAll():

0 comments on commit e77dfba

Please sign in to comment.