示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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());
        }
示例#5
0
 public static void MapLeft_left_either_with_null_mapping_throws_exception() =>
 Assert.Throws <ArgumentNullException>(() =>
                                       TestMonads.Left("Test").MapLeft((Func <string, string>)null));
示例#6
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());
        }
示例#7
0
 public static void Match_with_null_right_func_throws_exception() =>
 Assert.Throws <ArgumentNullException>(() => TestMonads.Left("Test").Match(_ => "Left", null));
示例#8
0
 public static void Match_with_null_left_action_throws_exception() =>
 Assert.Throws <ArgumentNullException>(() => TestMonads.Left("Test").Match(null, _ => { }));
示例#9
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);
        }
示例#10
0
 public static void Left_to_maybe_returns_empty_maybe() =>
 TestMonads.Left("Test").ToMaybe().Match(Assert.Fail, Assert.Pass);