• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

local.test.h

Go to the documentation of this file.
00001 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
00002 /*
00003  * popcon/local test
00004  *
00005  * Copyright (C) 2007  Enrico Zini <enrico@debian.org>
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00022 #include <ept/popcon/local.h>
00023 #include <ept/popcon/popcon.h>
00024 #include <ept/popcon/maint/path.h>
00025 
00026 #include <ept/test.h>
00027 
00028 using namespace std;
00029 using namespace ept;
00030 using namespace ept::popcon;
00031 
00032 struct TestPopconLocal
00033 {
00034     Path::OverridePopconSourceDir odsd;
00035     Path::OverridePopconIndexDir odid;
00036     Path::OverridePopconUserSourceDir odusd;
00037     Path::OverridePopconUserIndexDir oduid;
00038 
00039     Popcon popcon;
00040     Local local;
00041 
00042     TestPopconLocal()
00043         : odsd( TEST_ENV_DIR "popcon" ),
00044           odid( TEST_ENV_DIR "popcon" ),
00045           odusd( TEST_ENV_DIR "popcon" ),
00046           oduid( TEST_ENV_DIR "popcon" ),
00047           local( TEST_ENV_DIR "popcon/popularity-contest" )
00048     {}
00049 
00050     // Very basic access
00051     Test basicAccess()
00052     {
00053         assert(local.score("apt") > 0);
00054         assert(local.tfidf(popcon, "apt") > 0);
00055     }
00056 
00057 #if 0 // mornfall: apparently left out by enrico, leaving as it is
00058 // Check that every valid index is accessible
00059 template<> template<>
00060 void to::test< 2 >()
00061 {
00062     for (size_t i = 0; i < popcon.size(); ++i)
00063     {
00064         //cerr << popcon.name(i) << " " << popcon.score(i) << endl;
00065         assert(popcon.score(i) > 0);
00066     }
00067 }
00068 
00069 // Check that we can get a score for every package
00070 template<> template<>
00071 void to::test< 3 >()
00072 {
00073     int has = 0;
00074     for (Apt::iterator i = apt.begin(); i != apt.end(); ++i)
00075     {
00076         float score = popcon.score(*i);
00077         if (score > 0)
00078             ++has;
00079     }
00080     // At least 1000 packages should have a score
00081     assert(has > 1000);
00082 }
00083 
00084 // Check that scores are meaningful
00085 template<> template<>
00086 void to::test< 4 >()
00087 {
00088     assert(popcon["apt"] > popcon["libapt-pkg-dev"]);
00089 }
00090 
00091 // If there is no data, Popcon should work as if all scores were 0
00092 template<> template<>
00093 void to::test<5>()
00094 {
00095     Path::OverridePopconSourceDir odsd("./empty");
00096     Path::OverridePopconIndexDir odid("./empty");
00097     Path::OverridePopconUserSourceDir odusd("./empty");
00098     Path::OverridePopconUserIndexDir oduid("./empty");
00099     Popcon empty;
00100 
00101     assert_eq(empty.timestamp(), 0);
00102     assert(!empty.hasData());
00103 
00104     assert(empty.size() == 0);
00105     assert(empty.score("apt") == 0.0);
00106 }
00107 #endif
00108 
00109 };
00110 
00111 // vim:set ts=4 sw=4:

Generated on Wed Oct 27 2010 12:43:31 for libept by  doxygen 1.7.1