public void WhenListWithRepeatedIntegerValuesThenDistinctShouldReturnListWithSameCount() { List <Foo> sourceList = new List <Foo>(); sourceList.Add(new Foo() { IntProp = 42, StringProp = "First String" }); sourceList.Add(new Foo() { IntProp = 42, StringProp = "Second String" }); sourceList.Add(new Foo() { IntProp = 42, StringProp = "Second String" }); sourceList.Add(new Foo() { IntProp = 41, StringProp = "Third String" }); sourceList.Add(new Foo() { IntProp = 40, StringProp = "Fourth String" }); var distinctEnumerable = IEnumerableUtil.DistinctBy(sourceList, f => f.IntProp); Assert.AreEqual(3, distinctEnumerable.Count()); }
public void WhenListsAreSameThenContainsShouldReturnTrue() { List <int> sourceList = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; Assert.IsTrue(IEnumerableUtil.Contains(sourceList, sourceList)); }
public void WhenOrderedCollectionsThenShuffleShouldReturnUnorderedCollection() { //Arrange var source = Enumerable.Range(0, 1000).ToList(); var shuffled = IEnumerableUtil.Shuffle(source).ToList(); Assert.AreNotSame(source, shuffled); CollectionAssert.AreNotEqual(source, shuffled); }
public void WhenOtherListIsEmptyAndOtherDontThenContainsShouldReturnFalse() { List <int> sourceList = new List <int>() { 2, 3, 4, 5, 6, 7, 8, 9, 1, 1 }; List <int> otherList = new List <int>() { }; Assert.IsFalse(IEnumerableUtil.Contains(sourceList, otherList)); }
public void WhenBothListsContainsDuplicatesThenContainsShouldReturnTrue() { List <int> sourceList = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1 }; List <int> otherList = new List <int>() { 2, 3, 4, 5, 6, 7, 8, 9, 1, 1 }; Assert.IsTrue(IEnumerableUtil.Contains(sourceList, otherList)); }
public void WhenListsContainsDifferentElementsThenContainsShouldReturnFalse() { List <int> sourceList = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; List <int> otherList = new List <int>() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Assert.IsFalse(IEnumerableUtil.Contains(sourceList, otherList)); }
public void WhenListsContainsSameElementsButInDifferentOrderThenContainsShouldReturnTrue() { List <int> sourceList = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; List <int> otherList = new List <int>() { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; Assert.IsTrue(IEnumerableUtil.Contains(sourceList, otherList)); }
internal static IEnumerable <ArgumentInfo[]> BuildPermetations(CallInfo call) { var parameters = call.Method.GetParameters().TakeWhile(p => !CallFlagAttribute.ExistsOn(p)); var required = parameters.Where(p => !p.HasDefaultValue); var optional = parameters.Where(p => p.HasDefaultValue); var requiredMask = Enumerable.Range(0, required.Count()) .Select(v => true) .ToArray(); foreach (var optionalMask in IEnumerableUtil.BooleanMask(optional.Count())) { var fullMask = requiredMask.Concat(optionalMask).ToArray(); var args = parameters.Select((p, i) => new ArgumentInfo(p, call, !fullMask[i])).ToArray(); if (args.Count(a => a.IsDense) <= 1) { yield return(args); } } }
public AnatomyLuceneSearch(AnatomyController anatomyController) { this.anatomyController = anatomyController; systems = new AnatomyGroupFacetManager("Systems", "System", group => { group.addCommand(new BreakdownSearchCallbackCommand("Show System Anatomy", true, () => displayAnatomyForFacet(group.AnatomicalName, systems.FacetName))); group.addCommand(new BreakdownSearchCallbackCommand("Breakdown by Region", true, () => breakdownGroup("{0} of the {1}", group, regions))); group.addCommand(new BreakdownSearchCallbackCommand("Breakdown by Structure", true, () => breakdownGroup("{0} of the {1}", group, structures))); group.addCommand(new BreakdownSearchCallbackCommand("Breakdown by Classification", true, () => breakdownGroup("{1} of the {0}", group, classifications))); }, anatomy => { String system = anatomy.Systems.FirstOrDefault(); return(buildGroupFromFacets(String.Format("{0} of the {1}", system, anatomy.Region), IEnumerableUtil <AnatomyFacet> .Iter(new AnatomyFacet("System", system), new AnatomyFacet("Region", anatomy.Region)))); }); regions = new AnatomyGroupFacetManager("Regions", "Region", group => { group.addCommand(new BreakdownSearchCallbackCommand("Show Region Anatomy", true, () => displayAnatomyForFacet(group.AnatomicalName, regions.FacetName))); group.addCommand(new BreakdownSearchCallbackCommand("Breakdown by System", true, () => breakdownGroup("{1} of the {0}", group, systems))); group.addCommand(new BreakdownSearchCallbackCommand("Breakdown by Classification", true, () => breakdownGroup("{1} of the {0}", group, classifications))); }, anatomy => { String system = anatomy.Systems.FirstOrDefault(); return(buildGroupFromFacets(String.Format("{0} of the {1}", system, anatomy.Region), IEnumerableUtil <AnatomyFacet> .Iter(new AnatomyFacet("System", system), new AnatomyFacet("Region", anatomy.Region)))); }); classifications = new AnatomyGroupFacetManager("Classifications", "Classification", group => { group.addCommand(new BreakdownSearchCallbackCommand("Show Individual Anatomy", true, () => displayAnatomyForFacet(group.AnatomicalName, classifications.FacetName))); group.addCommand(new BreakdownSearchCallbackCommand("Breakdown by Region", true, () => breakdownGroup("{0} of the {1}", group, regions))); group.addCommand(new BreakdownSearchCallbackCommand("Breakdown by Structure", true, () => breakdownGroup("{0} of the {1}", group, structures))); }, anatomy => { return(buildGroupFromFacets(String.Format("{0} of the {1}", anatomy.Classification, anatomy.Region), IEnumerableUtil <AnatomyFacet> .Iter(new AnatomyFacet("Classification", anatomy.Classification), new AnatomyFacet("Region", anatomy.Region)))); }); tags = new AnatomyGroupFacetManager("Tags", "Tag", group => { group.addCommand(new BreakdownSearchCallbackCommand("Show Individual Anatomy", true, () => displayAnatomyForFacet(group.AnatomicalName, tags.FacetName))); }, anatomy => { throw new NotImplementedException(); }); structures = new AnatomyGroupFacetManager("Structures", "Structure", group => { group.addCommand(new BreakdownSearchCallbackCommand("Show Individual Anatomy", true, () => displayAnatomyForFacet(group.AnatomicalName, structures.FacetName))); group.addCommand(new BreakdownSearchCallbackCommand("Breakdown by System", true, () => breakdownGroup("{1} of the {0}", group, systems))); group.addCommand(new BreakdownSearchCallbackCommand("Breakdown by Classification", true, () => breakdownGroup("{1} of the {0}", group, classifications))); }, anatomy => { String system = anatomy.Systems.FirstOrDefault(); return(buildGroupFromFacets(String.Format("{0} of the {1}", system, anatomy.Structure), IEnumerableUtil <AnatomyFacet> .Iter(new AnatomyFacet("System", system), new AnatomyFacet("Structure", anatomy.Structure)))); }); }
public void WhenCollectionIsNullThenToStringShouldThrowArgumentNullException() { Assert.ThrowsException <ArgumentNullException>(() => IEnumerableUtil.ToString <int>(null).ToList()); }
public void WhenSourceCollectionIsNullThenShuffleShouldThrowArgumentNullException() { Assert.ThrowsException <ArgumentNullException>(() => IEnumerableUtil.Shuffle <int>(null).ToList()); }
public void WhenOtherListIsNullThenContainsShouldThrowArgumentNullException() { Assert.ThrowsException <ArgumentNullException>(() => IEnumerableUtil.Contains(new List <int>() { }, null)); }
public void WhenNullListThenDistinctShouldThrowArgumentNullException() { List <Foo> sourceList = null; Assert.ThrowsException <ArgumentNullException>(() => { IEnumerableUtil.DistinctBy(sourceList, f => f.IntProp).ToList(); }); }