Unity Scopes API
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 #pragma once
20 
21 #include <functional>
22 
23 namespace unity
24 {
25 
26 namespace scopes
27 {
28 class ScopeBase;
29 
30 namespace testing
31 {
36 class Sample
37 {
38 public:
40  typedef std::size_t SizeType;
42  typedef double ValueType;
44  typedef std::function<void(ValueType)> Enumerator;
45 
47  virtual ~Sample() = default;
48 
49  Sample& operator=(const Sample&) = delete;
50  Sample& operator=(Sample&&) = delete;
51  bool operator==(const Sample&) const = delete;
55  virtual SizeType get_size() const = 0;
56 
58  virtual ValueType get_mean() const = 0;
59 
61  virtual ValueType get_variance() const = 0;
62 
64  virtual void enumerate(const Enumerator& enumerator) const = 0;
65 
66 protected:
68  Sample() = default;
69  Sample(const Sample&) = default;
70  Sample(Sample&&) = default;
72 };
73 
83 enum class HypothesisStatus
84 {
85  rejected,
86  not_rejected
87 };
88 
90 typedef std::function<HypothesisStatus(double)> Hypothesis;
91 
96 enum class Confidence
97 {
98  zero_point_five_percent,
99  one_percent,
100  two_point_five_percent,
101  five_percent,
102  ten_percent
103 };
104 
106 typedef std::function<HypothesisStatus(Confidence)> HypothesisForWellKnownConfidence;
107 
110 {
115  struct Result
116  {
117  HypothesisForWellKnownConfidence data_fits_normal_distribution;
118  };
119 
125  Result for_normality(const Sample& sample);
126 };
127 
166 {
171  struct Result
172  {
173  double t;
174  Hypothesis both_means_are_equal;
177  };
178 
187  const Sample& sample,
188  Sample::ValueType mean,
189  Sample::ValueType std_dev);
190 
198  const Sample& sample1,
199  const Sample& sample2);
200 
201 
202 };
203 
204 } // namespace testing
205 
206 } // namespace scopes
207 
208 } // namespace unity
Executing the test returns a set of hypothesis that have to be evaluated at the desired confidence le...
Definition: Statistics.h:171
Hypothesis both_means_are_equal
H0, both means are equal.
Definition: Statistics.h:174
std::function< void(ValueType)> Enumerator
Definition: Statistics.h:44
The Sample class models the interface to a sample of raw observations and their statistical propertie...
Definition: Statistics.h:36
Definition: OnlineAccountClient.h:39
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:109
virtual void enumerate(const Enumerator &enumerator) const =0
Top-level namespace for all things Unity-related.
Definition: Version.h:49
virtual ValueType get_variance() const =0
virtual ValueType get_mean() const =0
std::size_t SizeType
Definition: Statistics.h:40
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:165
double t
The t value of the test.
Definition: Statistics.h:173
Hypothesis sample1_mean_lt_sample2_mean
H1, sample1 mean < sample2 mean.
Definition: Statistics.h:175
Executing the test returns a set of hypothesis that have to be evaluated at the desired confidence le...
Definition: Statistics.h:115
Hypothesis sample1_mean_gt_sample2_mean
H2, sample1 mean > sample2 mean.
Definition: Statistics.h:176
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:42
HypothesisForWellKnownConfidence data_fits_normal_distribution
H0, data is normally distributed.
Definition: Statistics.h:117