add string formatter

This commit is contained in:
2016-07-07 13:36:30 +03:00
parent 085eec7a3d
commit 0d4211b2c4
14 changed files with 776 additions and 29 deletions

View File

@ -49,8 +49,7 @@ void TestAWFloatFormatter::test_count()
QCOMPARE(formatter->count(), count);
// test
double value = AWTestLibrary::randomDouble();
QString output = formatter->convert(value);
QString output = formatter->convert(AWTestLibrary::randomDouble());
QCOMPARE(output.count(), count);
// reset
@ -67,8 +66,7 @@ void TestAWFloatFormatter::test_fillChar()
formatter->setCount(101);
// test
int value = AWTestLibrary::randomInt();
QString output = formatter->convert(value);
QString output = formatter->convert(AWTestLibrary::randomInt());
QVERIFY(output.startsWith(QChar(c)));
// reset
@ -77,6 +75,24 @@ void TestAWFloatFormatter::test_fillChar()
}
void TestAWFloatFormatter::test_forceWidth()
{
// assign
int count = AWTestLibrary::randomInt(6);
formatter->setForceWidth(true);
formatter->setCount(count);
QCOMPARE(formatter->forceWidth(), true);
// test
QString output = formatter->convert(AWTestLibrary::randomDouble());
QCOMPARE(output.count(), count);
// reset
formatter->setForceWidth(false);
formatter->setCount(0);
}
void TestAWFloatFormatter::test_format()
{
// assign
@ -87,8 +103,7 @@ void TestAWFloatFormatter::test_format()
QCOMPARE(formatter->format(), 'e');
// test
double value = AWTestLibrary::randomDouble();
QString output = formatter->convert(value);
QString output = formatter->convert(AWTestLibrary::randomDouble());
QVERIFY(output.contains('e'));
// reset
@ -104,8 +119,7 @@ void TestAWFloatFormatter::test_precision()
QCOMPARE(formatter->precision(), precision);
// test
double value = AWTestLibrary::randomDouble();
QString output = formatter->convert(value);
QString output = formatter->convert(AWTestLibrary::randomDouble());
output.remove(QString("0."));
QCOMPARE(output.count(), precision);
@ -157,6 +171,7 @@ void TestAWFloatFormatter::test_copy()
QCOMPARE(newFormatter->count(), formatter->count());
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
QCOMPARE(newFormatter->forceWidth(), formatter->forceWidth());
QCOMPARE(newFormatter->format(), formatter->format());
QCOMPARE(newFormatter->multiplier(), formatter->multiplier());
QCOMPARE(newFormatter->precision(), formatter->precision());
@ -171,6 +186,7 @@ void TestAWFloatFormatter::doRandom()
{
formatter->setCount(AWTestLibrary::randomInt());
formatter->setFillChar(QChar(AWTestLibrary::randomChar()));
formatter->setForceWidth(AWTestLibrary::randomInt() % 2);
formatter->setFormat(AWTestLibrary::randomChar());
formatter->setMultiplier(AWTestLibrary::randomDouble());
formatter->setPrecision(AWTestLibrary::randomInt());