public void Throw_ArgumentException_After_CopyTo_When_Not_Enough_Space_In_Destination_Array() { hashSet = new MyHashSet <Box>(boxes); var array = new Box[hashSet.Count - 1]; hashSet.Invoking(x => x.CopyTo(array, 0)).Should().Throw <ArgumentException>(); }
private static Tuple <int, int> NeedNewPair(MyHashSet alredyGeneratedEdges, Tuple <int, int> value, int vertexes) { var from = value.Item1; var to = value.Item2; for (var i = from; i < vertexes; i++) { for (var j = to; j < vertexes; j++) { var tuple = Tuple.Create(i, j); if (!alredyGeneratedEdges.Contains(tuple)) { return(tuple); } } } for (var i = from; i >= 0; i--) { for (var j = to; j >= 0; j--) { var tuple = Tuple.Create(i, j); if (!alredyGeneratedEdges.Contains(tuple)) { return(tuple); } } } throw new Exception("Check edges count"); }
public void Should_ReturnTrue_After_Executing_IsSupersetOf_ReferenceEqual_Collection() { hashSet = new MyHashSet <Box>(boxes, new BoxSameDimensionsComparer()); var secondHashSet = hashSet; hashSet.IsSupersetOf(secondHashSet).Should().BeTrue(); }
public void Throw_ArgumentOutOfRangeException_After_CopyTo_With_Negative_ArrayIndex() { hashSet = new MyHashSet <Box>(); var array = new Box[2]; hashSet.Invoking(x => x.CopyTo(array, -1)).Should().Throw <ArgumentOutOfRangeException>(); }
public void TestGetEnumerator() { MyHashSet <int> set = new MyHashSet <int>(); int itemsCount = 5; for (int i = 0; i < itemsCount; i++) { set.Add(i); } List <int> items = new List <int>(); foreach (var item in set) { items.Add(item); } items.Sort(); string expected = "01234"; StringBuilder actual = new StringBuilder(); foreach (var item in items) { actual.Append(item); } Assert.AreEqual(expected, actual.ToString()); }
public void Should_ReturnTrue_After_SetEquals_With_ReferenceEqual_Collection() { hashSet = new MyHashSet <Box>(boxes, new BoxSameDimensionsComparer()); var secondHashSet = hashSet; hashSet.SetEquals(secondHashSet).Should().BeTrue(); }
public void TestUnionWith_BothArentEmpty() { MyHashSet <int> firstSet = new MyHashSet <int>(); int itemsCount = 5; for (int i = 0; i < itemsCount; i++) { firstSet.Add(i); } MyHashSet <int> secondSet = new MyHashSet <int>(); for (int i = 3; i < 7; i++) { secondSet.Add(i); } // 0,1,2,3,4 U 3,4,5,6 = 0,1,2,3,4,5,6 firstSet.UnionWith(secondSet); Assert.AreEqual(7, firstSet.Count); Assert.IsTrue(firstSet.Contains(0)); Assert.IsTrue(firstSet.Contains(1)); Assert.IsTrue(firstSet.Contains(2)); Assert.IsTrue(firstSet.Contains(3)); Assert.IsTrue(firstSet.Contains(4)); Assert.IsTrue(firstSet.Contains(5)); Assert.IsTrue(firstSet.Contains(6)); }
private static void MyHashSetFunctionality() { var set = new MyHashSet <int>() { 1, 2, 5, 4 }; set.Add(64); set.Add(0); foreach (var item in set) { Console.WriteLine(item); } set.Remove(64); Console.WriteLine("64 was removed"); foreach (var item in set) { Console.WriteLine(item); } set.Clear(); Console.WriteLine($"Set was cleared and it's size: {set.Count}"); }
public void TestRemove() { var hashSet = new MyHashSet<int> { 5, 3, 4 }; hashSet.Remove(4); Assert.IsFalse(hashSet.Contains(4)); }
public void ShouldAddItem() { hashSet = new MyHashSet <Box>(); hashSet.Add(boxes[0]).Should().BeTrue(); hashSet.Should().BeEquivalentTo(boxes[0]); hashSet.Count.Should().Be(1); }
public void Should_BeEmptyAfterCreation_WithoutComparer() { hashSet = new MyHashSet <Box>(); hashSet.Should().BeEmpty(); hashSet.Count.Should().Be(0); hashSet.Comparer.Should().Be(EqualityComparer <Box> .Default); }
public void Check_For_The_Presence_Of_Null() { hashSet = new MyHashSet <Box>(); hashSet.Contains(null).Should().BeFalse(); hashSet.Should().BeEmpty(); hashSet.Count.Should().Be(0); }
public void Add_SingleItem_CanAdd(int input, bool expected) { var sut = new MyHashSet(); sut.Add(input); var actual = sut.Contains(input); Assert.AreEqual(expected, actual); }
private static void DisplaySet(MyHashSet <int> collection) { Console.Write("{"); foreach (var i in collection) { Console.Write(" {0}", i); } Console.WriteLine(" }"); }
public void Should_Correctly_SymmetricExceptWith_ReferenceEqual_Collection() { hashSet = new MyHashSet <Box>(boxes, new BoxSameDimensionsComparer()); var secondHashSet = hashSet; hashSet.SymmetricExceptWith(secondHashSet); hashSet.Should().BeEmpty(); }
public void UnionWith_TwoCollections_WithSameItems() { hashSet = new MyHashSet <Box>(new [] { boxes[0], boxes[1] }, new BoxSameDimensionsComparer()); hashSet.UnionWith(new [] { boxes[1], boxes[2] }); hashSet.Should().BeEquivalentTo(boxes); hashSet.Count.Should().Be(3); }
public void Should_Correctly_UnionWith_ReferenceEqual_Collection() { hashSet = new MyHashSet <Box>(boxes, new BoxSameDimensionsComparer()); var secondHashSet = hashSet; hashSet.UnionWith(secondHashSet); hashSet.Should().BeEquivalentTo(boxes); }
public void AddAllCollection_After_SymmetricExceptWith_If_It_IsEmpty() { hashSet = new MyHashSet <Box>(); hashSet.SymmetricExceptWith(boxes); hashSet.Should().BeEquivalentTo(boxes); hashSet.Count.Should().Be(3); }
public void SymmetricExceptWithCorrectly() { hashSet = new MyHashSet <Box>(new[] { boxes[0], boxes[2] }); hashSet.SymmetricExceptWith(new[] { boxes[1], boxes[2] }); hashSet.Should().BeEquivalentTo(boxes[0], boxes[1]); hashSet.Count.Should().Be(2); }
public void IntersectWith() { hashSet = new MyHashSet <Box>(boxes, new BoxSameDimensionsComparer()); hashSet.IntersectWith(new [] { boxes[1] }); hashSet.Should().BeEquivalentTo(boxes[1]); hashSet.Count.Should().Be(1); }
public void NotChange_After_SymmetricExceptWith_EmptyCollection() { hashSet = new MyHashSet <Box>(boxes, new BoxSameDimensionsComparer()); hashSet.SymmetricExceptWith(new Box[0]); hashSet.Should().BeEquivalentTo(boxes); hashSet.Count.Should().Be(3); }
public void Clear() { hashSet = new MyHashSet <Box>(boxes); hashSet.Clear(); hashSet.Should().BeEmpty(); hashSet.Count.Should().Be(0); }
public void CopyTo() { hashSet = new MyHashSet <Box>(boxes); var array = new Box[hashSet.Count]; hashSet.CopyTo(array, 0); array.Should().BeEquivalentTo(boxes); }
public void ShouldRemoveItem() { hashSet = new MyHashSet <Box> { boxes[0], boxes[1] }; hashSet.Remove(boxes[1]).Should().BeTrue(); hashSet.Should().BeEquivalentTo(boxes[0]); hashSet.Count.Should().Be(1); }
public void ShouldAddItem_As_Collection() { hashSet = new MyHashSet <Box>(); var hashSetAsCollection = (ICollection <Box>)hashSet; hashSetAsCollection.Add(boxes[0]); hashSetAsCollection.Should().BeEquivalentTo(boxes[0]); hashSet.Count.Should().Be(1); }
public void ReturnFalse_After_TryToRemoveItem_ThatItDoesNotContain() { hashSet = new MyHashSet <Box> { boxes[0] }; hashSet.Remove(boxes[2]).Should().BeFalse(); hashSet.Should().BeEquivalentTo(boxes[0]); hashSet.Count.Should().Be(1); }
public void ExampleTest4() { MyHashSet myHashSet = new MyHashSet(); myHashSet.Add(1); // set = [1] myHashSet.Add(2); // set = [1, 2] var actual = myHashSet.Contains(3); // return False, (never added) Assert.False(actual); }
public void ExampleTest1() { MyHashSet myHashSet = new MyHashSet(); myHashSet.Add(1); // set = [1] myHashSet.Add(2); // set = [1, 2] var actual = myHashSet.Contains(1); // return True Assert.True(actual); }
public void ReturnFalse_After_Checking_For_The_Presence_Of_An_Item_ThatItDoesNotContain() { hashSet = new MyHashSet <Box> { boxes[0], boxes[1] }; hashSet.Contains(boxes[2]).Should().BeFalse(); hashSet.Should().BeEquivalentTo(boxes[0], boxes[1]); hashSet.Count.Should().Be(2); }
public void ReturnFalse_After_TryToAddItem_ThatItAlreadyContain() { hashSet = new MyHashSet <Box> { boxes[0] }; hashSet.Add(boxes[0]).Should().BeFalse(); hashSet.Should().BeEquivalentTo(boxes[0]); hashSet.Count.Should().Be(1); }
public void ReturnTrue_After_Checking_For_The_Presence_Of_An_Item_ThatItContains() { hashSet = new MyHashSet <Box> { boxes[0] }; hashSet.Contains(boxes[0]).Should().BeTrue(); hashSet.Should().BeEquivalentTo(boxes[0]); hashSet.Count.Should().Be(1); }
private static void Main() { var hashSet = new MyHashSet<int>(); var otherSet = new MyHashSet<int>(); for (int i = 0; i < 20; i++) { hashSet.Add(i); otherSet.Add(i + 1); } Console.WriteLine("Test intersect:"); otherSet.IntersectWith(hashSet); Console.WriteLine(otherSet); otherSet.Add(-1); otherSet.Add(1000); Console.WriteLine("Test union:"); otherSet.UnionWith(hashSet); Console.WriteLine(otherSet); }
static void Main(string[] args) { var set = new MyHashSet<int>(); set.Add(5); set.Add(19); set.Add(1513513); set.Add(4464); Console.WriteLine("Count: {0}", set.Count); var anotherSet = new MyHashSet<int>(); anotherSet.Add(-5); anotherSet.Add(19); anotherSet.Add(1513513); anotherSet.Add(-111); set.Union(anotherSet); Console.WriteLine("Elements after union: {0}", string.Join(", ", set.Elements())); // count gives back as a result 5 because 5 and -5 have got equal hash codes Console.WriteLine("Count: {0}", set.Count); set.Intersect(anotherSet); Console.WriteLine("Elements after intersect: {0}", string.Join(", ", set.Elements())); Console.WriteLine("Contains value: {0} -> {1}", 4464, set.Contains(4464)); Console.WriteLine("Contains value: {0} -> {1}", 4, set.Contains(4)); Console.WriteLine("Count: {0}", set.Count); anotherSet.Clear(); Console.WriteLine("Another set elements: {0}", string.Join(", ", anotherSet.Elements())); // if we add one value more than once exception is thrown because it is not valid in hash set // set.Add(5); }
public static void Main() { var firstSet = new MyHashSet<int>(); var secondSet = new MyHashSet<int>(); for (int i = 0; i < 15; i++) { int valueToAdd = i * 5; firstSet.Add(valueToAdd); if (i % 3 == 0) { secondSet.Add(valueToAdd); } } secondSet.Add(13); secondSet.Add(19); Console.WriteLine("First set count of elements = {0}", firstSet.Count); firstSet.Remove(20); firstSet.Remove(5); Console.WriteLine("First set count of elements = {0}", firstSet.Count); int ten = firstSet.Find(10); Console.WriteLine("Is ten in the first set {0}", ten == 10 ? "YES" : "NO"); Console.WriteLine("First set = {0}", firstSet); Console.WriteLine("Second set = {0}", secondSet); var unionSet = firstSet.Union(secondSet); Console.WriteLine("Union set = {0}", unionSet); var intersectSet = firstSet.Intersect(secondSet); Console.WriteLine("Intersect set = {0}", intersectSet); }
public void TestCreation() { var hashSet = new MyHashSet<int>(); Assert.AreEqual(0, hashSet.Count); }
public void TestAdd() { var hashSet = new MyHashSet<int> { 5, 3, 4 }; Assert.AreEqual(3, hashSet.Count); }
public void TestClear() { var hashSet = new MyHashSet<int> { 5, 3, 4 }; hashSet.Clear(); Assert.AreEqual(0, hashSet.Count); }