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")); }
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")); }
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")); }
public void MapEitherAppliedToLeft() { var either = EitherString.Left <int>("error"); var actual = either.MapEither(l => l + l, null); Assert.That(actual, Is.EqualTo("errorerror")); }
public void MatchOfTAppliedToLeft() { var either = EitherString.Left <int>("error"); var actual = either.Match(_ => 1.0, _ => 2.0); Assert.That(actual, Is.EqualTo(1.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 }
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")); }
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) }); }
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); }
public Either <string, int> ToEither() { return(_error != null?EitherString.Left <int>(_error) : EitherString.Right(_number)); }
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")); }
private static TestCaseData MakeEqualsTestCaseData(string e1, string e2, bool flag) { return(new TestCaseData(EitherString.Left <int>(e1), EitherString.Left <int>(e2), flag)); }
private static TestCaseData MakeEqualsTestCaseData(string e, int n, bool flag) { return(new TestCaseData(EitherString.Left <int>(e), EitherString.Right(n), flag)); }