Example #1
0
        public void ExtractWorksCorrectly()
        {
            Union2 <int, string>[] unions = new Union2 <int, string>[]
            {
                new Union2 <int, string> .Case1(7),
                new Union2 <int, string> .Case2("7")
            };

            var strs = unions.Select(u => u.Extract(num => num.ToString(), str => str));

            Assert.Equal(new[] { "7", "7" }, strs);
        }
Example #2
0
        public void ProcessWorksCorrectly()
        {
            Union2 <int, string>[] unions = new Union2 <int, string>[]
            {
                new Union2 <int, string> .Case1(7),
                new Union2 <int, string> .Case2("7")
            };

            int sum = 0;

            foreach (var union in unions)
            {
                union.Act(i => sum   += i,
                          str => sum += int.Parse(str));
            }

            Assert.True(14 == sum);
        }
Example #3
0
 public void Union2_MatchShouldInvokeTheFunctionForTheSecondCase()
 => Assert.IsTrue(
     Union2 <int, string> .Case2("1")
     .Match(
         case1 => false,
         case2 => true));
Example #4
0
 public void Union2_TwoUnionsWithTheSameTypeAndCaseAndValueShouldBeEqual()
 => Assert.AreEqual(
     Union2 <int, string> .Case1(1),
     Union2 <int, string> .Case1(1));
Example #5
0
 public void Union2_TwoUnionsWithTheDifferentTypesShouldNotBeEqual()
 => Assert.AreNotEqual(
     Union2 <int, string> .Case1(1),
     Union2 <string, int> .Case2(1));
Example #6
0
 public void Union2_MatchShouldInvokeTheFunctionForTheFirstCase()
 => Assert.IsTrue(
     Union2 <int, string> .Case1(1)
     .Match(
         case1 => true,
         case2 => false));
Example #7
0
 public void Union2_TwoUnionsWithTheSameTypeButDifferentCaseShouldNotBeEqual()
 => Assert.AreNotEqual(
     Union2 <int, string> .Case1(1),
     Union2 <int, string> .Case2("1"));
Example #8
0
 static public bool Is <T, Eq>(HashSet <T, Eq> b, Union2 <T, Eq> a)
     where Eq : IEqualityComparer <T>, new()
 {
     return(Is(b, a.ToLiteral()));
 }
Example #9
0
 static public bool Is <T, Eq>(Union2 <T, Eq> a, HashSet <T, Eq> b)
     where Eq : IEqualityComparer <T>, new()
 {
     return(Is(a.ToLiteral(), b));
 }
Example #10
0
 static public bool Is <T>(HashSet <T> b, Union2 <T> a)
 {
     return(Is(a.toLiteral(), b));
 }
Example #11
0
 static public void AssertNo <T, Eq>(Union2 <T, Eq> a, HashSet <T, Eq> b)
     where Eq : IEqualityComparer <T>, new()
 {
     nilnul.bit.AssertX.False(Is <T, Eq>(a, b));
 }