public void Getting_Errors_From_Maybe_Enumerable() { var maybes = new List <IMaybe <int> > { AssertionUtilities.DivisionMaybe(4, 2), AssertionUtilities.DivisionMaybe(3, 0), AssertionUtilities.DivisionMaybe(3, 3), AssertionUtilities.DivisionMaybe(4, 0), AssertionUtilities.DivisionMaybe(5, 0), AssertionUtilities.DivisionMaybe(6, 0), AssertionUtilities.DivisionMaybe(7, 0), AssertionUtilities.DivisionMaybe(8, 0), AssertionUtilities.DivisionMaybe(10, 2) }; var list = maybes.Nones(() => "Failed divisions.").ToArray(); Assert.Equal(6, list.Length); }
public void Passing_Null_As_Value_Selector_Throws() { var maybes = new List <IMaybe <int> > { AssertionUtilities.DivisionMaybe(4, 2), AssertionUtilities.DivisionMaybe(3, 0), AssertionUtilities.DivisionMaybe(3, 3), AssertionUtilities.DivisionMaybe(4, 0), AssertionUtilities.DivisionMaybe(5, 0), AssertionUtilities.DivisionMaybe(6, 0), AssertionUtilities.DivisionMaybe(7, 0), AssertionUtilities.DivisionMaybe(8, 0), AssertionUtilities.DivisionMaybe(10, 2) }; Assert.Throws <ArgumentNullException>( AssertionUtilities.MaybeValueSelector, () => maybes.Match(null, () => - 1) ); }
public void Works_Like_Extension_Methods_Values_And_Nones() { var maybes = new List <IMaybe <int> > { AssertionUtilities.DivisionMaybe(4, 2), AssertionUtilities.DivisionMaybe(3, 0), AssertionUtilities.DivisionMaybe(3, 3), AssertionUtilities.DivisionMaybe(4, 0), AssertionUtilities.DivisionMaybe(5, 0), AssertionUtilities.DivisionMaybe(6, 0), AssertionUtilities.DivisionMaybe(7, 0), AssertionUtilities.DivisionMaybe(8, 0), AssertionUtilities.DivisionMaybe(10, 2) }; var matches = maybes .Match(i => i, () => - 1) .ToArray(); Assert.Equal(maybes.Values(), matches.Where(x => x != -1)); Assert.Equal(maybes.Nones(() => - 1), matches.Where(x => x == -1)); }