/*******************************************************************************
***  This file is part of Dux Rei Nummariae.                                 ***
***                                                                          ***
***  Copyright (C) 2017, 2018, 2019, 2020, 2021                              ***
***  John Schneiderman <Licensing _AT_ Schneiderman _DOT_ me>                ***
***                                                                          ***
***  This program is free software: you can redistribute it and/or modify it ***
***  under the terms of the GNU Affero 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 Affero General Public License for more details.             ***
***                                                                          ***
***  You should have received a copy of the GNU Affero General Public License***
***  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
*******************************************************************************/
#include <QObject>
using ::QObject;
// using Q_OBJECT
#include <QTest>
// using QTEST_MAIN
// using QVERIFY_EXCEPTION_THROWN
#include <qt-mocks/Matchers.h>
using qt_mocks::equals;
using qt_mocks::isFalse;
using qt_mocks::isTrue;
using qt_mocks::memberFunction;
// using QVERIFY_THAT

#include <accounting/Transaction.h>
using drn::accounting::TransactionNumber;
#include <foundation/Error.h>
using drn::foundation::Error;


namespace drn
{
namespace accounting
{
namespace tests
{

struct TransactionNumberUT : QObject
{
	Q_OBJECT

private slots:
	//{ constructor Tests

	void constructor_default_ShouldBeDefaults()
	{
		TransactionNumber tn{};
		QVERIFY_THAT(
			tn,
			memberFunction(&TransactionNumber::integer, equals(TransactionNumber::invalid_))
		);
	}

	void constructor_fullInit_ShouldBeValues()
	{
		const quint32 number{156951u};
		TransactionNumber tn{number};
		QVERIFY_THAT(tn, memberFunction(&TransactionNumber::integer, equals(number)));
	}

	void constructor_invalidNumber_ShouldThrow()
	{
		QVERIFY_EXCEPTION_THROWN(TransactionNumber{TransactionNumber::invalid_}, Error);
	}

	//}

	//{ Equality Operator Tests

	void equalityOperator_SameValue_ShouldBeTrue()
	{
		const TransactionNumber tn0{15u};
		const TransactionNumber tn1{15u};
		QVERIFY_THAT(tn0 == tn1, isTrue());
	}
	void equalityOperator_DifferentValue_ShouldBeFalse()
	{
		const TransactionNumber tn0{15u};
		const TransactionNumber tn1{5u};
		QVERIFY_THAT(tn0 == tn1, isFalse());
	}
	void equalityOperator_SameValueInteger_ShouldBeTrue()
	{
		const TransactionNumber tn0{15u};
		const quint32 tn1{15u};
		QVERIFY_THAT(tn0 == tn1, isTrue());
	}
	void equalityOperator_DifferentValueInteger_ShouldBeFalse()
	{
		const TransactionNumber tn0{15u};
		const quint32 tn1{5u};
		QVERIFY_THAT(tn0 == tn1, isFalse());
	}

	//}

	//{ Inequality Operator Tests

	void inequalityOperator_SameValue_ShouldBeFalse()
	{
		const TransactionNumber tn0{15u};
		const TransactionNumber tn1{15u};
		QVERIFY_THAT(tn0 != tn1, isFalse());
	}
	void inequalityOperator_DifferentValue_ShouldBeTrue()
	{
		const TransactionNumber tn0{15u};
		const TransactionNumber tn1{5u};
		QVERIFY_THAT(tn0 != tn1, isTrue());
	}
	void inequalityOperator_SameValueInteger_ShouldBeFalse()
	{
		const TransactionNumber tn0{15u};
		const quint32 tn1{15u};
		QVERIFY_THAT(tn0 != tn1, isFalse());
	}
	void inequalityOperator_DifferentValueInteger_ShouldBeTrue()
	{
		const TransactionNumber tn0{15u};
		const quint32 tn1{5u};
		QVERIFY_THAT(tn0 != tn1, isTrue());
	}

	//}

	//{ Increment Operator Tests

	void preIncrementOperator_Incremented_ShouldBeOneMore()
	{
		TransactionNumber tn{5u};
		const TransactionNumber increment{++tn};
		const TransactionNumber expectedTn{6u};
		const TransactionNumber expectedIncrement{6u};
		QVERIFY_THAT(tn, equals(expectedTn));
		QVERIFY_THAT(increment, equals(expectedIncrement));
	}
	void postIncrementOperator_Incremented_ShouldBeOneMore()
	{
		TransactionNumber tn{5u};
		const TransactionNumber increment{tn++};
		const TransactionNumber expectedTn{6u};
		const TransactionNumber expectedIncrement{5u};
		QVERIFY_THAT(tn, equals(expectedTn));
		QVERIFY_THAT(increment, equals(expectedIncrement));
	}

	//}
};


}}}

QTEST_MAIN(drn::accounting::tests::TransactionNumberUT)
#include "TransactionNumber-unit-tests.moc"
