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); }
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); }
public void Union2_MatchShouldInvokeTheFunctionForTheSecondCase() => Assert.IsTrue( Union2 <int, string> .Case2("1") .Match( case1 => false, case2 => true));
public void Union2_TwoUnionsWithTheSameTypeAndCaseAndValueShouldBeEqual() => Assert.AreEqual( Union2 <int, string> .Case1(1), Union2 <int, string> .Case1(1));
public void Union2_TwoUnionsWithTheDifferentTypesShouldNotBeEqual() => Assert.AreNotEqual( Union2 <int, string> .Case1(1), Union2 <string, int> .Case2(1));
public void Union2_MatchShouldInvokeTheFunctionForTheFirstCase() => Assert.IsTrue( Union2 <int, string> .Case1(1) .Match( case1 => true, case2 => false));
public void Union2_TwoUnionsWithTheSameTypeButDifferentCaseShouldNotBeEqual() => Assert.AreNotEqual( Union2 <int, string> .Case1(1), Union2 <int, string> .Case2("1"));
static public bool Is <T, Eq>(HashSet <T, Eq> b, Union2 <T, Eq> a) where Eq : IEqualityComparer <T>, new() { return(Is(b, a.ToLiteral())); }
static public bool Is <T, Eq>(Union2 <T, Eq> a, HashSet <T, Eq> b) where Eq : IEqualityComparer <T>, new() { return(Is(a.ToLiteral(), b)); }
static public bool Is <T>(HashSet <T> b, Union2 <T> a) { return(Is(a.toLiteral(), b)); }
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)); }