public void AddTest() { // ARRANGE var set = new CustomSet <int>(); // ACT set.Add(1); // ASSERT Assert.AreEqual(1, set.Count); }
public void CustomSet_TestForAdd(List <string> expectedValue, params string[] values) { var actual = new CustomSet <string>(); foreach (var value in values) { actual.Add(value); } Assert.AreEqual(expectedValue, new List <string>(actual)); }
public bool Disjoint(CustomSet right) { if (this.hash.Count == 0) { return(true); } HashSet <int> tmp = new HashSet <int>(this.hash); tmp.IntersectWith(right.Hash); return(tmp.Count == 0 ? true : false); }
public void Add_NormalConditions_Test() { CustomSet <string> testSet = new CustomSet <string>(); CustomSet <string> expectedSet = new CustomSet <string> { "Test", "Test2" }; testSet.Add("Test"); testSet.Add("Test"); testSet.Add("Test2"); CollectionAssert.AreEqual(testSet, expectedSet); }
public bool TestUploadToFileDownload(CustomSet <Book> booksUp) { Logger.Logger logger = new Logger.Logger(); BooksXmlStorage storage = new BooksXmlStorage(logger, @"C:\Users\Polina\Documents\git\Net.W.2016.01.Freydlina.12\Net.W.2016.01.Freydlina.12\Net.W.2016.01.Freydlina.12\test2.xml"); BookListService serviceToSave = new BookListService(booksUp, logger); serviceToSave.SaveTo(storage); BookListService serviceToOpen = new BookListService(logger); serviceToOpen.OpenFrom(storage); return(serviceToSave.Equals(serviceToOpen)); }
public void Subset_NormalCOnditions_Test() { CustomSet <string> testSet = new CustomSet <string> { "Test", "Test3", "Test4", "Test5" }; CustomSet <string> subSet = new CustomSet <string> { "Test3", "Test4", }; var result = subSet.SubsetWith(testSet); Assert.That(result, Is.EqualTo(true)); }
public void RemoveTest() { // ARRANGE var set = new CustomSet <int>(); set.Add(1); // ACT set.Remove(1); // ASSERT Assert.AreEqual(0, set.Count); }
private static void CreateBookService() { CustomSet <Book> books = new CustomSet <Book>(3) { new Book("Announcing.NET Framework 4.6.2", "Microsoft", 2016, "Haffner, Stacey"), new Book(".NET Core - .NET Goes Cross - Platform with.NET Core", "Microsoft", 2016, "Carter, Phillip", "Knezevic, Zlatko"), new Book("Understanding .NET Just-In-Time Compilation", "Telerik") }; service = new BookListService(books, logger); Console.WriteLine(service.PrintBooks()); }
public void CustomQueue_TestForCopyTo(params string[] expectedResult) { var set = new CustomSet <string>(expectedResult.ToList()); var actual = new string[set.Count]; Console.WriteLine(string.Join(" ", set)); set.CopyTo(actual, 0); Console.WriteLine(string.Join(" ", actual.ToList())); Assert.AreEqual(expectedResult, actual); }
public CustomSet Difference(CustomSet right) { CustomSet res = this.Intersection(right); HashSet <int> res1 = new HashSet <int>(); foreach (int val in this.hash) { if (!right.Contains(val)) { res1.Add(val); } } return(new CustomSet(res1)); }
public void Intersection_NormalConditions_Test() { CustomSet <string> testSet = new CustomSet <string> { "Test", "Test3", "Test4" }; CustomSet <string> intersectionSet = new CustomSet <string> { "Test3", "Test4" }; CustomSet <string> expectedSet = new CustomSet <string> { "Test3", "Test4" }; testSet.IntersectionWith(intersectionSet); CollectionAssert.AreEqual(testSet, expectedSet); }
public void Difference_NormalConditions_Test() { CustomSet <string> testSet = new CustomSet <string> { "Test", "Test3", "Test4", "Test5" }; CustomSet <string> differenceSet = new CustomSet <string> { "Test3", "Test4", }; CustomSet <string> expectedSet = new CustomSet <string> { "Test", "Test5" }; testSet.DifferenceWith(differenceSet); CollectionAssert.AreEqual(testSet, expectedSet); }
public CustomSet Intersection(CustomSet right) { System.Collections.Generic.List <int> comValues = new System.Collections.Generic.List <int>(); foreach (int i in right.values) { foreach (int j in this.values) { if (i == j) { comValues.Add(i); } } } return(new CustomSet(comValues.ToArray())); }
public void CustomQueue_TestForCustomEqualityComparer(int[] values, int expectedResult) { var list = new List <CustomQueue <int> > (); while (list.Count != 5) { var queue = new CustomQueue <int>(5); foreach (var value in values) { queue.Enqueue(value); } list.Add(queue); } var set = new CustomSet <CustomQueue <int> >(list, new CustomQueueEqualityComparerByValues <int>()); Assert.AreEqual(1, set.Count); }
public CustomSet Union(CustomSet right) { if (this.values.Length == 0 && right.values.Length == 0) { return(new CustomSet()); } else if (this.values.Length == 0) { return(right); } else if (right.values.Length == 0) { return(this); } CustomSet retVal = new CustomSet(this.values); foreach (int i in right.values) { retVal = retVal.Add(i); } return(retVal); }
public bool Disjoint(CustomSet right) { if (this.values.Length == 0) { return(true); } if (right.values.Length == 0 && this.values.Length != 0) { return(true); } foreach (int i in right.values) { foreach (int j in this.values) { if (j == i) { return(false); } } } return(true); }
public CustomSet Difference(CustomSet right) { if (right.values.Length == 0) { return(new CustomSet(this.values)); } if (this.values.Length == 0) { return(new CustomSet()); } CustomSet tmpSet = this.Intersection(right); CustomSet retVal = new CustomSet(); foreach (int i in this.values) { if (Array.IndexOf(tmpSet.values, i) == -1) { retVal = retVal.Add(i); } } return(retVal); }
public override bool Equals(object obj) { CustomSet tmpSet = (CustomSet)obj; if (tmpSet.values.Length != this.values.Length) { return(false); } if (tmpSet.values.Length == 0 && this.values.Length == 0) { return(true); } Array left = Array.CreateInstance(typeof(int), this.values.Length); for (int i = 0; i < this.values.Length; i++) { left.SetValue(this.values[i], i); } Array.Sort(left); Array right = Array.CreateInstance(typeof(int), tmpSet.values.Length); for (int i = 0; i < tmpSet.values.Length; i++) { right.SetValue(tmpSet.values[i], i); } Array.Sort(right); for (int i = 0; i < this.values.Length; i++) { if (!left.GetValue(i).Equals(right.GetValue(i))) { return(false); } } return(true); }
public bool IsDisjointFrom(CustomSet <T> right) => !items.Keys.Any(key => right.items.ContainsKey(key));
public bool IsSubsetOf(CustomSet <T> right) => items.Keys.All(key => right.items.ContainsKey(key));
public CustomSet Union(CustomSet right) { return(new CustomSet(items.Values.Concat(right.items.Values).ToArray())); }
public bool Disjoint(CustomSet right) => !items.Keys.Any(key => right.items.ContainsKey(key));
public bool Subset(CustomSet right) => items.Keys.All(key => right.items.ContainsKey(key));
public void Sets_with_no_elements_are_empty() { var actual = new CustomSet <int>(); Assert.True(actual.IsEmpty()); }
public void Sets_with_elements_are_not_empty() { var sut = new CustomSet(new[] { 1 }); Assert.False(sut.Empty()); }
public CustomSet <T> Intersection(CustomSet <T> right) { var intersectionKeys = items.Keys.Intersect(right.items.Keys); return(new CustomSet <T>(GetValuesFromKeys(intersectionKeys))); }
public CustomSet <T> Difference(CustomSet <T> right) { var differenceKeys = items.Keys.Except(right.items.Keys); return(new CustomSet <T>(GetValuesFromKeys(differenceKeys))); }
public void Nothing_is_contained_in_an_empty_set() { var actual = new CustomSet <int>(); Assert.False(actual.Contains(1)); }
public void Sets_with_no_elements_are_empty() { var sut = new CustomSet(); Assert.True(sut.Empty()); }
public void Detect_if_the_element_is_not_in_the_set() { var actual = new CustomSet <int>(new[] { 1, 2, 3 }); Assert.False(actual.Contains(4)); }