/
test_low_confidence_adapter.py
72 lines (61 loc) · 2.29 KB
/
test_low_confidence_adapter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from chatterbot.logic import LowConfidenceAdapter
from chatterbot.conversation import Statement
from tests.base_case import ChatBotTestCase
class LowConfidenceAdapterTestCase(ChatBotTestCase):
"""
Test cases for the LowConfidenceAdapter.
"""
def setUp(self):
super().setUp()
self.adapter = LowConfidenceAdapter(self.chatbot)
self.chatbot.storage.create(
text='Who do you love?',
in_response_to='I hear you are going on a quest?'
)
self.chatbot.storage.create(
text='What is the meaning of life?',
in_response_to='Yuck, black licorice jelly beans.'
)
self.chatbot.storage.create(
text='I am Iron Man.',
in_response_to='What... is your quest?'
)
self.chatbot.storage.create(
text='What... is your quest?',
in_response_to='I am Iron Man.'
)
self.chatbot.storage.create(
text='Yuck, black licorice jelly beans.',
in_response_to='What is the meaning of life?'
)
self.chatbot.storage.create(
text='I hear you are going on a quest?',
in_response_to='Who do you love?'
)
def test_high_confidence(self):
"""
Test the case that a high confidence response is known.
"""
statement = Statement(text='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(text='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(text='Is this a tomato?')
match = self.adapter.process(statement)
self.assertEqual(match.confidence, 1)
self.assertEqual(match, 'No')