using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NavisworksTransport.Utils;

namespace NavisworksTransport.UnitTests.Core
{
    [TestClass]
    public class CornerTurnCheckHelperTests
    {
        [TestMethod]
        public void LongEnoughForCorner_ShouldPass()
        {
            // maxLength ≈ 6.393，长度6.0 < 6.393 可通过
            Assert.IsTrue(CornerTurnCheckHelper.CanPass(6.0, 2.0, 4.8, 2.75, out _, out double max));
            Assert.AreEqual(6.3932, max, 1e-3);
        }

        [TestMethod]
        public void ModuleLongerThanRequired_ShouldPass()
        {
            // maxLength ≈ 6.765，长度6.5 < 6.765 可通过
            Assert.IsTrue(CornerTurnCheckHelper.CanPass(6.5, 0.5, 3.0, 2.5, out _, out double max));
            Assert.AreEqual(6.7652, max, 1e-3);
        }

        [TestMethod]
        public void WidthExceedsExit_ShouldNotPass()
        {
            Assert.IsFalse(CornerTurnCheckHelper.CanPass(4.8, 2.8, 3.0, 2.75, out _, out _));
        }

        [TestMethod]
        public void ZeroOrNegative_ShouldNotPass()
        {
            Assert.IsFalse(CornerTurnCheckHelper.CanPass(0, 1, 2, 2, out _, out _));
            Assert.IsFalse(CornerTurnCheckHelper.CanPass(2, 0, 2, 2, out _, out _));
            Assert.IsFalse(CornerTurnCheckHelper.CanPass(2, 1, 0, 2, out _, out _));
            Assert.IsFalse(CornerTurnCheckHelper.CanPass(2, 1, 2, 0, out _, out _));
            Assert.IsFalse(CornerTurnCheckHelper.CanPass(-1, 1, 2, 2, out _, out _));
        }

        [TestMethod]
        public void WidthExceedsBoth_ShouldNotPass()
        {
            Assert.IsFalse(CornerTurnCheckHelper.CanPass(3.0, 4.0, 2.0, 2.5, out _, out _));
        }

        [TestMethod]
        public void VeryLarge_ShouldNotPass()
        {
            Assert.IsFalse(CornerTurnCheckHelper.CanPass(20.0, 5.0, 2.0, 2.0, out _, out _));
        }

        [TestMethod]
        public void WideAndLongEnough_ShouldPass()
        {
            // maxLength ≈ 2.657，长度2.5 < 2.657 可通过
            Assert.IsTrue(CornerTurnCheckHelper.CanPass(2.5, 1.5, 2.0, 2.0, out _, out double max));
            Assert.AreEqual(2.6569, max, 1e-3);
        }

        [TestMethod]
        public void WideAndTooLong_ShouldNotPass()
        {
            // maxLength ≈ 2.657，长度3.0 > 2.657 不可通过
            Assert.IsFalse(CornerTurnCheckHelper.CanPass(3.0, 1.5, 2.0, 2.0, out _, out double max));
            Assert.AreEqual(2.6569, max, 1e-3);
        }

        [TestMethod]
        public void NarrowLongEnough_ShouldPass()
        {
            // maxLength ≈ 3.657，长度3.5 < 3.657 可通过
            Assert.IsTrue(CornerTurnCheckHelper.CanPass(3.5, 1.0, 2.0, 2.0, out _, out double max));
            Assert.AreEqual(3.6569, max, 1e-3);
        }

        [TestMethod]
        public void NarrowTooLong_ShouldNotPass()
        {
            // maxLength ≈ 3.657，长度4.0 > 3.657 不可通过
            Assert.IsFalse(CornerTurnCheckHelper.CanPass(4.0, 1.0, 2.0, 2.0, out _, out double max));
            Assert.AreEqual(3.6569, max, 1e-3);
        }
    }
}
