mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-07 02:45:51 +00:00
add test library for random values generation
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "awtestlibrary.h"
|
||||
#include "awnoformatter.h"
|
||||
|
||||
|
||||
@ -43,12 +44,12 @@ void TestAWNoFormatter::test_values()
|
||||
void TestAWNoFormatter::test_conversion()
|
||||
{
|
||||
// integer
|
||||
int randomInt = rand();
|
||||
int randomInt = AWTestLibrary::randomInt();
|
||||
QCOMPARE(formatter->convert(randomInt), QString::number(randomInt));
|
||||
// float
|
||||
QWARN("Float conversion isn't tested here due to possible rounding errors");
|
||||
// string
|
||||
QString randomString = generateRandomString();
|
||||
QString randomString = AWTestLibrary::randomString();
|
||||
QCOMPARE(formatter->convert(randomString), randomString);
|
||||
}
|
||||
|
||||
@ -63,19 +64,4 @@ void TestAWNoFormatter::test_copy()
|
||||
}
|
||||
|
||||
|
||||
QString TestAWNoFormatter::generateRandomString()
|
||||
{
|
||||
QString string;
|
||||
|
||||
int diff = 'Z' - 'A';
|
||||
int count = rand() % 100 + 1;
|
||||
for (int i = 0; i < count; i++) {
|
||||
char c = 'A' + (rand() % diff);
|
||||
string += QChar(c);
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestAWNoFormatter);
|
||||
|
Reference in New Issue
Block a user