/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <catch2/catch_all.hpp>

#include "Base/UnitFormatter.hpp"

using namespace units::literals;

TEST_CASE("testUnitFormatterWithTrailingZeros", "[UnitFormatter]")
{
	OpenVulkano::UnitFormatter metricFormatter(true, 2, false);
	OpenVulkano::UnitFormatter imperialFormatter(false, 2, false);

	units::length::meter_t positiveDistance = 1500.0_m;
	units::length::meter_t smallDistance = 0.5_m;
	units::length::meter_t negativeDistance = -100.0_m;
	units::length::meter_t smallDistanceMetric = 0.05_m;
	units::length::meter_t smallDistanceImperial = 0.03_m;
	units::area::square_meter_t smallArea(0.005);
	units::area::square_meter_t negativeArea(-50.0);

	REQUIRE(metricFormatter.Format(positiveDistance) == "1.50 km");
	REQUIRE(metricFormatter.Format(smallDistance) == "0.50 m");
	REQUIRE(metricFormatter.Format(negativeDistance) == "-100.00 m");
	REQUIRE(metricFormatter.Format(smallArea) == "0.01 m²");
	REQUIRE(metricFormatter.Format(negativeArea) == "-50.00 m²");
	REQUIRE(imperialFormatter.Format(smallDistance) == "1.64 ft");
	REQUIRE(imperialFormatter.Format(negativeDistance) == "-328.08 ft");
	REQUIRE(imperialFormatter.Format(smallArea) == "0.05 ft²");
	REQUIRE(imperialFormatter.Format(negativeArea) == "-538.20 ft²");
	REQUIRE(metricFormatter.Format(smallDistanceMetric) == "50.00 mm");
	REQUIRE(imperialFormatter.Format(smallDistanceImperial) == "1.18 in");
}

TEST_CASE("testUnitFormatterWithoutTrailingZeros", "[UnitFormatter]")
{
	OpenVulkano::UnitFormatter metricFormatter(true, 2);
	OpenVulkano::UnitFormatter imperialFormatter(false, 2);

	units::length::meter_t positiveDistance = 1500.0_m;
	units::length::meter_t smallDistance = 0.5_m;
	units::length::meter_t negativeDistance = -100.0_m;
	units::length::meter_t smallDistanceMetric = 0.05_m;
	units::length::meter_t smallDistanceImperial = 0.03_m;
	units::length::meter_t mediumDistanceMetric = 0.5_m;
	units::length::meter_t largeDistanceMetric = 100.0_m;
	units::area::square_meter_t smallArea(0.005);
	units::area::square_meter_t negativeArea(-50.0);

	REQUIRE(metricFormatter.Format(positiveDistance) == "1.5 km");
	REQUIRE(metricFormatter.Format(smallDistance) == "0.5 m");
	REQUIRE(metricFormatter.Format(negativeDistance) == "-100 m");
	REQUIRE(metricFormatter.Format(smallArea) == "0.01 m²");
	REQUIRE(metricFormatter.Format(negativeArea) == "-50 m²");
	REQUIRE(imperialFormatter.Format(smallDistance) == "1.64 ft");
	REQUIRE(imperialFormatter.Format(negativeDistance) == "-328.08 ft");
	REQUIRE(imperialFormatter.Format(smallArea) == "0.05 ft²");
	REQUIRE(imperialFormatter.Format(negativeArea) == "-538.2 ft²");
	REQUIRE(metricFormatter.Format(smallDistanceMetric) == "50 mm");
	REQUIRE(imperialFormatter.Format(smallDistanceImperial) == "1.18 in");
	REQUIRE(metricFormatter.Format(smallDistanceMetric) == "50 mm");
	REQUIRE(metricFormatter.Format(mediumDistanceMetric) == "0.5 m");
	REQUIRE(metricFormatter.Format(largeDistanceMetric) == "100 m");
}