A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Haivision/srt/commit/fa1c3736cfd3a76f7892f186955aa57cbaaaa290 below:

[tests] Added check for a minimal value of the uniform distribution. · Haivision/srt@fa1c373 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+36

-19

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+36

-19

lines changed Original file line number Diff line number Diff line change

@@ -126,7 +126,10 @@ class TestConnection

126 126

};

127 127 128 128 129 - 129 +

// This test establishes multiple connections to a single SRT listener on a localhost port.

130 +

// Packets are submitted for sending to all those connections in a non-blocking mode.

131 +

// Then all connections are closed. Some sockets may potentially still have undelivered packets.

132 +

// This test tries to reproduce the issue described in #1182, and fixed by #1315.

130 133

TEST_F(TestConnection, Multiple)

131 134

{

132 135

const sockaddr_in lsa = m_sa;

Original file line number Diff line number Diff line change

@@ -1,4 +1,5 @@

1 1

#include "gtest/gtest.h"

2 +

#include <array>

2 3

#include <chrono>

3 4

#include <thread>

4 5

#include <future>

@@ -15,14 +16,6 @@

15 16

using namespace std;

16 17

using namespace srt::sync;

17 18 18 -

// GNUC supports C++14 starting from version 5

19 -

//#if defined(__GNUC__) && (__GNUC__ < 5)

20 -

////namespace srt

21 -

// constexpr chrono::milliseconds operator"" ms(

22 -

// unsigned long long _Val) { // return integral milliseconds

23 -

// return chrono::milliseconds(_Val);

24 -

//}

25 -

//#endif

26 19 27 20

TEST(SyncDuration, BasicChecks)

28 21

{

@@ -159,23 +152,44 @@ TEST(SyncDuration, OperatorMultIntEq)

159 152 160 153

TEST(SyncRandom, GenRandomInt)

161 154

{

162 -

vector<int> mn(64);

155 +

array<int, 64> mn = {};

163 156 164 -

for (int i = 0; i < 2048; ++i)

157 +

// Check generated values are in the specified range.

158 +

const size_t n = 2048;

159 +

for (size_t i = 0; i < n; ++i)

165 160

{

166 -

const int rand_val = genRandomInt(0, 63);

161 +

const int rand_val = genRandomInt(0, mn.size() - 1);

167 162

ASSERT_GE(rand_val, 0);

168 -

ASSERT_LE(rand_val, 63);

163 +

ASSERT_LT(rand_val, mn.size());

169 164

++mn[rand_val];

170 165

}

171 166 167 +

// Check the distribution is more or less uniform.

168 +

// 100% uniform if each value is generated (n / (2 * mn.size())) times.

169 +

// We expect at least half of that value for a random uniform distribution.

170 +

const int min_value = n / (2 * mn.size()) - 1;

171 +

cout << "min value: " << min_value << endl;

172 +

for (size_t i = 0; i < mn.size(); ++i)

173 +

{

174 +

EXPECT_GE(mn[i], min_value) << "i=" << i << ". Ok-ish if the count is non-zero.";

175 +

}

176 + 172 177

// Uncomment to see the distribution.

173 -

// for (size_t i = 0; i < mn.size(); ++i)

174 -

// {

175 -

// cout << i << '\t';

176 -

// for (int j=0; j<mn[i]; ++j) cout << '*';

177 -

// cout << '\n';

178 -

// }

178 +

//for (size_t i = 0; i < mn.size(); ++i)

179 +

//{

180 +

// cout << i << '\t';

181 +

// for (int j=0; j<mn[i]; ++j) cout << '*';

182 +

// cout << '\n';

183 +

//}

184 + 185 +

// Check INT32_MAX

186 +

for (size_t i = 0; i < n; ++i)

187 +

{

188 +

const int rand_val = genRandomInt(INT32_MAX - 1, INT32_MAX);

189 + 190 +

EXPECT_GE(rand_val, INT32_MAX - 1);

191 +

EXPECT_LE(rand_val, INT32_MAX);

192 +

}

179 193

}

180 194 181 195

/*****************************************************************************/

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4