Skip to content
Permalink
Browse files
UnitTest for FoodFinder
  • Loading branch information
jansonsa committed Nov 21, 2017
1 parent b282fa1 commit 3b0e3453a5873bceb8f4228c154bed96d5365658
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
@@ -1,6 +1,7 @@
# Made by Andris Jansons

KEYWORDS = "the, a, an, get, good, best, is, are, to, nice, pleasant, lovely, cool, fine, stupid, goddamn, great, large, small, medium, new, newest, old, closest, smallest, biggest, coolest".split(", ")
KEYWORDS = "the, a, an, get, good, best, is, are, to, nice, pleasant, lovely, cool, fine, stupid, goddamn, nearest, great, large, small, medium, new, newest, old, closest, smallest, biggest, coolest".split(", ")
SKIPS = "get, is, are, to".split(", ")

def findFood(text):
"""Finds food after special KEYWORDS"""
@@ -10,15 +11,17 @@ def findFood(text):
if found == False:
if word in KEYWORDS:
found = True #Finds the first keyword
food = word
if not(word in SKIPS):
food = word

else:
if word in KEYWORDS:
food = food + " " + word
if not(word in SKIPS):
food = food + " " + word
continue
food = food + " " + word #If multiple keywords follow each other
break # take all of them in account and the word
# that follows them as well e.g. "The best burger"

food = food.replace("get",'').replace("is",'').replace("are",'').replace("to",'').strip(' ') # Make the string neat for printing it out
food = food.strip(' ') # Make the string neat for printing it out
return food
@@ -0,0 +1,25 @@
from QuestionToList import makeList
print("Running Food finder tests")
print("-"*50)
try:
from FoodFinder import findFood
questions = ["Where can a man get himself a burger?", "I would like an icecream" , "I'm craving a lettuce at this time of the day", "How far is the nearest hospital?", "The closest atm", "A nice place to sleep"]
answers = ["a burger", "an icecream", "a lettuce", "the nearest hospital", "the closest atm", "a nice place to sleep"]
n = len(questions)
count=0
for i in range(n):
que = questions[i]
ans = findFood(makeList(que))
if ans!=answers[i]:
print("Food finder test for \"" + que + "\" failed")
print("Expected: "+answers[i])
print("Got: "+ans)
print("-"*50)
count = count+1
print(str(n-count) + "/" + str(n) + " food finder tests passed")
except ImportError:
print("The function findFood was not present in the module FoodFinder")
print("-"*50)
print("End of Food finder tests")


0 comments on commit 3b0e345

Please sign in to comment.