Ejemplo 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
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo 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
Ejemplo n.º 5
0
 def __init__(self, question, potentialAnswers):
     self.db = QuestionDB()
     self.question = question
     self.potentialAnswers = potentialAnswers
Ejemplo n.º 6
0
 def setUp(self):
     self.db = QuestionDB()
     pass
Ejemplo n.º 7
0
 def __init__(self, question, potentialAnswers):
     self.db = QuestionDB()
     self.question = question
     self.potentialAnswers = potentialAnswers
Ejemplo n.º 8
0
 def setUp(self):
     self.db = QuestionDB()
     pass