Lv2: Improve LED widget's digit calculation

This improves the way digits are calculated for display in
`Lv2ViewProc`:

- More than 2 digits are now recognized
- Minus signs are now recognized
- Tests have been added
This commit is contained in:
Johannes Lorenz
2023-09-22 23:58:52 +02:00
committed by Johannes Lorenz
parent c309d8bd11
commit d97377b640
4 changed files with 85 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ ADD_EXECUTABLE(tests
src/core/ArrayVectorTest.cpp
src/core/AutomatableModelTest.cpp
src/core/MathTest.cpp
src/core/ProjectVersionTest.cpp
src/core/RelativePathsTest.cpp

View File

@@ -0,0 +1,53 @@
/*
* MathTest.cpp
*
* Copyright (c) 2023 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "QTestSuite.h"
#include "lmms_math.h"
#include <QDir>
class MathTest : QTestSuite
{
Q_OBJECT
private slots:
void NumDigitsTest()
{
using namespace lmms;
QCOMPARE(numDigitsAsInt(1.f), 1);
QCOMPARE(numDigitsAsInt(9.9f), 2);
QCOMPARE(numDigitsAsInt(10.f), 2);
QCOMPARE(numDigitsAsInt(0.f), 1);
QCOMPARE(numDigitsAsInt(-100.f), 4);
QCOMPARE(numDigitsAsInt(-99.f), 3);
QCOMPARE(numDigitsAsInt(-0.4f), 1); // there is no "-0" for LED spinbox
QCOMPARE(numDigitsAsInt(-0.99f), 2);
QCOMPARE(numDigitsAsInt(1000000000), 10);
QCOMPARE(numDigitsAsInt(-1000000000), 11);
QCOMPARE(numDigitsAsInt(900000000), 9);
QCOMPARE(numDigitsAsInt(-900000000), 10);
}
} MathTests;
#include "MathTest.moc"