Unity Scopes API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Statistics.h
1 /*
2  * Copyright (C) 2013 Canonical Ltd
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
19 #ifndef UNITY_SCOPES_TESTING_STATISTICS_H
20 #define UNITY_SCOPES_TESTING_STATISTICS_H
21 
22 #include <functional>
23 
24 namespace unity
25 {
26 
27 namespace scopes
28 {
29 class ScopeBase;
30 
31 namespace testing
32 {
37 class Sample
38 {
39 public:
41  typedef std::size_t SizeType;
43  typedef double ValueType;
45  typedef std::function<void(ValueType)> Enumerator;
46 
48  virtual ~Sample() = default;
49 
50  Sample& operator=(const Sample&) = delete;
51  Sample& operator=(Sample&&) = delete;
52  bool operator==(const Sample&) const = delete;
56  virtual SizeType get_size() const = 0;
57 
59  virtual ValueType get_mean() const = 0;
60 
62  virtual ValueType get_variance() const = 0;
63 
65  virtual void enumerate(const Enumerator& enumerator) const = 0;
66 
67 protected:
69  Sample() = default;
70  Sample(const Sample&) = default;
71  Sample(Sample&&) = default;
73 };
74 
84 enum class HypothesisStatus
85 {
86  rejected,
87  not_rejected
88 };
89 
91 typedef std::function<HypothesisStatus(double)> Hypothesis;
92 
97 enum class Confidence
98 {
99  zero_point_five_percent,
100  one_percent,
101  two_point_five_percent,
102  five_percent,
103  ten_percent
104 };
105 
107 typedef std::function<HypothesisStatus(Confidence)> HypothesisForWellKnownConfidence;
108 
111 {
116  struct Result
117  {
118  HypothesisForWellKnownConfidence data_fits_normal_distribution;
119  };
120 
126  Result for_normality(const Sample& sample);
127 };
128 
167 {
172  struct Result
173  {
174  double t;
175  Hypothesis both_means_are_equal;
178  };
179 
188  const Sample& sample,
189  Sample::ValueType mean,
190  Sample::ValueType std_dev);
191 
199  const Sample& sample1,
200  const Sample& sample2);
201 
202 
203 };
204 
205 } // namespace testing
206 
207 } // namespace scopes
208 
209 } // namespace unity
210 
211 #endif
Executing the test returns a set of hypothesis that have to be evaluated at the desired confidence le...
Definition: Statistics.h:172
Hypothesis both_means_are_equal
H0, both means are equal.
Definition: Statistics.h:175
std::function< void(ValueType)> Enumerator
Definition: Statistics.h:45
The Sample class models the interface to a sample of raw observations and their statistical propertie...
Definition: Statistics.h:37
Result for_normality(const Sample &sample)
for_normality evaluates a given sample to check if its underlying distribution is normal...
Definition: Statistics.cpp:37
Implements the Anderson-Darling test for normality for the case of empirical mean and variance...
Definition: Statistics.h:110
virtual void enumerate(const Enumerator &enumerator) const =0
virtual ValueType get_variance() const =0
virtual ValueType get_mean() const =0
std::size_t SizeType
Definition: Statistics.h:41
virtual SizeType get_size() const =0
Implements different variants of the Student's T-test (see http://en.wikipedia.org/wiki/Student's_t-t...
Definition: Statistics.h:166
double t
The t value of the test.
Definition: Statistics.h:174
Hypothesis sample1_mean_lt_sample2_mean
H1, sample1 mean < sample2 mean.
Definition: Statistics.h:176
Executing the test returns a set of hypothesis that have to be evaluated at the desired confidence le...
Definition: Statistics.h:116
Hypothesis sample1_mean_gt_sample2_mean
H2, sample1 mean > sample2 mean.
Definition: Statistics.h:177
Result one_sample(const Sample &sample, Sample::ValueType mean, Sample::ValueType std_dev)
one_sample calculates the Student's T test for one sample and a known mean and std. dev..
Definition: Statistics.cpp:90
Result two_independent_samples(const Sample &sample1, const Sample &sample2)
two_independent_samples calculates the Student's T test for two samples
Definition: Statistics.cpp:124
double ValueType
Definition: Statistics.h:43
HypothesisForWellKnownConfidence data_fits_normal_distribution
H0, data is normally distributed.
Definition: Statistics.h:118