Commit c4327ec074f68d907b6ed3712b531d5a8a367692
1 parent
8a5b273c
Exists in
master
and in
1 other branch
Updated tests
Showing
2 changed files
with
106 additions
and
1 deletions
Show diff stats
src/tests/data_tests.py
... | ... | @@ -22,14 +22,29 @@ __license__ = """ |
22 | 22 | import unittest2 |
23 | 23 | import shutil |
24 | 24 | import os |
25 | +import xapian | |
25 | 26 | import sys |
26 | 27 | sys.path.insert(0,'../') |
27 | -from data import PopconSubmission, PopconXapianIndex | |
28 | +from data import PopconSubmission, PopconXapianIndex, axi_search_pkg_tags | |
28 | 29 | from config import Config |
29 | 30 | |
30 | 31 | def suite(): |
31 | 32 | return unittest2.TestLoader().loadTestsFromTestCase(PopconSubmissionTests) |
32 | 33 | |
34 | +class AxiSearchTests(unittest2.TestCase): | |
35 | + @classmethod | |
36 | + def setUpClass(self): | |
37 | + cfg = Config() | |
38 | + self.axi = xapian.Database(cfg.axi) | |
39 | + | |
40 | + def test_search_pkg_tags(self): | |
41 | + tags = axi_search_pkg_tags(self.axi,'apticron') | |
42 | + self.assertEqual(set(tags),set(['XTadmin::package-management', | |
43 | + 'XTinterface::daemon', | |
44 | + 'XTnetwork::server', 'XTrole::program', | |
45 | + 'XTsuite::debian', 'XTuse::monitor', | |
46 | + 'XTworks-with::mail'])) | |
47 | + | |
33 | 48 | class PopconSubmissionTests(unittest2.TestCase): |
34 | 49 | @classmethod |
35 | 50 | def setUpClass(self): | ... | ... |
... | ... | @@ -0,0 +1,90 @@ |
1 | +#!/usr/bin/env python | |
2 | +""" | |
3 | + singletonTests - Singleton 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 xapian | |
23 | +import unittest2 | |
24 | +import sys | |
25 | +sys.path.insert(0,'../') | |
26 | +from evaluation import (Accuracy, Precision, Recall, F1, Coverage, | |
27 | + Evaluation, CrossValidation) | |
28 | +from recommender import RecommendationResult | |
29 | +from config import Config | |
30 | +from recommender import Recommender | |
31 | +from user import User | |
32 | +from data import SampleAptXapianIndex | |
33 | + | |
34 | +class MetricsTests(unittest2.TestCase): | |
35 | + @classmethod | |
36 | + def setUpClass(self): | |
37 | + repository = ['apple','grape','pineaple','melon','watermelon','orange'] | |
38 | + real = RecommendationResult(dict.fromkeys(['apple','grape','pineaple','melon'],1)) | |
39 | + predicted = RecommendationResult(dict.fromkeys(['apple','grape','orange'],1)) | |
40 | + self.evaluation = Evaluation(predicted,real,len(repository)) | |
41 | + | |
42 | + def test_class_accuracy(self): | |
43 | + accuracy = Accuracy().run(self.evaluation) | |
44 | + self.assertEqual(accuracy,0.5) | |
45 | + | |
46 | + def test_precision(self): | |
47 | + precision = Precision().run(self.evaluation) | |
48 | + self.assertEqual("%.2f" % precision,"0.67") | |
49 | + | |
50 | + def test_recall(self): | |
51 | + recall = Recall().run(self.evaluation) | |
52 | + self.assertEqual(recall,0.5) | |
53 | + | |
54 | + def test_f1(self): | |
55 | + f1 = F1().run(self.evaluation) | |
56 | + self.assertEqual("%.2f" % f1,"0.57") | |
57 | + | |
58 | + def test_coverage(self): | |
59 | + evaluations_set = set() | |
60 | + evaluations_set.add(self.evaluation) | |
61 | + coverage = Coverage().run(evaluations_set) | |
62 | + self.assertEqual(coverage,0.5) | |
63 | + | |
64 | + def test_evaluation(self): | |
65 | + self.assertEqual(self.evaluation.true_positive, ['apple','grape']) | |
66 | + self.assertEqual(self.evaluation.false_positive, ['orange']) | |
67 | + self.assertEqual(self.evaluation.false_negative, ['pineaple','melon']) | |
68 | + | |
69 | + def test_cross_validation(self): | |
70 | + cfg = Config() | |
71 | + axi = xapian.Database(cfg.axi) | |
72 | + packages = ["gimp","aaphoto","eog","emacs","dia","ferret", | |
73 | + "festival","file","inkscape","xpdf"] | |
74 | + path = "test_data/.sample_axi" | |
75 | + sample_axi = SampleAptXapianIndex(packages,axi,path) | |
76 | + rec = Recommender(cfg) | |
77 | + rec.items_repository = sample_axi | |
78 | + user = User({"gimp":1,"aaphoto":1,"eog":1,"emacs":1}) | |
79 | + | |
80 | + metrics = [] | |
81 | + metrics.append(Precision()) | |
82 | + metrics.append(Recall()) | |
83 | + metrics.append(F1()) | |
84 | + | |
85 | + validation = CrossValidation(0.3,5,rec,metrics,0.5) | |
86 | + validation.run(user) | |
87 | + print validation | |
88 | + | |
89 | +if __name__ == '__main__': | |
90 | + unittest2.main() | ... | ... |