Beispiel #1
0
        public static void BindLeft_left_either_to_method_returns_either_with_new_type_and_value()
        {
            const int bindValue = 42;

            TestMonads.Left("Test").BindLeft(_ => bindValue.Left <int, string>())
            .Match(i => Assert.AreEqual(bindValue, i), Assert.Fail);
        }
Beispiel #2
0
        public static void BindLeft_right_either_to_method_returns_same_right_either()
        {
            const string value = "Test";

            TestMonads.Right(value).BindLeft(_ => 42.Left < int, string > ())
            .Match(_ => Assert.Fail(), s => Assert.AreEqual(value, s));
        }
Beispiel #3
0
        public static void Bind_left_either_to_method_returns_same_left_either()
        {
            const string value = "Test";

            TestMonads.Left(value).Bind(_ => 42.Right < string, int > ())
            .Match(s => Assert.AreEqual(value, s), _ => Assert.Fail());
        }
Beispiel #4
0
        public static void Match_right_either_returns_right_value()
        {
            const string value  = "Test";
            var          result = TestMonads.Right(value).Match(_ => "Left", s => s);

            Assert.AreEqual(value, result);
        }
        public static void Or_on_nothing_returns_initial_value()
        {
            const string alternativeValue = "alternative";

            TestMonads.Nothing <string>().Or(() => alternativeValue.Just())
            .Match(j => j.Should().Be(alternativeValue), Assert.Fail);
        }
Beispiel #6
0
        public static void Map_right_either_returns_either_with_new_type_and_value()
        {
            const int mappedValue = 42;

            TestMonads.Right("Test").Map(_ => mappedValue)
            .Match(Assert.Fail, i => Assert.AreEqual(mappedValue, i));
        }
Beispiel #7
0
        public static void Match_left_either_returns_left_value()
        {
            const string value  = "Test";
            var          result = TestMonads.Left(value).Match(s => s, _ => "Right");

            Assert.AreEqual(value, result);
        }
Beispiel #8
0
        public static void MapLeft_left_either_returns_either_with_new_type_and_value()
        {
            const int mappedValue = 42;

            TestMonads.Left("Test").MapLeft(_ => mappedValue)
            .Match(i => Assert.AreEqual(mappedValue, i), Assert.Fail);
        }
Beispiel #9
0
        public static void Bind_right_either_to_method_returns_either_with_new_type_and_value()
        {
            const int bindValue = 42;

            TestMonads.Right("Test").Bind(_ => bindValue.Right <string, int>())
            .Match(Assert.Fail, i => Assert.AreEqual(bindValue, i));
        }
 public static void Nothing_to_nullable_returns_null() =>
 TestMonads.Nothing <int>().ToNullable().Should().Be(null);
Beispiel #11
0
        public static void MapLeft_right_either_returns_same_right_either()
        {
            const string value = "Test";

            TestMonads.Right(value).MapLeft(_ => 42).Match(_ => Assert.Fail(), s => Assert.AreEqual(value, s));
        }
Beispiel #12
0
        public static void Right_creates_either_with_right_value()
        {
            const string input = "Test";

            TestMonads.Right(input).Match(Assert.Fail, s => Assert.AreEqual(input, s));
        }
Beispiel #13
0
 public static void MapLeft_left_either_with_null_mapping_throws_exception() =>
 Assert.Throws <ArgumentNullException>(() =>
                                       TestMonads.Left("Test").MapLeft((Func <string, string>)null));
Beispiel #14
0
        public static void Map_left_either_returns_same_left_either()
        {
            const string value = "Test";

            TestMonads.Left(value).Map(_ => 42).Match(s => Assert.AreEqual(value, s), _ => Assert.Fail());
        }
 public static void Or_on_nothing_and_nothing_alternative_returns_nothing() =>
 TestMonads.Nothing <string>().Or(() => Nothing)
 .Match(Assert.Fail, Assert.Pass);
Beispiel #16
0
 public static void Match_with_null_right_func_throws_exception() =>
 Assert.Throws <ArgumentNullException>(() => TestMonads.Left("Test").Match(_ => "Left", null));
Beispiel #17
0
 public static void Match_with_null_left_action_throws_exception() =>
 Assert.Throws <ArgumentNullException>(() => TestMonads.Left("Test").Match(null, _ => { }));
Beispiel #18
0
        public static void Left_creates_either_with_left_value()
        {
            const string input = "Test";

            TestMonads.Left(input).Match(s => Assert.AreEqual(input, s), Assert.Fail);
        }
Beispiel #19
0
        public static void Right_to_maybe_returns_maybe_with_value()
        {
            const string value = "Test";

            TestMonads.Right(value).ToMaybe().Match(s => Assert.AreEqual(value, s), Assert.Fail);
        }
Beispiel #20
0
 public static void Left_to_maybe_returns_empty_maybe() =>
 TestMonads.Left("Test").ToMaybe().Match(Assert.Fail, Assert.Pass);
 public static void Enumerable_created_from_nothing_is_empty() =>
 TestMonads.Nothing <int>().ToEnumerable().Should().BeEmpty();
Beispiel #22
0
 public static void Bind_right_either_with_null_mapping_throws_exception() =>
 Assert.Throws <ArgumentNullException>(() =>
                                       TestMonads.Right("Test").Bind((Func <string, Either <string, string> >)null));