module TestDataSet where import Test.HUnit import DataSet hiding (map) import Data.Maybe (fromJust) import Algorithms criticsList :: [(String, [(String, Double)])] criticsList = [ ("Lisa Rose", [("Lady in the Water" , 2.5), ("Snakes on a Plane" , 3.5), ("Just My Luck" , 3.0), ("Superman Returns" , 3.5), ("You, Me and Dupree", 2.5), ("The Night Listener", 3.0) ]), ("Gene Seymour", [("Lady in the Water" , 3.0), ("Snakes on a Plane" , 3.5), ("Just My Luck" , 1.5), ("Superman Returns" , 5.0), ("The Night Listener", 3.0), ("You, Me and Dupree", 3.5) ]), ("Michael Phillips", [("Lady in the Water" , 2.5), ("Snakes on a Plane" , 3.0), ("Superman Returns" , 3.5), ("The Night Listener", 4.0) ]), ("Claudia Puig", [("Snakes on a Plane" , 3.5), ("Just My Luck" , 3.0), ("The Night Listener", 4.5), ("Superman Returns" , 4.0), ("You, Me and Dupree", 2.5) ]), ("Mick LaSalle", [("Lady in the Water" , 3.0), ("Snakes on a Plane" , 4.0), ("Just My Luck" , 2.0), ("Superman Returns" , 3.0), ("The Night Listener", 3.0), ("You, Me and Dupree", 2.0) ]), ("Jack Matthews", [("Lady in the Water" , 3.0), ("Snakes on a Plane" , 4.0), ("The Night Listener", 3.0), ("Superman Returns" , 5.0), ("You, Me and Dupree", 3.5) ]), ("Toby", [("Snakes on a Plane" ,4.5), ("You, Me and Dupree",1.0), ("Superman Returns" ,4.0) ]) ] critics :: DataSet String String Double critics = fromLists criticsList tolerance :: Double tolerance = 0.00001 test1 = testMetric "euclidean distance" euclidean "Lisa Rose" "Gene Seymour" 0.148148 test2 = testMetric "pearson distance" pearson "Lisa Rose" "Gene Seymour" 0.396059017 testMetric :: String -> Metric String String Double -> String -> String -> Double -> Test testMetric msg metric c1 c2 ans = TestCase (assertBool msg (distance < tolerance)) where distance = abs (ans - result) result = fromJust (metric c1 c2 critics) test3 = TestCase (assertEqual "testing topMatches" correct tops) where correct = ["Lisa Rose", "Mick LaSalle", "Claudia Puig"] tops = take 3 . map fst $ tops' tops' = topMatches "Toby" pearson' critics test4 = TestCase (assertBool "testing getRecommendations" $ and $ map (`elem` result) $ cs) where cs = ["The Night Listener", "Lady in the Water", "Just My Luck"] result = map fst $ getRecommendations "Toby" pearson' critics test5 = TestCase (assertEqual "testing transform" correct tops) where correct = ["You, Me and Dupree", "Lady in the Water", "Snakes on a Plane", "The Night Listener", "Just My Luck"] tops = map fst $ tops' tops' = topMatches "Superman Returns" pearson' (transform critics) tests = TestList [TestLabel "test1" test1, TestLabel "test2" test2, TestLabel "test3" test3, TestLabel "test4" test4, TestLabel "test5" test5]