strategy_tests.py
3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
"""
strategyTests - Recommendation strategies classes test case
"""
__author__ = "Tassia Camoes Araujo <tassia@gmail.com>"
__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo"
__license__ = """
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import unittest2
import xapian
import sys
sys.path.insert(0,'../')
from error import Error
from user import User
from recommender import RecommendationResult
from config import Config
from strategy import (PkgMatchDecider, UserMatchDecider, PkgExpandDecider,
TagExpandDecider, ContentBasedStrategy,
CollaborativeStrategy, DemographicStrategy,
KnowledgeBasedStrategy, ItemReputationStrategy)
class PkgMatchDeciderTests(unittest2.TestCase):
@classmethod
def setUpClass(self):
pkgs_list = ["gimp","eog","inkscape"]
self.decider = PkgMatchDecider(pkgs_list)
self.doc = xapian.Document()
def test_match(self):
self.doc.set_data("emacs")
self.assertTrue(self.decider(self.doc))
def test_no_match(self):
self.doc.set_data("gimp")
self.assertFalse(self.decider(self.doc))
class UserMatchDeciderTests(unittest2.TestCase):
@classmethod
def setUpClass(self):
user_profile = ["gimp","eog","inkscape", "emacs"]
self.decider = UserMatchDecider(user_profile)
def setUp(self):
self.doc = xapian.Document()
def test_match(self):
self.doc.add_term("emacs")
self.doc.add_term("gimp")
self.doc.add_term("eog")
self.assertTrue(self.decider(self.doc))
def test_no_match(self):
self.doc.add_term("gimp")
self.assertFalse(self.decider(self.doc))
class PkgExpandDeciderTests(unittest2.TestCase):
@classmethod
def setUpClass(self):
self.decider = PkgExpandDecider()
def test_match(self):
self.assertTrue(self.decider("XPgimp"))
def test_no_match(self):
self.assertFalse(self.decider("XTgimp"))
class TagExpandDeciderTests(unittest2.TestCase):
@classmethod
def setUpClass(self):
self.decider = TagExpandDecider()
def test_match(self):
self.assertTrue(self.decider("XTgimp"))
def test_no_match(self):
self.assertFalse(self.decider("gimp"))
class ContentBasedStrategyTests(unittest2.TestCase):
@classmethod
def setUpClass(self):
pass
class CollaborativeStrategyTests(unittest2.TestCase):
@classmethod
def setUpClass(self):
pass
class DemographicStrategyTests(unittest2.TestCase):
def test_call(self):
self.assertRaises(Error,lambda: DemographicStrategy())
class KnowledgeBasedStrategyTests(unittest2.TestCase):
def test_call(self):
self.assertRaises(Error,lambda: KnowledgeBasedStrategy())
class ItemReputationStrategyTests(unittest2.TestCase):
def test_call(self):
self.assertRaises(Error,lambda: ItemReputationStrategy())
if __name__ == '__main__':
unittest2.main()