Commit 8ce5c49951da404105bce9f15c53861df5e04824

Authored by Tássia Camões Araújo
1 parent dcbbf624
Exists in master and in 1 other branch add_vagrant

Added weighting scheme and clustering options to recommender; changed method for…

… setting recommender strategy; do not use eval due to security risks; implemmented tests for recommender.
Showing 1 changed file with 69 additions and 0 deletions   Show diff stats
src/tests/recommender_tests.py 0 → 100755
... ... @@ -0,0 +1,69 @@
  1 +#!/usr/bin/env python
  2 +"""
  3 + recommenderTests - Recommender class test case
  4 +"""
  5 +__author__ = "Tassia Camoes Araujo <tassia@gmail.com>"
  6 +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo"
  7 +__license__ = """
  8 + This program is free software: you can redistribute it and/or modify
  9 + it under the terms of the GNU General Public License as published by
  10 + the Free Software Foundation, either version 3 of the License, or
  11 + (at your option) any later version.
  12 +
  13 + This program is distributed in the hope that it will be useful,
  14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + GNU General Public License for more details.
  17 +
  18 + You should have received a copy of the GNU General Public License
  19 + along with this program. If not, see <http://www.gnu.org/licenses/>.
  20 +"""
  21 +
  22 +import unittest2
  23 +import sys
  24 +sys.path.insert(0,'../')
  25 +from recommender import RecommendationResult, Recommender
  26 +from user import User
  27 +from config import Config
  28 +from strategy import ContentBasedStrategy, CollaborativeStrategy
  29 +
  30 +class RecommendationResultTests(unittest2.TestCase):
  31 + @classmethod
  32 + def setUpClass(self):
  33 + self.result = RecommendationResult({"gimp":1.5,"inkscape":3.0,"eog":1})
  34 +
  35 + def test_str(self):
  36 + string = "\n 0: inkscape\n 1: gimp\n 2: eog\n"
  37 + self.assertEqual(self.result.__str__(),string)
  38 +
  39 + def test_get_prediction(self):
  40 + prediction = [("inkscape",3.0),("gimp",1.5),("eog",1)]
  41 + self.assertEqual(self.result.get_prediction(),prediction)
  42 +
  43 +class RecommenderTests(unittest2.TestCase):
  44 + @classmethod
  45 + def setUpClass(self):
  46 + cfg = Config()
  47 + self.rec = Recommender(cfg)
  48 +
  49 + def test_set_strategy(self):
  50 + self.rec.set_strategy("cb")
  51 + self.assertIsInstance(self.rec.strategy,ContentBasedStrategy)
  52 + self.assertEqual(self.rec.strategy.content,"full")
  53 + self.rec.set_strategy("cbt")
  54 + self.assertIsInstance(self.rec.strategy,ContentBasedStrategy)
  55 + self.assertEqual(self.rec.strategy.content,"tag")
  56 + self.rec.set_strategy("cbd")
  57 + self.assertIsInstance(self.rec.strategy,ContentBasedStrategy)
  58 + self.assertEqual(self.rec.strategy.content,"desc")
  59 + self.rec.set_strategy("col")
  60 + self.assertIsInstance(self.rec.strategy,CollaborativeStrategy)
  61 +
  62 + def test_get_recommendation(self):
  63 + user = User({"inkscape": 1, "gimp": 1, "eog":1})
  64 + result = self.rec.get_recommendation(user)
  65 + self.assertIsInstance(result, RecommendationResult)
  66 + self.assertGreater(len(result.item_score),0)
  67 +
  68 +if __name__ == '__main__':
  69 + unittest2.main()
... ...