Directory: | ./ |
---|---|
File: | tests/test-successstatistics.cc |
Date: | 2025-03-06 12:03:19 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 25 | 29 | 86.2% |
Branches: | 19 | 54 | 35.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 | |||
22 | #include "hpp/statistics/success-bin.hh" | ||
23 | |||
24 | HPP_DEFINE_REASON_FAILURE(REASON_TEST, "Fake reason for testing purpose"); | ||
25 | |||
26 | using namespace hpp; | ||
27 | |||
28 | 1 | int main() { | |
29 | /* initialize random seed: */ | ||
30 | 1 | srand((unsigned int)time(NULL)); | |
31 | |||
32 | using namespace hpp::statistics; | ||
33 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | SuccessStatistics ss; |
34 | std::size_t counter[3]; | ||
35 | 1 | counter[0] = 0; | |
36 | 1 | counter[1] = 0; | |
37 | 1 | counter[2] = 0; | |
38 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < 100; i++) { |
39 | 100 | std::size_t nb = static_cast<std::size_t>(rand() % 3); | |
40 | 100 | counter[nb]++; | |
41 |
3/4✓ Branch 0 taken 30 times.
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
100 | switch (nb) { |
42 | 30 | case 0: | |
43 |
1/2✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
|
30 | ss.addSuccess(); |
44 | 30 | break; | |
45 | 34 | case 1: | |
46 |
1/2✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
|
34 | ss.addFailure(); |
47 | 34 | break; | |
48 | 36 | case 2: | |
49 |
1/2✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
|
36 | ss.addFailure(REASON_TEST); |
50 | 36 | break; | |
51 | } | ||
52 | } | ||
53 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (ss.nbSuccess() != counter[0] || |
54 |
4/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
|
2 | ss.nbFailure(SuccessBin::REASON_UNKNOWN) != counter[1] || |
55 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | ss.nbFailure(REASON_TEST) != counter[2]) { |
56 | ✗ | std::cout << ss << std::endl; | |
57 | ✗ | std::cout << "Real frequencies are: ( " << counter[0] << ", " << counter[1] | |
58 | ✗ | << ", " << counter[2] << ")" << std::endl; | |
59 | ✗ | return EXIT_FAILURE; | |
60 | } | ||
61 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if (ss.nbFailure() != counter[1] + counter[2]) return EXIT_FAILURE; |
62 | 1 | return EXIT_SUCCESS; | |
63 | 1 | } | |
64 |