Skip to content

Commit

Permalink
Updated test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
adipai committed Oct 12, 2023
1 parent 947bbfa commit 93569e5
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Code/recommenderapp/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ def results_top_ten(self, word):
return self.results(word)[:10]


if __name__ == "__main__":
app.run()
#if __name__ == "__main__":
# app.run()
45 changes: 32 additions & 13 deletions test/test_search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Test suit for search feature
"""

import unittest
import warnings
import sys
Expand All @@ -8,12 +12,18 @@

warnings.filterwarnings("ignore")


class Tests(unittest.TestCase):
def testSearchToy(self):
"""
Test cases for search feature
"""

def test_search_toy(self):
"""
Test case 1
"""
search_word = "toy"
search = Search()
filtered_dict = search.resultsTop10(search_word)
finder = Search()
filtered_dict = finder.results_top_ten(search_word)
expected_resp = [
"Toy Story (1995)",
"Toys (1992)",
Expand All @@ -26,10 +36,13 @@ def testSearchToy(self):
]
self.assertTrue(filtered_dict == expected_resp)

def testSearchLove(self):
def test_search_love(self):
"""
Test case 2
"""
search_word = "love"
search = Search()
filtered_dict = search.resultsTop10(search_word)
finder = Search()
filtered_dict = finder.results_top_ten(search_word)
expected_resp = [
"Love & Human Remains (1993)",
"Love Affair (1994)",
Expand All @@ -44,17 +57,23 @@ def testSearchLove(self):
]
self.assertTrue(filtered_dict == expected_resp)

def testSearchGibberish(self):
def test_search_gibberish(self):
"""
Test case 3
"""
search_word = "gibberish"
search = Search()
filtered_dict = search.resultsTop10(search_word)
finder = Search()
filtered_dict = finder.results_top_ten(search_word)
expected_resp = []
self.assertTrue(filtered_dict == expected_resp)

def testSearch1995(self):
def test_search_1995(self):
"""
Test case 4
"""
search_word = "1995"
search = Search()
filtered_dict = search.resultsTop10(search_word)
finder = Search()
filtered_dict = finder.results_top_ten(search_word)
expected_resp = [
"Toy Story (1995)",
"Jumanji (1995)",
Expand Down
115 changes: 84 additions & 31 deletions test/tests.py
Original file line number Diff line number Diff line change
@@ -1,120 +1,173 @@
"""
Test suite for recommender system
"""

import unittest
import warnings
import sys

sys.path.append("../")
from Code.prediction_scripts.item_based import recommendForNewUser
from Code.prediction_scripts.item_based import recommend_for_new_user

warnings.filterwarnings("ignore")


class Tests(unittest.TestCase):
def testToyStory(self):
"""
Test cases for recommender system
"""

def test_toy_story(self):
"""
Test case 1
"""
ts = [
{"title": "Toy Story (1995)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue("Toy Story 3 (2010)" in recommendations)

def testKunfuPanda(self):
def test_kunfu_panda(self):
"""
Test case 2
"""
ts = [
{"title": "Kung Fu Panda (2008)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue("Toy Story (1995)" in recommendations)

def testHorrorWithCartoon(self):
def test_horror_with_cartoon(self):
"""
Test case 3
"""
ts = [
{"title": "Strangers, The (2008)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("Toy Story (1995)" in recommendations) == False)

def testIronMan(self):
def test_iron_man(self):
"""
Test case 4
"""
ts = [
{"title": "Iron Man (2008)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("Avengers: Infinity War - Part I (2018)" in recommendations))

def testRoboCop(self):
def test_robo_cop(self):
"""
Test case 5
"""
ts = [
{"title": "RoboCop (1987)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("RoboCop 2 (1990)" in recommendations))

def testNolan(self):
def test_nolan(self):
"""
Test case 6
"""
ts = [
{"title": "Inception (2010)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("Dark Knight, The (2008)" in recommendations))

def testDC(self):
def test_dc(self):
"""
Test case 7
"""
ts = [
{"title": "Man of Steel (2013)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(
("Batman v Superman: Dawn of Justice (2016)" in recommendations)
)

def testArmageddon(self):
def test_armageddon(self):
"""
Test case 8
"""
ts = [
{"title": "Armageddon (1998)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("2012 (2009)" in recommendations))

def testLethalWeapon(self):
def test_lethal_weapon(self):
"""
Test case 9
"""
ts = [
{"title": "Lethal Weapon (1987)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("Lethal Weapon 3 (1992)" in recommendations))

def testDarkAction(self):
def test_dark_action(self):
"""
Test case 10
"""
ts = [
{"title": "Batman: The Killing Joke (2016)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("Punisher: War Zone (2008)" in recommendations))

def testDark(self):
def test_dark(self):
"""
Test case 11
"""
ts = [
{"title": "Puppet Master (1989)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("Black Mirror: White Christmas (2014)" in recommendations))

def testHorrorComedy(self):
def test_horror_comedy(self):
"""
Test case 12
"""
ts = [
{"title": "Scary Movie (2000)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("I Sell the Dead (2008)" in recommendations))

def testSuperHeroes(self):
def test_super_heroes(self):
"""
Test case 13
"""
ts = [
{"title": "Spider-Man (2002)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("Iron Man 2 (2010)" in recommendations))

def testCartoon(self):
def test_cartoon(self):
"""
Test case 14
"""
ts = [
{"title": "Moana (2016)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("Monsters, Inc. (2001)" in recommendations))

def testMultipleMovies(self):
def test_multiple_movies(self):
"""
Test case 15
"""
ts = [
{"title": "Harry Potter and the Goblet of Fire (2005)", "rating": 5.0},
{"title": "Twilight Saga: New Moon, The (2009)", "rating": 5.0},
]
recommendations = recommendForNewUser(ts)
recommendations = recommend_for_new_user(ts)
self.assertTrue(("Twilight (2008)" in recommendations))


Expand Down

0 comments on commit 93569e5

Please sign in to comment.