Permalink
Browse files

Merge pull request #11 from sykesda/userInterface

User interface
  • Loading branch information...
strasburgerad committed Sep 23, 2012
2 parents 5496f1e + 4e13c5e commit d924f6f0c80d616ea90bf0186afeba0523fdc842
Showing with 159 additions and 0 deletions.
  1. +46 −0 userInterface.py
  2. +113 −0 userInterfaceUnitTest.py
View
@@ -3,7 +3,14 @@
__author__ = "Tony Humphries"
__date__ = "09/17/12"
+<<<<<<< HEAD
+<<<<<<< HEAD
+=======
import dummyQuiz
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+import dummyQuiz
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
import string
class UserInterface:
@@ -12,6 +19,17 @@ class UserInterface:
possible answers as well as displaying whether the answer given was
correct or incorrect. Special dependencies include ..."""
+<<<<<<< HEAD
+<<<<<<< HEAD
+ def __init__(self, Question):
+ # Set _questionObj to the question object passed in.
+ self._questionObj = Question
+ # This is an index of the alphabet when set.
+ self._userAnswer = None
+ self._alphabet = string.ascii_lowercase
+=======
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
def __init__(self, Quiz):
# We choose 1 instead of None here to differentiate between
# there being no questions remaining and that the interface
@@ -21,6 +39,10 @@ def __init__(self, Quiz):
self._userAnswer = -1
self._alphabet = string.ascii_lowercase
self._quiz = Quiz
+<<<<<<< HEAD
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
def _formatChoice(self, choiceIndex, choiceText):
"""Returns a string with the appropriate letter and formatting
@@ -30,16 +52,40 @@ def _formatChoice(self, choiceIndex, choiceText):
alphabet."""
return self._alphabet[choiceIndex]+".)\t"+choiceText
+<<<<<<< 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
+ which is a question object."""
+ self._questionObj = newQuestion
+=======
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
def _updateQuestion(self):
"""Updates self._questionObj to be the next question object
from the quiz."""
self._questionObj = self._quiz.getQuestion()
+<<<<<<< HEAD
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
# This is to prevent the same answer from being submitted
# without the user specifying so.
self._userAnswer = None
+<<<<<<< HEAD
+<<<<<<< HEAD
+ def updateQuestion(self, newQuestion):
+ self._updateQuestion(newQuestion)
+=======
+ def updateQuestion(self):
+ self._updateQuestion()
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
def updateQuestion(self):
self._updateQuestion()
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
def welcome(self):
"""Welcomes the user to the quiz."""
View
@@ -7,6 +7,24 @@
class Question:
"""A dummy class used to return values for testing userInterface.py"""
+<<<<<<< HEAD
+<<<<<<< HEAD
+ def __init__(self, questionText, choices, answer):
+ self._questionText = questionText
+ self._choices = choices
+ self._answer = answer
+
+ def getQuestionText(self):
+ return self._questionText
+
+ def getChoices(self):
+ return self._choices
+
+ def getAnswer(self):
+ return self._answer
+=======
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
def __init__(self, questionIndx):
self._questionIndx = questionIndx
@@ -37,6 +55,10 @@ def getAnswer(self):
# The answer is "Kraken"
return 0
+<<<<<<< HEAD
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
class Quiz:
"""A dummy Quiz object used for testing userInterface.py"""
@@ -63,20 +85,67 @@ def getQuestion(self):
import userInterface
import string
+<<<<<<< HEAD
+<<<<<<< HEAD
+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
+ questions. It is for testing only. The function gets the question
+ based on indices 0, 1, or 2."""
+
+ if indx == 0:
+ # The answer is at index 3 of the tuple of choices.
+ return Question("This is my dummy question. How are you?", \
+ ("Fine, thank you.", "Not well.", \
+ "Why are you asking?", "That's trash."), 3)
+ elif indx == 1:
+ # The answer is at index 2
+ return Question("How much is a diet coke in the Student Lounge in the Olin building at Wofford?", \
+ ("$1.75", "$1.00", "$1.35", "$1.50", "$1.25"), 2)
+ elif indx == 2:
+ # The answer is at index 0
+ return Question("What is the name of the supercomputer that two Wofford students who graduated in the past two years work on today?", \
+ ("Kraken", "Sequoia", "Jaguar"), 0)
+# This is only used for testing
+indx = 0
+
+# Make the Question object.
+_questionObj = _makeQuestion(indx)
+# Make the interface object.
+_interfaceObj = userInterface.UserInterface(_questionObj)
+=======
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
# Make the Quiz object.
_quizObj = Quiz()
# Make the interface object.
_interfaceObj = userInterface.UserInterface(_quizObj)
+<<<<<<< HEAD
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
# My own alphabet string for testing.
_alphabet = "abcdefghijklmnopqrstuvwxyz"
def initTest():
"""This test asserts that the interface has been initialized
properly."""
+<<<<<<< HEAD
+<<<<<<< HEAD
+ assert type(_interfaceObj._questionObj) == type(_makeQuestion(indx))
+ assert _interfaceObj._userAnswer == None
+ assert _interfaceObj._alphabet == _alphabet
+=======
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
assert _interfaceObj._questionObj == 1
assert _interfaceObj._userAnswer == -1
assert _interfaceObj._alphabet == _alphabet
assert type(_interfaceObj._quiz) == type(Quiz())
+<<<<<<< HEAD
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
print("initTest() ran successfully")
def formatChoiceTest():
@@ -103,11 +172,26 @@ def interfaceTest():
tester."""
# Welcome the user.
_interfaceObj.welcome()
+<<<<<<< HEAD
+<<<<<<< HEAD
+ # 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))
+=======
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
_interfaceObj.updateQuestion()
# Assert that there is a question object in the interface object's
# class variables.
assert type(_interfaceObj._questionObj) == \
type(Question(0))
+<<<<<<< HEAD
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
# We have 3 test quesitons
for i in range(3):
_interfaceObj.displayQuestion()
@@ -123,19 +207,48 @@ def interfaceTest():
print("DEBUG_OUTPUT: getResponse() returned", \
_interfaceObj.getResponse(), \
"for your response.")
+<<<<<<< HEAD
+<<<<<<< HEAD
+ # 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))
+=======
+ # Update the question for the next test.
+ _interfaceObj.updateQuestion()
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
# Update the question for the next test.
_interfaceObj.updateQuestion()
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
# Call the function indicating that the quiz is over.
_interfaceObj.endOfQuiz()
print("interfaceTest() ran successfully")
def resetGlobals():
"""Sets the global variables of this unit test to what they were
initialized to be."""
+<<<<<<< HEAD
+<<<<<<< HEAD
+ global _questionObj
+ global _interfaceObj
+ global indx
+ indx = 0
+ _questionObj = _makeQuestion(indx)
+ _interfaceObj = userInterface.UserInterface(_questionObj)
+=======
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
global _quizObj
global _interfaceObj
_quizObj = Quiz()
_interfaceObj = userInterface.UserInterface(_quizObj)
+<<<<<<< HEAD
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
+=======
+>>>>>>> f92896852af7d045df37e338f32df7c842fea4b4
# The _alphabet variable should never have changed.
def runAll():

0 comments on commit d924f6f

Please sign in to comment.