1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Copyright © 2015 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
#include "igt_core.h"
#include "igt_stats.h"
/* Make sure we zero igt_stats_t fields at init() time */
static void test_init_zero(void)
{
igt_stats_t stats;
stats.mean = 1.;
igt_stats_init(&stats, 2);
igt_assert(stats.mean == 0.);
}
static void test_mean(void)
{
igt_stats_t stats;
double mean;
igt_stats_init(&stats, 5);
igt_stats_push(&stats, 2);
igt_stats_push(&stats, 4);
igt_stats_push(&stats, 6);
igt_stats_push(&stats, 8);
igt_stats_push(&stats, 10);
mean = igt_stats_get_mean(&stats);
igt_assert(mean == (2 + 4 + 6 + 8 + 10) / 5.);
igt_stats_fini(&stats);
}
static void test_invalidate_mean(void)
{
igt_stats_t stats;
double mean1, mean2;
igt_stats_init(&stats, 6);
igt_stats_push(&stats, 2);
igt_stats_push(&stats, 4);
igt_stats_push(&stats, 6);
igt_stats_push(&stats, 8);
igt_stats_push(&stats, 10);
mean1 = igt_stats_get_mean(&stats);
igt_assert(mean1 == (2 + 4 + 6 + 8 + 10) / 5.);
igt_stats_push(&stats, 100);
mean2 = igt_stats_get_mean(&stats);
igt_assert(mean1 != mean2);
igt_stats_fini(&stats);
}
/*
* Taken from the "Basic examples" section of:
* https://en.wikipedia.org/wiki/Standard_deviation
*/
static void test_std_deviation(void)
{
igt_stats_t stats;
double mean, variance, std_deviation;
igt_stats_init(&stats, 8);
igt_stats_push(&stats, 2);
igt_stats_push(&stats, 4);
igt_stats_push(&stats, 4);
igt_stats_push(&stats, 4);
igt_stats_push(&stats, 5);
igt_stats_push(&stats, 5);
igt_stats_push(&stats, 7);
igt_stats_push(&stats, 9);
mean = igt_stats_get_mean(&stats);
igt_assert(mean == (2 + 3 * 4 + 2 * 5 + 7 + 9) / 8.);
variance = igt_stats_get_variance(&stats);
igt_assert(variance == 4);
std_deviation = igt_stats_get_std_deviation(&stats);
igt_assert(std_deviation == 2);
igt_stats_fini(&stats);
}
igt_simple_main
{
test_init_zero();
test_mean();
test_invalidate_mean();
test_std_deviation();
}
|