1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-03-04 19:27:29 +01:00
SqMod/vendor/POCO/Foundation/testsuite/src/RandomStreamTest.cpp
Sandu Liviu Catalin 4a6bfc086c Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
2021-01-30 08:51:39 +02:00

76 lines
1.2 KiB
C++

//
// RandomStreamTest.cpp
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "RandomStreamTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/RandomStream.h"
#include <vector>
#include <cmath>
using Poco::RandomInputStream;
RandomStreamTest::RandomStreamTest(const std::string& name): CppUnit::TestCase(name)
{
}
RandomStreamTest::~RandomStreamTest()
{
}
void RandomStreamTest::testStream()
{
RandomInputStream rnd;
const int n = 16;
std::vector<int> d(n, 0);
for (int i = 0; i < 1000; ++i)
{
unsigned char c;
rnd >> c;
d[c & 0x0F]++;
d[(c >> 4) & 0x0F]++;
}
int sum = 0;
for (int k = 0; k < n; ++k) sum += d[k];
int avg = sum/n;
int var = 0;
for (int k = 0; k < n; ++k) var += (d[k] - avg)*(d[k] - avg);
var /= n;
int sd = int(std::sqrt((double) var));
assertTrue (110 < avg && avg < 140);
assertTrue (sd < 20);
}
void RandomStreamTest::setUp()
{
}
void RandomStreamTest::tearDown()
{
}
CppUnit::Test* RandomStreamTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("RandomStreamTest");
CppUnit_addTest(pSuite, RandomStreamTest, testStream);
return pSuite;
}