MCPcopy Create free account
hub / github.com/davisking/dlib / test_uniform_random_hash

Function test_uniform_random_hash

dlib/test/rand.cpp:311–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

309 }
310
311 void test_uniform_random_hash()
312 {
313 print_spinner();
314 dlog << LINFO << "test_uniform_random_hash()";
315 double cnt1 = 0; // num <= 0.2
316 double cnt2 = 0; // num <= 0.4
317 double cnt3 = 0; // num <= 0.6
318 double cnt4 = 0; // num <= 0.8
319 double cnt5 = 0; // num <= 1.0
320
321 double min_val = 10;
322 double max_val = 0;
323
324 const unsigned long total = 1000000;
325 for (unsigned long i = 0; i < total; ++i)
326 {
327 const double r = uniform_random_hash(i,0,0);
328 min_val = min(r,min_val);
329 max_val = max(r,max_val);
330
331 if (r <= 0.2) cnt1 += 1;
332 if (r <= 0.4) cnt2 += 1;
333 if (r <= 0.6) cnt3 += 1;
334 if (r <= 0.8) cnt4 += 1;
335 if (r <= 1.0) cnt5 += 1;
336 }
337 for (unsigned long i = 0; i < total; ++i)
338 {
339 const double r = uniform_random_hash(0,i,0);
340 min_val = min(r,min_val);
341 max_val = max(r,max_val);
342
343 if (r <= 0.2) cnt1 += 1;
344 if (r <= 0.4) cnt2 += 1;
345 if (r <= 0.6) cnt3 += 1;
346 if (r <= 0.8) cnt4 += 1;
347 if (r <= 1.0) cnt5 += 1;
348 }
349 for (unsigned long i = 0; i < total; ++i)
350 {
351 const double r = uniform_random_hash(0,0,i);
352 min_val = min(r,min_val);
353 max_val = max(r,max_val);
354
355 if (r <= 0.2) cnt1 += 1;
356 if (r <= 0.4) cnt2 += 1;
357 if (r <= 0.6) cnt3 += 1;
358 if (r <= 0.8) cnt4 += 1;
359 if (r <= 1.0) cnt5 += 1;
360 }
361
362 cnt1 /= total*3;
363 cnt2 /= total*3;
364 cnt3 /= total*3;
365 cnt4 /= total*3;
366 cnt5 /= total*3;
367
368 dlog << LINFO << "cnt1: "<< cnt1;

Callers 1

perform_testMethod · 0.85

Calls 5

print_spinnerFunction · 0.85
uniform_random_hashFunction · 0.85
absFunction · 0.85
minFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected