Exemplo n.º 1
0
        public void JoinAppliedToRightOfLeft()
        {
            var actual = Either.Join(EitherString.Right(EitherString.Left <int>("error")));

            Assert.That(actual.IsLeft, Is.True);
            Assert.That(actual.Left, Is.EqualTo("error"));
        }
Exemplo n.º 2
0
        public void ReplicateM_AppliedToLeft()
        {
            var actual = Either.ReplicateM_(5, EitherString.Left <int>("error"));

            Assert.That(actual.IsLeft, Is.True);
            Assert.That(actual.Left, Is.EqualTo("error"));
        }
Exemplo n.º 3
0
        public void JoinAppliedToLeft()
        {
            var actual = Either.Join(EitherString.Left <Either <string, int> >("error"));

            Assert.That(actual.IsLeft, Is.True);
            Assert.That(actual.Left, Is.EqualTo("error"));
        }
Exemplo n.º 4
0
        public void MapEitherAppliedToLeft()
        {
            var either = EitherString.Left <int>("error");
            var actual = either.MapEither(l => l + l, null);

            Assert.That(actual, Is.EqualTo("errorerror"));
        }
Exemplo n.º 5
0
        public void MatchOfTAppliedToLeft()
        {
            var either = EitherString.Left <int>("error");
            var actual = either.Match(_ => 1.0, _ => 2.0);

            Assert.That(actual, Is.EqualTo(1.0));
        }
Exemplo n.º 6
0
        public void RightAppliedToLeftThrowsException()
        {
            var either = EitherString.Left <int>("error");

            #pragma warning disable 168
            Assert.Throws <InvalidOperationException>(() => { var dummy = either.Right; });
            #pragma warning restore 168
        }
Exemplo n.º 7
0
        public void Left()
        {
            var either = EitherString.Left <int>("error");

            Assert.That(either.IsLeft, Is.True);
            Assert.That(either.IsRight, Is.False);
            Assert.That(either.Left, Is.EqualTo("error"));
        }
Exemplo n.º 8
0
 private static IEnumerable <Either <string, int> > MixtureOfLeftsAndRights()
 {
     return(new[]
     {
         EitherString.Right(1),
         EitherString.Right(2),
         EitherString.Left <int>("Error 1"),
         EitherString.Right(4),
         EitherString.Left <int>("Error 2"),
         EitherString.Right(6)
     });
 }
Exemplo n.º 9
0
        public void MatchAppliedToLeft()
        {
            var either            = EitherString.Left <int>("error");
            var leftActionCalled  = false;
            var leftActionParam   = default(string);
            var rightActionCalled = false;

            either.Match(
                e =>
            {
                leftActionCalled = true;
                leftActionParam  = e;
            },
                _ =>
            {
                rightActionCalled = true;
            });
            Assert.That(leftActionCalled, Is.True);
            Assert.That(leftActionParam, Is.EqualTo("error"));
            Assert.That(rightActionCalled, Is.False);
        }
Exemplo n.º 10
0
 public Either <string, int> ToEither()
 {
     return(_error != null?EitherString.Left <int>(_error) : EitherString.Right(_number));
 }
Exemplo n.º 11
0
        public void MapM_WithFuncReturningMixtureOfLeftsAndRights()
        {
            var ints   = new[] { 1, 2, 3, 4, 5 };
            var actual = Either.MapM_(n => n < 4 ? EitherString.Right(Convert.ToString(n)) : EitherString.Left <string>("error"), ints);

            Assert.That(actual.IsLeft, Is.True);
            Assert.That(actual.Left, Is.EqualTo("error"));
        }
Exemplo n.º 12
0
 private static TestCaseData MakeEqualsTestCaseData(string e1, string e2, bool flag)
 {
     return(new TestCaseData(EitherString.Left <int>(e1), EitherString.Left <int>(e2), flag));
 }
Exemplo n.º 13
0
 private static TestCaseData MakeEqualsTestCaseData(string e, int n, bool flag)
 {
     return(new TestCaseData(EitherString.Left <int>(e), EitherString.Right(n), flag));
 }