libept
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
60  Test accessibility()
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
90  Test fallbackValues()
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: