using NUnit.Framework;
using RebootKit.Engine.Foundation;

namespace Tests.Runtime.Engine {
    public class EitherTests {
        [Test]
        public void Either_Left_IsCorrect() {
            Either<int, string> either = Either<int, string>.FromLeft(1);
            Assert.IsTrue(either.IsLeft);
            Assert.IsFalse(either.IsRight);
            Assert.AreEqual(1, either.Left);
        }

        [Test]
        public void Either_Right_IsCorrect() {
            Either<int, string> either = Either<int, string>.FromRight("test");
            Assert.IsFalse(either.IsLeft);
            Assert.IsTrue(either.IsRight);
            Assert.AreEqual("test", either.Right);
        }

        [Test]
        public void Either_Match_Left_IsCorrect() {
            const int k_expectedValue = 10;

            Either<int, string> either = Either<int, string>.FromLeft(k_expectedValue);

            int matchedValue = 0;
            either.Match(v => { matchedValue = v; }, _ => { });

            Assert.AreEqual(matchedValue, k_expectedValue);
        }

        [Test]
        public void Either_Match_Right_IsCorrect() {
            const string k_expectedValue = "reboot_test";

            Either<int, string> either = Either<int, string>.FromRight(k_expectedValue);

            string matchedValue = "invalid";
            either.Match(_ => { }, v => { matchedValue = v; });

            Assert.AreEqual(matchedValue, k_expectedValue);
        }
    }
}