From c4327ec074f68d907b6ed3712b531d5a8a367692 Mon Sep 17 00:00:00 2001 From: Tássia Camões Araújo Date: Thu, 21 Jul 2011 20:44:15 -0300 Subject: [PATCH] Updated tests --- src/tests/data_tests.py | 17 ++++++++++++++++- src/tests/evaluation_tests.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100755 src/tests/evaluation_tests.py diff --git a/src/tests/data_tests.py b/src/tests/data_tests.py index 2c7e4df..7683520 100755 --- a/src/tests/data_tests.py +++ b/src/tests/data_tests.py @@ -22,14 +22,29 @@ __license__ = """ import unittest2 import shutil import os +import xapian import sys sys.path.insert(0,'../') -from data import PopconSubmission, PopconXapianIndex +from data import PopconSubmission, PopconXapianIndex, axi_search_pkg_tags from config import Config def suite(): return unittest2.TestLoader().loadTestsFromTestCase(PopconSubmissionTests) +class AxiSearchTests(unittest2.TestCase): + @classmethod + def setUpClass(self): + cfg = Config() + self.axi = xapian.Database(cfg.axi) + + def test_search_pkg_tags(self): + tags = axi_search_pkg_tags(self.axi,'apticron') + self.assertEqual(set(tags),set(['XTadmin::package-management', + 'XTinterface::daemon', + 'XTnetwork::server', 'XTrole::program', + 'XTsuite::debian', 'XTuse::monitor', + 'XTworks-with::mail'])) + class PopconSubmissionTests(unittest2.TestCase): @classmethod def setUpClass(self): diff --git a/src/tests/evaluation_tests.py b/src/tests/evaluation_tests.py new file mode 100755 index 0000000..458c3fc --- /dev/null +++ b/src/tests/evaluation_tests.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +""" + singletonTests - Singleton class test case +""" +__author__ = "Tassia Camoes Araujo " +__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 . +""" + +import xapian +import unittest2 +import sys +sys.path.insert(0,'../') +from evaluation import (Accuracy, Precision, Recall, F1, Coverage, + Evaluation, CrossValidation) +from recommender import RecommendationResult +from config import Config +from recommender import Recommender +from user import User +from data import SampleAptXapianIndex + +class MetricsTests(unittest2.TestCase): + @classmethod + def setUpClass(self): + repository = ['apple','grape','pineaple','melon','watermelon','orange'] + real = RecommendationResult(dict.fromkeys(['apple','grape','pineaple','melon'],1)) + predicted = RecommendationResult(dict.fromkeys(['apple','grape','orange'],1)) + self.evaluation = Evaluation(predicted,real,len(repository)) + + def test_class_accuracy(self): + accuracy = Accuracy().run(self.evaluation) + self.assertEqual(accuracy,0.5) + + def test_precision(self): + precision = Precision().run(self.evaluation) + self.assertEqual("%.2f" % precision,"0.67") + + def test_recall(self): + recall = Recall().run(self.evaluation) + self.assertEqual(recall,0.5) + + def test_f1(self): + f1 = F1().run(self.evaluation) + self.assertEqual("%.2f" % f1,"0.57") + + def test_coverage(self): + evaluations_set = set() + evaluations_set.add(self.evaluation) + coverage = Coverage().run(evaluations_set) + self.assertEqual(coverage,0.5) + + def test_evaluation(self): + self.assertEqual(self.evaluation.true_positive, ['apple','grape']) + self.assertEqual(self.evaluation.false_positive, ['orange']) + self.assertEqual(self.evaluation.false_negative, ['pineaple','melon']) + + def test_cross_validation(self): + cfg = Config() + axi = xapian.Database(cfg.axi) + packages = ["gimp","aaphoto","eog","emacs","dia","ferret", + "festival","file","inkscape","xpdf"] + path = "test_data/.sample_axi" + sample_axi = SampleAptXapianIndex(packages,axi,path) + rec = Recommender(cfg) + rec.items_repository = sample_axi + user = User({"gimp":1,"aaphoto":1,"eog":1,"emacs":1}) + + metrics = [] + metrics.append(Precision()) + metrics.append(Recall()) + metrics.append(F1()) + + validation = CrossValidation(0.3,5,rec,metrics,0.5) + validation.run(user) + print validation + +if __name__ == '__main__': + unittest2.main() -- libgit2 0.21.2