Exemplo n.º 1
0
class Researcher(object):
    '''
    Responsible for trying to figure out which answer is correct, using any means necessary.
    '''
    def __init__(self, question, potentialAnswers):
        self.db = QuestionDB()
        self.question = question
        self.potentialAnswers = potentialAnswers

    def guess(self):
        ''' Guess which of these answers is correct.  Returns the index of the answer or None if we have got no clue. '''
        i = self.guessDB()
        if i == None:
            i = self.guessWiz()
        return i

    def guessDB(self):
        ''' Try to find the answer in the database '''
        ans = self.db.getAnswer(self.question)
        return self.findInList(ans)

    def guessWiz(self):
        ''' Try to find the answer via the gquery Wizard. '''
        ans = Wizard(self.question, self.potentialAnswers).guess()
        return ans.getValue()

    def findInList(self, ans):
        if ans == None:
            return None
        try:
            i = self.potentialAnswers.index(ans)
            return i
        except ValueError:
            return None
class Test(unittest.TestCase):


    def setUp(self):
        self.db = QuestionDB()
        pass


    def tearDown(self):
        pass


    def test_get_answer(self):
        self.assertEqual(self.db.getAnswer('Which 1995 movie used the tagline "A little pig goes a long way"?'), 'Babe')
        
    def test_get_answer_for_unknown_question(self):
        self.assertEqual(self.db.getAnswer('blah blah whatever.  this question doesnt exist.'), None)
class Test(unittest.TestCase):
    def setUp(self):
        self.db = QuestionDB()
        pass

    def tearDown(self):
        pass

    def test_get_answer(self):
        self.assertEqual(
            self.db.getAnswer(
                'Which 1995 movie used the tagline "A little pig goes a long way"?'
            ), 'Babe')

    def test_get_answer_for_unknown_question(self):
        self.assertEqual(
            self.db.getAnswer(
                'blah blah whatever.  this question doesnt exist.'), None)
Exemplo n.º 4
0
class Researcher(object):
    '''
    Responsible for trying to figure out which answer is correct, using any means necessary.
    '''


    def __init__(self, question, potentialAnswers):
        self.db = QuestionDB()
        self.question = question
        self.potentialAnswers = potentialAnswers
        
    def guess(self):
        ''' Guess which of these answers is correct.  Returns the index of the answer or None if we have got no clue. '''
        i = self.guessDB()
        if i == None:
            i = self.guessWiz()
        return i 
        
    
    def guessDB(self):
        ''' Try to find the answer in the database '''
        ans = self.db.getAnswer(self.question)
        return self.findInList(ans)
        
        
    def guessWiz(self):
        ''' Try to find the answer via the gquery Wizard. '''
        ans = Wizard(self.question, self.potentialAnswers).guess()
        return ans.getValue()
        
        
    def findInList(self, ans):
        if ans == None:
            return None
        try:
            i = self.potentialAnswers.index(ans)
            return i
        except ValueError:
            return None
Exemplo n.º 5
0
 def __init__(self, question, potentialAnswers):
     self.db = QuestionDB()
     self.question = question
     self.potentialAnswers = potentialAnswers
 def setUp(self):
     self.db = QuestionDB()
     pass
Exemplo n.º 7
0
 def __init__(self, question, potentialAnswers):
     self.db = QuestionDB()
     self.question = question
     self.potentialAnswers = potentialAnswers
 def setUp(self):
     self.db = QuestionDB()
     pass