libept  0.5.25
popcon.test.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
2 /*
3  * popcon 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/popcon.h>
23 #include <ept/popcon/maint/path.h>
24 #include <ept/apt/apt.h>
25 #include <set>
26 
27 #include <ept/test.h>
28 
29 using namespace std;
30 using namespace ept;
31 using namespace ept::popcon;
32 using namespace ept::apt;
33 
34 struct TestPopcon
35 {
40 
43 
45  : odsd( TEST_ENV_DIR "popcon" ),
46  odid( TEST_ENV_DIR "popcon" ),
47  odusd( TEST_ENV_DIR "popcon" ),
48  oduid( TEST_ENV_DIR "popcon" )
49  {}
50 
51  Test basicAccess()
52  {
53  assert_eq(popcon.submissions(), 52024);
54  assert(popcon.size() > 0);
55  assert(popcon.score(0) > 0);
56  assert(!popcon.name(0).empty());
57  }
58 
59  // Check that every valid index is accessible
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  Test haveScores()
71  {
72  int has = 0;
73  for (Apt::iterator i = apt.begin(); i != apt.end(); ++i)
74  {
75  float score = popcon.score(*i);
76  if (score > 0)
77  ++has;
78  }
79  // At least 1000 packages should have a score
80  assert(has > 1000);
81  }
82 
83  // Check that scores are meaningful
84  Test validScores()
85  {
86  assert(popcon["apt"] > popcon["libapt-pkg-dev"]);
87  }
88 
89  // If there is no data, Popcon should work as if all scores were 0
91  {
96  Popcon empty;
97 
98  assert_eq(empty.timestamp(), 0);
99  assert(!empty.hasData());
100 
101  assert_eq(empty.submissions(), 0);
102  assert(empty.size() == 0);
103  assert(empty.score("apt") == 0.0);
104  }
105 
106 };
107 
108 // vim:set ts=4 sw=4:
Definition: popcon.test.h:34
Apt apt
Definition: popcon.test.h:41
Definition: popcon/maint/path.h:66
popcon::Path::OverridePopconUserSourceDir odusd
Definition: popcon.test.h:38
Definition: popcon/maint/path.h:96
TestPopcon()
Definition: popcon.test.h:44
size_t submissions() const
Return the total number of popcon submissions.
Definition: popcon.h:102
Maps Packages to IDs and vice-versa.
Definition: popcon.h:72
size_t size() const
Get the number of packages in the index.
Definition: popcon.h:105
Test haveScores()
Definition: popcon.test.h:70
popcon::Path::OverridePopconUserIndexDir oduid
Definition: popcon.test.h:39
popcon::Path::OverridePopconSourceDir odsd
Definition: popcon.test.h:36
Definition: popcon/maint/path.h:86
High-level access to the Apt cache, as a data provider for the ept framework.
Definition: apt/apt.h:60
Test fallbackValues()
Definition: popcon.test.h:90
bool hasData() const
Return true if this data source has data, false if it's empty.
Definition: popcon.h:99
Definition: apt/apt.h:67
High-level front-end to libapt-pkg, as a data provider for the ept framework.
float score(size_t idx) const
Get the score by index.
Definition: popcon.h:137
time_t timestamp() const
Get the timestamp of when the index was last updated.
Definition: popcon.h:96
Test validScores()
Definition: popcon.test.h:84
Definition: popcon/maint/path.h:76
Test accessibility()
Definition: popcon.test.h:60
Popcon popcon
Definition: popcon.test.h:42
Test basicAccess()
Definition: popcon.test.h:51
popcon::Path::OverridePopconIndexDir odid
Definition: popcon.test.h:37
popcon paths