Issue 150 - Add unit tests

pull/152/head
Ethan Ward 2016-06-17 09:44:51 -05:00
parent 740f35fa60
commit c7f1c81e37
2 changed files with 20 additions and 4 deletions

View File

@ -171,9 +171,9 @@ class WolframAlphaSkill(MycroftSkill):
if "|" in result: # Assuming "|" indicates a list of items
verb = ":"
result = self.__process_wolfram_string(result)
result = self.process_wolfram_string(result)
input_interpretation = \
self.__process_wolfram_string(input_interpretation)
self.process_wolfram_string(input_interpretation)
response = "%s %s %s" % (input_interpretation, verb, result)
self.speak(response)
@ -188,7 +188,7 @@ class WolframAlphaSkill(MycroftSkill):
return None
@staticmethod
def __process_wolfram_string(text):
def process_wolfram_string(text):
# Remove extra whitespace
text = re.sub(r" \s+", r" ", text)
@ -196,7 +196,7 @@ class WolframAlphaSkill(MycroftSkill):
text = re.sub(r" \| ", r", ", text)
# Convert newlines to commas
text = re.sub(r"\n", r",. ", text)
text = re.sub(r"\n", r", ", text)
# Convert !s to factorial
text = re.sub(r"!", r",factorial", text)

View File

@ -48,3 +48,19 @@ class WolframAlphaTest(unittest.TestCase):
def test_invalid_pod(self):
res = self.create_result("InvalidTitle", "Test")
self.assertEquals(WolframAlphaSkill().get_result(res), None)
def test_whitespace_process(self):
self.assertEquals(WolframAlphaSkill().process_wolfram_string
("Test string"), "Test string")
def test_pipe_process(self):
self.assertEquals(WolframAlphaSkill().process_wolfram_string
("Test | string"), "Test, string")
def test_newline_process(self):
self.assertEquals(WolframAlphaSkill().process_wolfram_string
("Test\nstring"), "Test, string")
def test_factorial_process(self):
self.assertEquals(WolframAlphaSkill().process_wolfram_string
("Test!"), "Test,factorial")