public void RemoveRangeFromListSafety() { var nice = new List <string> { "1", "2", "3" }; Colls.RemoveRangeSafety(nice, 4, 4); nice.ShouldNotBeNull(); nice.ShouldNotBeEmpty(); nice.Count.ShouldBe(3); Colls.RemoveRangeSafety(nice, 0, 0); nice.ShouldNotBeNull(); nice.ShouldNotBeEmpty(); nice.Count.ShouldBe(3); Colls.RemoveRangeSafety(nice, 4, 0); nice.ShouldNotBeNull(); nice.ShouldNotBeEmpty(); nice.Count.ShouldBe(3); Colls.RemoveRangeSafety(nice, 0, 4); nice.ShouldNotBeNull(); nice.ShouldBeEmpty(); }
public void EmptyArrayTest() { var array = Colls.Empty <string>(); array.ShouldNotBeNull(); array.ShouldBeEmpty(); }
public void CollOfListAndReturnsListWithGivenListSequenceTest() { var list0 = new List <int> { 1, 2 }; var list1 = new List <int> { 3, 4 }; var list2 = new List <int> { 5 }; var listSrc = new List <List <int> > { list0, list1, list2 }.ToArray(); var list = Colls.OfList <int>(listSrc); list.ShouldNotBeNull(); list.ShouldNotBeEmpty(); list.Count.ShouldBe(5); list[0].ShouldBe(1); list[1].ShouldBe(2); list[2].ShouldBe(3); list[3].ShouldBe(4); list[4].ShouldBe(5); }
public void CollOfPageForQueryAndReturnsListWithinPageTest() { var query = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }.AsQueryable(); var page = Colls.OfPage(query, 2, 3); page.PageSize.ShouldBe(3); page.CurrentPageNumber.ShouldBe(2); page.CurrentPageSize.ShouldBe(3); page.HasNext.ShouldBeTrue(); page.HasPrevious.ShouldBeTrue(); page.TotalMemberCount.ShouldBe(9); page[0].Value.ShouldBe(4); page[1].Value.ShouldBe(5); page[2].Value.ShouldBe(6); var list1 = page.ToOriginalItems().ToList(); var list2 = page.ToList(); list1.Count.ShouldBe(3); list1[0].ShouldBe(4); list1[1].ShouldBe(5); list1[2].ShouldBe(6); list2.Count.ShouldBe(3); list2[0].Value.ShouldBe(4); list2[1].Value.ShouldBe(5); list2[2].Value.ShouldBe(6); }
public void MergeTwoListWithLimitedThatGreaterThanLengthTest() { var left = new List <int> { 0, 1, 2, 3, 4, 5 }; var right = new List <int> { 6, 7, 8, 9 }; var target = Colls.Merge(left, right, 20).ToList(); left.Count.ShouldBe(6); right.Count.ShouldBe(4); target.Count.ShouldBe(10); target[0].ShouldBe(0); target[1].ShouldBe(1); target[2].ShouldBe(2); target[3].ShouldBe(3); target[4].ShouldBe(4); target[5].ShouldBe(5); target[6].ShouldBe(6); target[7].ShouldBe(7); target[8].ShouldBe(8); target[9].ShouldBe(9); }
public void MergeTwoEnumeratorsTest() { var left = new List <int> { 0, 1, 2, 3, 4, 5 }; var right = new List <int> { 6, 7, 8, 9 }; using var leftEnumerator = left.GetEnumerator(); using var rightEnumerator = right.GetEnumerator(); var target = Colls.Merge(leftEnumerator, rightEnumerator).ToList(); left.Count.ShouldBe(6); right.Count.ShouldBe(4); target.Count.ShouldBe(10); target[0].ShouldBe(0); target[1].ShouldBe(1); target[2].ShouldBe(2); target[3].ShouldBe(3); target[4].ShouldBe(4); target[5].ShouldBe(5); target[6].ShouldBe(6); target[7].ShouldBe(7); target[8].ShouldBe(8); target[9].ShouldBe(9); }
public void AddOneListIntoAnotherTest() { var list = new List <int> { 1, 2, 3, 4, 5 }; var other = new List <int> { 6, 7, 8, 9, 10 }; var target = Colls.AddRange(list, other).ToList(); list.Count.ShouldBe(5); target.Count.ShouldBe(10); other.Count.ShouldBe(5); target[0].ShouldBe(1); target[1].ShouldBe(2); target[2].ShouldBe(3); target[3].ShouldBe(4); target[4].ShouldBe(5); target[5].ShouldBe(6); target[6].ShouldBe(7); target[7].ShouldBe(8); target[8].ShouldBe(9); target[9].ShouldBe(10); }
public void CollOfListAndReturnsAnEmptyListTest() { var list = Colls.OfList <int>(); list.ShouldNotBeNull(); list.ShouldBeEmpty(); }
public void SearchOneItemInListWithMapTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7 }; var val = Colls.BinarySearch(list, v => v + 1, 3); // 2 + 1 = 3, so matched 2 val.ShouldBe(1); }
public void SearchOneItemInReadOnlyListWithComparerTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7 }.AsReadOnly(); var val = Colls.BinarySearch(list, 3, Comparer <int> .Default); val.ShouldBe(2); }
public void CollOrderByRandomTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; var target = Colls.OrderByRandom(list); target.Count().ShouldBe(10); Signature(list).ShouldNotBe(Signature(target)); }
public void CollOrderByShuffleAndReturnsNewInstanceInTenTimesTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; var target = Colls.OrderByShuffleAndNewInstance(list, 10); target.Count.ShouldBe(10); Signature(list).ShouldNotBe(Signature(target)); }
public void GettingIndexOfCollWithDefaultComparerTest() { var list = new List <int> { 1, 2, 3, 4, 5 }; var index = Colls.IndexOf(list, 3, EqualityComparer <int> .Default); index.ShouldBe(2); }
public void GettingIndexOfCollTest() { var list = new List <int> { 1, 2, 3, 4, 5 }; var index = Colls.IndexOf(list, 3); index.ShouldBe(2); }
public void SearchOneItemInReadOnlyListTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7 }.AsReadOnly(); var val = Colls.BinarySearch(list, 3); val.ShouldBe(2); }
public void SearchOneItemInListWithMapAndComparerTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7 }; var val = Colls.BinarySearch(list, v => v + 1, 3, Comparer <int> .Default); val.ShouldBe(1); }
public void RemoveWithConditionTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; var target = Colls.RemoveIf(list, c => c > 1); list.Count.ShouldBe(2); target.Count().ShouldBe(2); }
public void GettingIndexOfCollWithCustomComparerTest() { var list = new List <int> { 1, 2, 3, 4, 5 }; var comparer = new Int32Comparer(); var index = Colls.IndexOf(list, 3, comparer); //y=3 index.ShouldBe(1); //x=2, so x+1 = y }
public void BeContainWithoutComparerTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var val0 = Colls.BeContainedIn(10, list); var val1 = Colls.BeContainedIn(11, list); val0.ShouldBeTrue(); val1.ShouldBeFalse(); }
public void RemoveDuplicatesIgnoreCaseFromStringListTest() { var list = new List <string> { "A", "a", "a", "b", "c", "C" }; list.Count.ShouldBe(6); var target = Colls.RemoveDuplicatesIgnoreCase(list); list.Count.ShouldBe(3); target.Count().ShouldBe(3); }
public void RemoveDuplicatesFromStringListTest() { var list = new List <string> { "A", "a", "a", "b", "c", "C" }; list.Count.ShouldBe(6); var target = Colls.RemoveDuplicates(list); list.Count.ShouldBe(5); // A a b c C target.Count().ShouldBe(5); // A a b c C }
public void UniqueCountWithDefaultValueCalculatorTest() { var list = new List <int> { 1, 2, 3, 1, 2, 3, 1, 2, 3 }; var val = list.Count; var val2 = Colls.UniqueCount(list); val.ShouldBe(9); val2.ShouldBe(3); }
public void UniqueCountWithCustomValueCalculatorTest() { var list = new List <int> { 1, 2, 3, 1, 2, 3, 1, 2, 3 }; var val = list.Count; var val2 = Colls.UniqueCount(list, v => v * 0); val.ShouldBe(9); val2.ShouldBe(1); }
public void RemoveDuplicatesFromInt32ListWithCheckTest() { var list = new List <int> { 1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 8, 9, 9, 9, 0, 0 }; list.Count.ShouldBe(16); var target = Colls.RemoveDuplicates(list, v => v * 0); list.Count.ShouldBe(1); target.Count().ShouldBe(1); }
public void CollOrderByShuffleInTenTimesTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; Colls.OrderByShuffle(list, 10); Signature(new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }).ShouldNotBe(Signature(list)); }
public void CollOfListAndReturnsListWithGivenParamsTest() { var list = Colls.OfList(1, 2, 3, 4, 5); list.ShouldNotBeNull(); list.ShouldNotBeEmpty(); list.Count.ShouldBe(5); list[0].ShouldBe(1); list[1].ShouldBe(2); list[2].ShouldBe(3); list[3].ShouldBe(4); list[4].ShouldBe(5); }
public void BeContainWithComparerTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var comparer = EqualityComparer <int> .Default; var val0 = Colls.BeContainedIn(10, list, comparer); var val1 = Colls.BeContainedIn(11, list, comparer); val0.ShouldBeTrue(); val1.ShouldBeFalse(); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { var hash = 41; // Suitable nullity checks etc, of course :) if (Id != null) { hash = hash * 57 + Id.GetHashCode(); } if (Rid != null) { hash = hash * 57 + Rid.GetHashCode(); } if (Databases != null) { hash = hash * 57 + Databases.GetHashCode(); } if (Ts != null) { hash = hash * 57 + Ts.GetHashCode(); } if (Self != null) { hash = hash * 57 + Self.GetHashCode(); } if (Etag != null) { hash = hash * 57 + Etag.GetHashCode(); } if (Colls != null) { hash = hash * 57 + Colls.GetHashCode(); } if (Users != null) { hash = hash * 57 + Users.GetHashCode(); } return(hash); } }
public void ContainsAtLeastAsQueryExpressionTest() { var query = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }.AsQueryable(); var val0 = Colls.ContainsAtLeast(query, 9); var val1 = Colls.ContainsAtLeast(query, 10); var val2 = Colls.ContainsAtLeast(query, 11); val0.ShouldBeTrue(); val1.ShouldBeTrue(); val2.ShouldBeFalse(); }
/// <summary> /// Returns true if DatabaseCollection instances are equal /// </summary> /// <param name="other">Instance of DatabaseCollection to be compared</param> /// <returns>Boolean</returns> public bool Equals(DatabaseCollection other) { // credit: http://stackoverflow.com/a/10454552/677735 if (other == null) { return(false); } return (( Id == other.Id || Id != null && Id.Equals(other.Id) ) && ( Rid == other.Rid || Rid != null && Rid.Equals(other.Rid) ) && ( Databases == other.Databases || Databases != null && Databases.SequenceEqual(other.Databases) ) && ( Ts == other.Ts || Ts != null && Ts.Equals(other.Ts) ) && ( Self == other.Self || Self != null && Self.Equals(other.Self) ) && ( Etag == other.Etag || Etag != null && Etag.Equals(other.Etag) ) && ( Colls == other.Colls || Colls != null && Colls.Equals(other.Colls) ) && ( Users == other.Users || Users != null && Users.Equals(other.Users) )); }