/*******************************************************************************
***  This file is part of Pecunia.                                           ***
***                                                                          ***
***  Copyright (C) 2017, 2018, 2019, 2020, 2021, 2023                        ***
***  John Schneiderman <Licencing _AT_ Schneiderman _DOT_ me>                ***
***                                                                          ***
***  This program is free software: you can redistribute it and/or modify it ***
***  under the terms of the GNU Lesser 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 Lesser General Public License for more details.             ***
***                                                                          ***
***  You should have received a copy of the GNU Lesser General Public License***
***  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
*******************************************************************************/
#include <QObject>
using ::QObject;
#include <QTest>
// Used for QTEST_MAIN

#include <stdexcept>
using std::overflow_error;

#include <pecunia/Codes.h>
using pecunia::currency::Iso4217Codes;
#include <pecunia/Conversion.h>
using pecunia::toMinorUnit;
#include <pecunia/MoneyTypes.h>
using pecunia::MinorUnit;


namespace pecunia
{
namespace tests
{

struct ConversionUT : QObject
{
	Q_OBJECT

private slots:
	//{ toMinorUnit unit tests

	void toMinorUnit_validValue_ShouldConvert()
	{
		QCOMPARE(toMinorUnit(25, Iso4217Codes::USD), static_cast<MinorUnit>(2500));
	}

	void toMinorUnit_minimumValue_ShouldConvert()
	{
		QCOMPARE(toMinorUnit(0, Iso4217Codes::USD), static_cast<MinorUnit>(0));
	}

	void toMinorUnit_maximumValue_ShouldConvert()
	{
		QCOMPARE(toMinorUnit(99, Iso4217Codes::USD), static_cast<MinorUnit>(9900));
	}

	void toMinorUnit_toLargeValue_ShouldThrow()
	{
		QVERIFY_EXCEPTION_THROWN(toMinorUnit(100, Iso4217Codes::USD), overflow_error);
	}

	//}
};

}}

QTEST_MAIN(pecunia::tests::ConversionUT)
#include "conversion-unit-tests.moc"

