Files
pay/testing/utils/TestUtils.cpp
T

56 lines
2.8 KiB
C++
Raw Permalink Normal View History

/*
* This file is part of the Flowee project
* Copyright (C) 2025 Tom Zander <tom@flowee.org>
*
* 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 3 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. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestUtils.h"
#include <FloweePay.h>
#include <qtest.h>
#include <qtestcase.h>
#include <QLocale>
void TestUtils::testAmountToString()
{
QCOMPARE(FloweePay::amountToString(12345678, FloweePay::BCH), "0.12345678");
QCOMPARE(FloweePay::amountToString(512345678, FloweePay::BCH), "5.12345678");
QCOMPARE(FloweePay::amountToString(12345678, FloweePay::MilliBCH), "123.45678");
QCOMPARE(FloweePay::amountToString(512345678, FloweePay::MilliBCH), "5,123.45678");
QCOMPARE(FloweePay::amountToString(12345678, FloweePay::MicroBCH), "123,456.78");
QCOMPARE(FloweePay::amountToString(512345678, FloweePay::MicroBCH), "5,123,456.78");
QCOMPARE(FloweePay::amountToString(12345678, FloweePay::Bits), "123,456.78");
QCOMPARE(FloweePay::amountToString(512345678, FloweePay::Bits), "5,123,456.78");
QCOMPARE(FloweePay::amountToString(12345678, FloweePay::Satoshis), "12,345,678");
QCOMPARE(FloweePay::amountToString(512345678, FloweePay::Satoshis), "512,345,678");
QCOMPARE(FloweePay::amountToString(1, FloweePay::Satoshis), "1");
QCOMPARE(FloweePay::amountToString(10, FloweePay::Satoshis), "10");
QCOMPARE(FloweePay::amountToString(100, FloweePay::Satoshis), "100");
QCOMPARE(FloweePay::amountToString(1000, FloweePay::Satoshis), "1,000");
QCOMPARE(FloweePay::amountToString(10000, FloweePay::Satoshis), "10,000");
QCOMPARE(FloweePay::amountToString(100000, FloweePay::Satoshis), "100,000");
QCOMPARE(FloweePay::amountToString(0, FloweePay::BCH), "0.00000000");
QCOMPARE(FloweePay::amountToString(0, FloweePay::MilliBCH), "0.00000");
QCOMPARE(FloweePay::amountToString(1, FloweePay::MilliBCH), "0.00001");
QCOMPARE(FloweePay::amountToString(10, FloweePay::MilliBCH), "0.00010");
QCOMPARE(FloweePay::amountToString(100, FloweePay::MilliBCH), "0.00100");
QCOMPARE(FloweePay::amountToString(1000, FloweePay::MilliBCH), "0.01000");
QCOMPARE(FloweePay::amountToString(10000, FloweePay::MilliBCH), "0.10000");
QCOMPARE(FloweePay::amountToString(100000, FloweePay::MilliBCH), "1.00000");
}
QTEST_MAIN(TestUtils)