GCC Code Coverage Report


Directory: ./
File: tests/test-statistics.cc
Date: 2025-03-06 12:03:19
Exec Total Coverage
Lines: 23 32 71.9%
Branches: 14 34 41.2%

Line Branch Exec Source
1 // Copyright (c) 2014, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of hpp-statistics.
5 // hpp-statistics is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // hpp-statistics is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // hpp-statistics. If not, see <http://www.gnu.org/licenses/>.
16
17 #include <stdlib.h>
18 #include <time.h>
19
20 #include <iostream>
21 #include <list>
22
23 #include "hpp/statistics/bin.hh"
24
25 using hpp::statistics::Bin;
26 using hpp::statistics::Statistics;
27
28 class TestBin : public Bin {
29 public:
30 int val;
31 std::list<double> l;
32
33 200 TestBin(int i) : val(i) {}
34
35 std::ostream& printValue(std::ostream& os) const {
36 os << val << " has :";
37 for (std::list<double>::const_iterator it = l.begin(); it != l.end(); ++it)
38 os << " " << *it << std::endl;
39 return os << std::endl;
40 }
41
42 10000 bool operator<(const TestBin& rhs) const { return val < rhs.val; }
43
44 100 bool operator==(const TestBin& rhs) const { return val == rhs.val; }
45 };
46
47 class TestStatistics : public Statistics<TestBin> {
48 public:
49 100 void add(int n, double d) {
50 100 TestBin b(n);
51
1/2
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
100 TestStatistics::iterator it = insert(b);
52
1/2
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
100 it->l.push_back(d);
53 100 }
54 };
55
56 1 int main() {
57 1 srand((unsigned int)time(NULL));
58
59
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TestStatistics t;
60
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 double* check = new double[100];
61 1 int status = EXIT_SUCCESS;
62
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
101 for (int i = 0; i < 100; i++) {
63 100 check[i] = ((double)(rand()) / (double)rand());
64
1/2
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
100 t.add(i, check[i]);
65 }
66
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
101 for (int i = 0; i < 100; i++) {
67
1/2
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
100 TestStatistics::const_iterator it = t.find(i);
68
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 100 times.
100 if (it == t.end()) {
69 status = EXIT_FAILURE;
70 break;
71 }
72
2/6
✗ Branch 2 not taken.
✓ Branch 3 taken 100 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 100 times.
100 if (it->l.size() != 1 && check[i] != it->l.front()) {
73 status = EXIT_FAILURE;
74 break;
75 }
76 }
77
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 delete[] check;
78 1 return status;
79 1 }
80