// ---------------------------------------------------------------------------
// BT.Framework.Tests
// FormatExTests.cs — FormatEx 포맷 유틸 단위 테스트
// ---------------------------------------------------------------------------
using NUnit.Framework;
using BurningTimes.Core.Util;

namespace BurningTimes.Tests.Core.Util
{
    public class FormatExTests
    {
        [Test]
        public void AbbreviateNumber_BelowThousand_ReturnsPlain()
        {
            Assert.That(FormatEx.AbbreviateNumber(0), Is.EqualTo("0"));
            Assert.That(FormatEx.AbbreviateNumber(42), Is.EqualTo("42"));
            Assert.That(FormatEx.AbbreviateNumber(999), Is.EqualTo("999"));
        }

        [Test]
        public void AbbreviateNumber_UsesKMBTiers()
        {
            Assert.That(FormatEx.AbbreviateNumber(12_345), Is.EqualTo("12.3K"));
            Assert.That(FormatEx.AbbreviateNumber(1_500_000), Is.EqualTo("1.5M"));
            Assert.That(FormatEx.AbbreviateNumber(2_000_000_000), Is.EqualTo("2.0B"));
        }

        [Test]
        public void AbbreviateNumber_NegativeKeepsSign()
        {
            Assert.That(FormatEx.AbbreviateNumber(-1_500), Is.EqualTo("-1.5K"));
        }

        [Test]
        public void AbbreviateNumber_ZeroDecimalsStripsFraction()
        {
            Assert.That(FormatEx.AbbreviateNumber(1_500, decimals: 0), Is.EqualTo("2K"));
        }

        [Test]
        public void FormatTimeSpan_UnderHour_MinSecOnly()
        {
            Assert.That(FormatEx.FormatTimeSpan(65f), Is.EqualTo("01:05"));
            Assert.That(FormatEx.FormatTimeSpan(0f), Is.EqualTo("00:00"));
        }

        [Test]
        public void FormatTimeSpan_OverHour_IncludesHour()
        {
            Assert.That(FormatEx.FormatTimeSpan(3670f), Is.EqualTo("01:01:10"));
        }

        [Test]
        public void FormatTimeSpan_NegativeClampsToZero()
        {
            Assert.That(FormatEx.FormatTimeSpan(-5f), Is.EqualTo("00:00"));
        }

        [Test]
        public void FormatPercent_TwoDecimalsByDefault()
        {
            Assert.That(FormatEx.FormatPercent(0.1234f), Is.EqualTo("12.34%"));
        }

        [Test]
        public void WithThousands_InsertsCommas()
        {
            Assert.That(FormatEx.WithThousands(1_234_567), Is.EqualTo("1,234,567"));
        }

        [Test]
        public void FormatBytes_ScalesTo1024()
        {
            Assert.That(FormatEx.FormatBytes(512), Is.EqualTo("512B"));
            Assert.That(FormatEx.FormatBytes(2048), Is.EqualTo("2.00KB"));
            Assert.That(FormatEx.FormatBytes(1_048_576), Is.EqualTo("1.00MB"));
        }
    }
}
