コード例 #1
0
class LowConfidenceAdapterTestCase(ChatBotTestCase):
    """
    Test cases for the LowConfidenceAdapter.
    """
    def setUp(self):
        super(LowConfidenceAdapterTestCase, self).setUp()
        self.adapter = LowConfidenceAdapter()

        # Add a mock storage adapter to the logic adapter
        self.adapter.set_chatbot(self.chatbot)

        possible_choices = [
            Statement('Who do you love?',
                      in_response_to='I hear you are going on a quest?'),
            Statement('What is the meaning of life?',
                      in_response_to='Yuck, black licorice jelly beans.'),
            Statement('I am Iron Man.',
                      in_response_to='What... is your quest?'),
            Statement('What... is your quest?',
                      in_response_to='I am Iron Man.'),
            Statement('Yuck, black licorice jelly beans.',
                      in_response_to='What is the meaning of life?'),
            Statement('I hear you are going on a quest?',
                      in_response_to='Who do you love?'),
        ]
        self.adapter.chatbot.storage.filter = MagicMock(
            return_value=possible_choices)

    def test_high_confidence(self):
        """
        Test the case that a high confidence response is known.
        """
        statement = Statement('What is your quest?')
        match = self.adapter.process(statement)

        self.assertEqual(match.confidence, 0)
        self.assertEqual(match, self.adapter.default_responses[0])

    def test_low_confidence(self):
        """
        Test the case that a high confidence response is not known.
        """
        statement = Statement('Is this a tomato?')
        match = self.adapter.process(statement)

        self.assertEqual(match.confidence, 1)
        self.assertEqual(match, self.adapter.default_responses[0])

    def test_low_confidence_options_list(self):
        """
        Test the case that a high confidence response is not known.
        """
        self.adapter.default_responses = [Statement(text='No')]

        statement = Statement('Is this a tomato?')
        match = self.adapter.process(statement)

        self.assertEqual(match.confidence, 1)
        self.assertEqual(match, 'No')
コード例 #2
0
class LowConfidenceAdapterTestCase(ChatBotTestCase):
    """
    Test cases for the LowConfidenceAdapter.
    """

    def setUp(self):
        super(LowConfidenceAdapterTestCase, self).setUp()
        self.adapter = LowConfidenceAdapter()

        # Add a mock storage adapter to the logic adapter
        self.adapter.set_chatbot(self.chatbot)

        possible_choices = [
            Statement('Who do you love?', in_response_to=[
                Response('I hear you are going on a quest?')
            ]),
            Statement('What is the meaning of life?', in_response_to=[
                Response('Yuck, black licorice jelly beans.')
            ]),
            Statement('I am Iron Man.', in_response_to=[
                Response('What... is your quest?')
            ]),
            Statement('What... is your quest?', in_response_to=[
                Response('I am Iron Man.')
            ]),
            Statement('Yuck, black licorice jelly beans.', in_response_to=[
                Response('What is the meaning of life?')
            ]),
            Statement('I hear you are going on a quest?', in_response_to=[
                Response('Who do you love?')
            ]),
        ]
        self.adapter.chatbot.storage.filter = MagicMock(return_value=possible_choices)

    def test_high_confidence(self):
        """
        Test the case that a high confidence response is known.
        """
        statement = Statement('What is your quest?')
        confidence, match = self.adapter.process(statement)

        self.assertEqual(confidence, 0)
        self.assertEqual(match.confidence, 0)
        self.assertEqual(match, self.adapter.default_response)

    def test_low_confidence(self):
        """
        Test the case that a high confidence response is not known.
        """
        statement = Statement('Is this a tomato?')
        confidence, match = self.adapter.process(statement)

        self.assertEqual(confidence, 1)
        self.assertEqual(match.confidence, 1)
        self.assertEqual(match, self.adapter.default_response)
コード例 #3
0
    def test_low_confidence(self):
        from chatterbot.logic import LowConfidenceAdapter

        adapter = LowConfidenceAdapter()
        adapter.set_chatbot(self.chatbot)

        statement = Statement(text='Why is the sky blue?')

        response = adapter.process(statement)

        self.assertEqual(response.text, adapter.default_response)
コード例 #4
0
    def test_low_confidence(self):
        from chatterbot.logic import LowConfidenceAdapter

        adapter = LowConfidenceAdapter()
        adapter.set_chatbot(self.chatbot)

        statement = Statement(text='Why is the sky blue?')

        response = adapter.process(statement)

        self.assertEqual(response.text, adapter.default_responses[0])