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 BaseTest() { // Act & Assert hashSet.Add(1); hashSet.Add(2); Assert.IsTrue(hashSet.Contains(1)); // returns true Assert.IsFalse(hashSet.Contains(3)); // returns false (not found) hashSet.Add(2); Assert.IsTrue(hashSet.Contains(2)); // returns true hashSet.Remove(2); Assert.IsFalse(hashSet.Contains(2)); // returns false (already removed) }
public void AddItem() { var a = new int[10]; var set = new MyHashSet <int>(); set.Add(1); Assert.IsTrue(set.Contains(1)); Assert.IsFalse(set.Contains(2)); Assert.IsFalse(set.Contains(3)); }
public void ContainsTest() { MyHashSet hashSet = new MyHashSet(); hashSet.Add(1); hashSet.Add(2); Assert.IsTrue(hashSet.Contains(1)); // 返回 true Assert.IsFalse(hashSet.Contains(3)); // 返回 false (未找到) hashSet.Add(2); Assert.IsTrue(hashSet.Contains(2)); // 返回 true hashSet.Remove(2); Assert.IsFalse(hashSet.Contains(2)); // 返回 false (已经被删除) }
public static void Print() { var evenNumbers = new MyHashSet <int>(); var oddNumbers = new MyHashSet <int>(); for (var i = 0; i < 5; i++) { evenNumbers.Add(i * 2); oddNumbers.Add((i * 2) + 1); } Console.WriteLine("evenNumbers contains {0} elements: ", evenNumbers.Count); DisplaySet(evenNumbers); Console.WriteLine("oddNumbers contains {0} elements: ", oddNumbers.Count); DisplaySet(oddNumbers); Console.WriteLine($"oddNumbers contains 1? {oddNumbers.Contains(1)}"); Console.WriteLine($"oddNumbers contains 2? {oddNumbers.Contains(2)}"); Console.WriteLine($"evenNumbers contains 1? {evenNumbers.Contains(1)}"); Console.WriteLine($"evenNumbers contains 2? {evenNumbers.Contains(2)}"); Console.WriteLine($"\nAdding existing values: "); Console.WriteLine($"Add to oddNumbers 1: {oddNumbers.Add(1)}"); Console.WriteLine($"Add to evenNumbers 2: {evenNumbers.Add(2)}"); Console.WriteLine("\nClearing and reinitializing"); evenNumbers.Clear(); oddNumbers.Clear(); Console.WriteLine("evenNumbers contains {0} elements: ", evenNumbers.Count); DisplaySet(evenNumbers); Console.WriteLine("oddNumbers contains {0} elements: ", oddNumbers.Count); DisplaySet(oddNumbers); for (var i = 0; i < 5; i++) { evenNumbers.Add(i * 2); oddNumbers.Add((i * 2) + 1); } Console.WriteLine("evenNumbers contains {0} elements: ", evenNumbers.Count); DisplaySet(evenNumbers); Console.WriteLine("oddNumbers contains {0} elements: ", oddNumbers.Count); DisplaySet(oddNumbers); }
// Start is called before the first frame update void Start() { MyHashSet hashSet = new MyHashSet(); hashSet.Add(1); hashSet.Add(2); Debug.Log(hashSet.Contains(1)); // 返回 true Debug.Log(hashSet.Contains(3)); // 返回 false (未找到) hashSet.Add(2); Debug.Log(hashSet.Contains(2)); // 返回 true hashSet.Remove(2); Debug.Log(hashSet.Contains(2)); // 返回 false (已经被删除) }
public void Test1() { MyHashSet obj = new MyHashSet(); obj.Add(1); obj.Add(2); obj.Add(2); var a = obj.Contains(1); var a1 = obj.Contains(3); var a2 = obj.Contains(2); obj.Remove(2); var a3 = obj.Contains(2); Assert.Pass(); }
public void TestContains() { MyHashSet <int> set = new MyHashSet <int>(); int itemsCount = 100; for (int i = 0; i < itemsCount; i++) { set.Add(i); } Assert.IsTrue(set.Contains(0)); Assert.IsTrue(set.Contains(99)); Assert.IsTrue(set.Contains(28)); Assert.IsFalse(set.Contains(-1)); Assert.IsFalse(set.Contains(120)); }
public void TestRemove() { var hashSet = new MyHashSet<int> { 5, 3, 4 }; hashSet.Remove(4); Assert.IsFalse(hashSet.Contains(4)); }
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 TestClear() { MyHashSet <int> set = new MyHashSet <int>(); int itemsCount = 100; for (int i = 0; i < itemsCount; i++) { set.Add(i); } Assert.AreEqual(100, set.Count); Assert.IsTrue(set.Contains(5)); set.Clear(); Assert.AreEqual(0, set.Count); Assert.IsFalse(set.Contains(5)); }
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)); }
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); }
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 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 Contains(int input, int isInHash, bool expected) { var sut = new MyHashSet(); sut.Add(input); var actual = sut.Contains(isInHash); Assert.AreEqual(expected, actual); }
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); }
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 Check_For_The_Presence_Of_An_Item_With_Using_Comparer() { hashSet = new MyHashSet <Box>(new BoxSameVolumeComparer()) { boxes[0] }; hashSet.Contains(boxes[1]).Should().BeTrue(); hashSet.Should().BeEquivalentTo(boxes[0]); hashSet.Count.Should().Be(1); }
public void ExampleTest3() { MyHashSet myHashSet = new MyHashSet(); myHashSet.Add(1); // set = [1] myHashSet.Add(2); // set = [1, 2] myHashSet.Add(2); // set = [1, 2] myHashSet.Remove(2); // set = [1] var actual = myHashSet.Contains(2); // return False, (already removed) Assert.False(actual); }
public void NullExceptionTest(string value, Type expectedEx) { var set = new MyHashSet <string>(); void Result1() => set.Add(value); void Result2() => set.Remove(value); void Result3() => set.Contains(value); Assert.Throws(expectedEx, Result1); Assert.Throws(expectedEx, Result2); Assert.Throws(expectedEx, Result3); }
public void Add_AddCollisions_ReturnsFalseIfDoesNotContain(int[] arrange, int input, bool expected) { var sut = new MyHashSet(); foreach (var val in arrange) { sut.Add(val); } var actual = sut.Contains(input); Assert.AreEqual(expected, actual); }
public void ContainsTest(List <int> source, List <int> containsNumbers, List <bool> expectedList) { var set = new MyHashSet <int>(); foreach (var num in source) { set.Add(num); } var result = containsNumbers.Select(item => set.Contains(item)).ToList(); Assert.That(result, Is.EqualTo(expectedList)); }
public void Rehasing() { var o1 = new Obj("Teste1"); var o2 = new Obj("Teste2"); var o3 = new Obj("Teste3"); var o4 = new Obj("Teste4"); var o5 = new Obj("Teste5"); var o6 = new Obj("Teste6"); var o7 = new Obj("Teste7"); var o8 = new Obj("Teste8"); var o9 = new Obj("Teste9"); var o10 = new Obj("Teste10"); var set = new MyHashSet <Obj>(5); set.Add(o1); set.Add(o2); set.Add(o3); set.Add(o4); set.Add(o5); set.Add(o7); set.Add(o8); set.Add(o9); set.Add(o10); set.Remove(o2); Assert.IsTrue(set.Contains(o1)); Assert.IsFalse(set.Contains(o2)); Assert.IsTrue(set.Contains(o3)); Assert.IsTrue(set.Contains(o4)); Assert.IsTrue(set.Contains(o5)); Assert.IsFalse(set.Contains(o6)); Assert.IsTrue(set.Contains(o7)); Assert.IsTrue(set.Contains(o8)); Assert.IsTrue(set.Contains(o9)); Assert.IsTrue(set.Contains(o10)); }
public void Remove_SingleItem_CanRemove() { var sut = new MyHashSet(); var input = 1; var expected = false; sut.Add(input); sut.Remove(input); var actual = sut.Contains(input); Assert.AreEqual(expected, actual); }
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 void Add_AddCollisions_ReturnValue(int[] inputs) { var sut = new MyHashSet(); foreach (var input in inputs) { sut.Add(input); } foreach (var input in inputs) { var doesContain = sut.Contains(input); Assert.IsTrue(doesContain); } }
public void TestIntersectWith_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 ^ 3,4,5,6 = 3,4 firstSet.IntersectWith(secondSet); Assert.AreEqual(2, firstSet.Count); Assert.IsTrue(firstSet.Contains(3)); Assert.IsTrue(firstSet.Contains(4)); }
public void TestRemove_Fail() { MyHashSet <int> set = new MyHashSet <int>(); int itemsCount = 100; for (int i = 0; i < itemsCount; i++) { set.Add(i); } bool removed = set.Remove(100); Assert.AreEqual(false, removed); Assert.AreEqual(100, set.Count); Assert.IsTrue(set.Contains(5)); }
public void TestRemove_Success() { MyHashSet <int> set = new MyHashSet <int>(); int itemsCount = 100; for (int i = 0; i < itemsCount; i++) { set.Add(i); } bool removed = set.Remove(5); Assert.AreEqual(true, removed); Assert.AreEqual(99, set.Count); Assert.IsFalse(set.Contains(5)); }
public void RunProblem() { /* * MyHashSet hashSet = new MyHashSet(); * hashSet.Add(1); * hashSet.Add(2); * var temp = hashSet.Contains(1); // 返回 true * if (temp != true) throw new Exception(); * * temp = hashSet.Contains(3); // 返回 false (未找到) * if (temp != false) throw new Exception(); * * hashSet.Add(2); * temp = hashSet.Contains(2); // 返回 true * if (temp != true) throw new Exception(); * * hashSet.Remove(2); * temp = hashSet.Contains(2); // 返回 false (已经被删除) * if (temp != false) throw new Exception(); */ var lines = File.ReadAllLines(@"C:\MSCode\JSON.json"); var commands = Newtonsoft.Json.JsonConvert.DeserializeObject <string[]>(lines[0]); var nums = Newtonsoft.Json.JsonConvert.DeserializeObject <int[][]>(lines[1]); MyHashSet hashSet = new MyHashSet(); for (int i = 0; i < commands.Length; i++) { switch (commands[i]) { case "add": hashSet.Add(nums[i].First()); break; case "remove": hashSet.Remove(nums[i].First()); break; case "contains": var result = hashSet.Contains(nums[i].First()); break; } } }
public void ContainsTest() { Assert.IsFalse(new MyHashSet <string>().Contains(null)); MyHashSet <string> myHashSet = new MyHashSet <string>() { "abs", "aaa", "bbb", "asdfsad" }; CollectionAssert.AreEquivalent(new string[] { "abs", "aaa", "bbb", "asdfsad" }, myHashSet); Assert.IsTrue(myHashSet.Contains("abs")); Assert.IsTrue(myHashSet.Contains("aaa")); Assert.IsTrue(myHashSet.Contains("asdfsad")); Assert.IsTrue(myHashSet.Contains("bbb")); Assert.IsFalse(myHashSet.Contains("")); Assert.IsFalse(myHashSet.Contains(null)); Assert.IsFalse(myHashSet.Contains("ork2p3okr")); Assert.IsFalse(myHashSet.Contains("\0")); }