Skip to content

Commit d46d760

Browse files
Added namespaces
1 parent 83ba7d5 commit d46d760

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

probability/exponential_dist.cpp

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
#include <stdexcept> // For std::invalid_argument
1919
#include <string> // For std::string
2020

21+
/**
22+
* @namespace probability
23+
* @brief Probability algorithms
24+
*/
25+
namespace probability {
26+
/**
27+
* @namespace exponential_dist
28+
* @brief Functions for the [Exponential
29+
* Distribution](https://en.wikipedia.org/wiki/Exponential_distribution)
30+
* algorithm implementation
31+
*/
32+
namespace geometric_dist {
2133
/**
2234
* @brief the expected value of the exponential distribution
2335
* @returns \f[\mu = \frac{1}{\lambda}\f]
@@ -50,6 +62,8 @@ double exponential_std(double lambda) {
5062
}
5163
return 1 / lambda;
5264
}
65+
} // namespace geometric_dist
66+
} // namespace probability
5367

5468
/**
5569
* @brief Self-test implementations
@@ -77,38 +91,50 @@ static void test() {
7791
const float threshold = 1e-3f;
7892

7993
std::cout << "Test for lambda = 1 \n";
80-
assert(std::abs(expected_1 - exponential_expected(lambda_1)) < threshold);
81-
assert(std::abs(var_1 - exponential_var(lambda_1)) < threshold);
82-
assert(std::abs(std_1 - exponential_std(lambda_1)) < threshold);
94+
assert(
95+
std::abs(expected_1 - probability::geometric_dist::exponential_expected(
96+
lambda_1)) < threshold);
97+
assert(std::abs(var_1 - probability::geometric_dist::exponential_var(
98+
lambda_1)) < threshold);
99+
assert(std::abs(std_1 - probability::geometric_dist::exponential_std(
100+
lambda_1)) < threshold);
83101
std::cout << "ALL TEST PASSED\n\n";
84102

85103
std::cout << "Test for lambda = 2 \n";
86-
assert(std::abs(expected_2 - exponential_expected(lambda_2)) < threshold);
87-
assert(std::abs(var_2 - exponential_var(lambda_2)) < threshold);
88-
assert(std::abs(std_2 - exponential_std(lambda_2)) < threshold);
104+
assert(
105+
std::abs(expected_2 - probability::geometric_dist::exponential_expected(
106+
lambda_2)) < threshold);
107+
assert(std::abs(var_2 - probability::geometric_dist::exponential_var(
108+
lambda_2)) < threshold);
109+
assert(std::abs(std_2 - probability::geometric_dist::exponential_std(
110+
lambda_2)) < threshold);
89111
std::cout << "ALL TEST PASSED\n\n";
90112

91113
std::cout << "Test for lambda = 3 \n";
92-
assert(std::abs(expected_3 - exponential_expected(lambda_3)) < threshold);
93-
assert(std::abs(var_3 - exponential_var(lambda_3)) < threshold);
94-
assert(std::abs(std_3 - exponential_std(lambda_3)) < threshold);
114+
assert(
115+
std::abs(expected_3 - probability::geometric_dist::exponential_expected(
116+
lambda_3)) < threshold);
117+
assert(std::abs(var_3 - probability::geometric_dist::exponential_var(
118+
lambda_3)) < threshold);
119+
assert(std::abs(std_3 - probability::geometric_dist::exponential_std(
120+
lambda_3)) < threshold);
95121
std::cout << "ALL TEST PASSED\n\n";
96122

97123
std::cout << "Test for lambda = 0 \n";
98124
try {
99-
exponential_expected(lambda_4);
100-
exponential_var(lambda_4);
101-
exponential_std(lambda_4);
125+
probability::geometric_dist::exponential_expected(lambda_4);
126+
probability::geometric_dist::exponential_var(lambda_4);
127+
probability::geometric_dist::exponential_std(lambda_4);
102128
} catch (std::invalid_argument& err) {
103129
assert(std::string(err.what()) == "lambda must be greater than 0");
104130
}
105131
std::cout << "ALL TEST PASSED\n\n";
106132

107133
std::cout << "Test for lambda = -2.3 \n";
108134
try {
109-
exponential_expected(lambda_5);
110-
exponential_var(lambda_5);
111-
exponential_std(lambda_5);
135+
probability::geometric_dist::exponential_expected(lambda_5);
136+
probability::geometric_dist::exponential_var(lambda_5);
137+
probability::geometric_dist::exponential_std(lambda_5);
112138
} catch (std::invalid_argument& err) {
113139
assert(std::string(err.what()) == "lambda must be greater than 0");
114140
}

0 commit comments

Comments
 (0)