libept
local.test.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
2 /*
3  * popcon/local test
4  *
5  * Copyright (C) 2007 Enrico Zini <enrico@debian.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21 
22 #include <ept/popcon/local.h>
23 #include <ept/popcon/popcon.h>
24 #include <ept/popcon/maint/path.h>
25 
26 #include <ept/test.h>
27 
28 using namespace std;
29 using namespace ept;
30 using namespace ept::popcon;
31 
33 {
38 
41 
43  : odsd( TEST_ENV_DIR "popcon" ),
44  odid( TEST_ENV_DIR "popcon" ),
45  odusd( TEST_ENV_DIR "popcon" ),
46  oduid( TEST_ENV_DIR "popcon" ),
47  local( TEST_ENV_DIR "popcon/popularity-contest" )
48  {}
49 
50  // Very basic access
51  Test basicAccess()
52  {
53  assert(local.score("apt") > 0);
54  assert(local.tfidf(popcon, "apt") > 0);
55  }
56 
57 #if 0 // mornfall: apparently left out by enrico, leaving as it is
58 // Check that every valid index is accessible
59 template<> template<>
60 void to::test< 2 >()
61 {
62  for (size_t i = 0; i < popcon.size(); ++i)
63  {
64  //cerr << popcon.name(i) << " " << popcon.score(i) << endl;
65  assert(popcon.score(i) > 0);
66  }
67 }
68 
69 // Check that we can get a score for every package
70 template<> template<>
71 void to::test< 3 >()
72 {
73  int has = 0;
74  for (Apt::iterator i = apt.begin(); i != apt.end(); ++i)
75  {
76  float score = popcon.score(*i);
77  if (score > 0)
78  ++has;
79  }
80  // At least 1000 packages should have a score
81  assert(has > 1000);
82 }
83 
84 // Check that scores are meaningful
85 template<> template<>
86 void to::test< 4 >()
87 {
88  assert(popcon["apt"] > popcon["libapt-pkg-dev"]);
89 }
90 
91 // If there is no data, Popcon should work as if all scores were 0
92 template<> template<>
93 void to::test<5>()
94 {
95  Path::OverridePopconSourceDir odsd("./empty");
96  Path::OverridePopconIndexDir odid("./empty");
97  Path::OverridePopconUserSourceDir odusd("./empty");
98  Path::OverridePopconUserIndexDir oduid("./empty");
99  Popcon empty;
100 
101  assert_eq(empty.timestamp(), 0);
102  assert(!empty.hasData());
103 
104  assert(empty.size() == 0);
105  assert(empty.score("apt") == 0.0);
106 }
107 #endif
108 
109 };
110 
111 // vim:set ts=4 sw=4: