Skip to content

Commit

Permalink
Updated logic adapter tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Sep 4, 2015
1 parent 4a081cd commit 3742f14
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
3 changes: 1 addition & 2 deletions chatterbot/adapters/logic/closest_match.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .logic import LogicAdapter
from fuzzywuzzy import process


class ClosestMatchAdapter(LogicAdapter):
Expand All @@ -8,8 +9,6 @@ def get(self, text, list_of_statements):
Takes a statement string and a list of statement strings.
Returns the closest matching statement from the list.
"""
from fuzzywuzzy import process

# If the list is empty, return the statement
if not list_of_statements:
return text
Expand Down
2 changes: 1 addition & 1 deletion chatterbot/adapters/logic/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

class LogicAdapter(object):

def get_response(self):
def get(self):
raise AdapterNotImplementedError()
8 changes: 0 additions & 8 deletions tests/io_adapter_tests/test_terminal_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ class TerminalAdapterTests(TestCase):
a command line interface.
"""

def test_response_is_printed(self):
"""
This test ensures that the bot's response is
correctly printed in the terminal.
"""
# TODO: How can you test this?
self.assertTrue(True)

def test_response_is_returned(self):
"""
For consistency across io adapters, the
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from .base_case import ChatBotTestCase
from unittest import TestCase
from chatterbot.adapters.logic import ClosestMatchAdapter


class ClosestMatchAdapterTests(ChatBotTestCase):
class ClosestMatchAdapterTests(TestCase):

def test_get_closest_statement(self):

adapter = ClosestMatchAdapter()
def setUp(self):
self.adapter = ClosestMatchAdapter()

def test_get_closest_statement(self):
possible_choices = [
"Who do you love?",
"What is the meaning of life?",
Expand All @@ -17,6 +17,13 @@ def test_get_closest_statement(self):
"I hear you are going on a quest?",
]

close = adapter.get("What is your quest?", possible_choices)
close = self.adapter.get("What is your quest?", possible_choices)

self.assertEqual("What... is your quest?", close)

def test_no_choices(self):
possible_choices = []
close = self.adapter.get("What is your quest?", possible_choices)

self.assertEqual("What is your quest?", close)

15 changes: 12 additions & 3 deletions tests/test_chatbot_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ def test_get_most_frequent_response(self):
def test_get_first_response(self):
statement_list = [
Statement("What... is your quest?", occurrence=2),
Statement("This is a phone.", occurrence=4),
Statement("A what?", occurrence=2),
Statement("A phone.", occurrence=2)
Statement("A quest.", occurrence=2)
]

output = self.chatbot.get_first_response(
Expand All @@ -55,7 +54,17 @@ def test_get_first_response(self):
self.assertEqual("What... is your quest?", output)

def test_get_random_response(self):
pass # TODO
statement_list = [
Statement("This is a phone.", occurrence=4),
Statement("A what?", occurrence=2),
Statement("A phone.", occurrence=2)
]

output = self.chatbot.get_random_response(
statement_list
)

self.assertTrue(output)

def test_answer_to_known_input(self):
"""
Expand Down

0 comments on commit 3742f14

Please sign in to comment.