public void TestCustomHashTableAddExistingKey(string rawTestDict) { var hashTable = new CustomHashTable(TestSize); var testDict = GetDictionaryFromString(rawTestDict); foreach (var dicItem in testDict) { hashTable.Add(dicItem.Key, dicItem.Value); } try { hashTable.Add(testDict.First().Key, new Random().Next()); } catch (HashTableElementPresenceException ex) { return; } catch (Exception ex) { Assert.Fail("Method Add doesn't work correctly"); } Assert.Fail("Method Add doesn't work correctly"); }
public void AddTwoKeyValueAndRetrieveBoth() { var customHashTable = new CustomHashTable <string, Person>(); var person = new Person { Name = "Vaibhav", Age = 35 }; customHashTable.Add(person.Name, person); var personTwo = new Person { Name = "Vaibhav Bali", Age = 35 }; customHashTable.Add(personTwo.Name, personTwo); Assert.IsTrue(customHashTable.Contains(person.Name)); var element = customHashTable.GetElement(person.Name); Assert.IsNotNull(element); Assert.AreEqual(person.Name, element.Name); Assert.AreEqual(person.Age, element.Age); Assert.IsTrue(customHashTable.Contains(personTwo.Name)); var secondElement = customHashTable.GetElement(personTwo.Name); Assert.IsNotNull(secondElement); Assert.AreEqual(personTwo.Name, secondElement.Name); Assert.AreEqual(personTwo.Age, secondElement.Age); }
internal CustomHashTable GetPublicationParametersTable() { CustomHashTable table = new CustomHashTable(); table.Add(DPE_PublicationsDefinitions.DPE_PUBLICATION_HOSTNAME, System.Net.Dns.GetHostName()); table.Add(DPE_PublicationsDefinitions.DPE_PUBLICATION_PORT, this._publicationSocketsServer.ListeningPort); return(table); }
public void ShouldAddCorrectNumberOfElements() { var table = new CustomHashTable<int, int>(); table.Add(1, 3); table.Add(2, 5); table.Add(3, 7); Assert.AreEqual(3, table.Count); }
public void ShouldAddNumberOfElementsCorrectly() { var table = new CustomHashTable <int, int>(); table.Add(1, 1); table.Add(2, 2); table.Add(3, 3); Assert.AreEqual(3, table.Count); }
public void ShouldAutoResizeInnerCollection() { var table = new CustomHashTable<int, int>(1); table.Add(1, 113); table.Add(2, 411); table.Add(3, 231); Assert.AreEqual(3, table.Count); }
public void ShouldAutoResizeInnerCollection() { var table = new CustomHashTable <int, int>(1); table.Add(1, 111); table.Add(2, 211); table.Add(3, 131); Assert.AreEqual(3, table.Count); }
public void Add_Test() { var hashtable = new CustomHashTable <int>(); for (int i = 0; i < 125; i++) { hashtable.Add(i); } hashtable.Add(1); }
public void Button7_Click(System.Object sender, System.EventArgs e) { CustomHashTable hashtable = new CustomHashTable(); hashtable.Add(1, "hugo"); hashtable.Add(2, "jose"); hashtable.Add(3, 3); hashtable.Add(4, 32); SocketData dataSortedList = new SocketData("HASHTABLE_DATA", hashtable); SocketData data = SocketData.ParseAndGet_SocketData_FromXMLDataString(dataSortedList.XMLDataString); this.txtDataSocketXMLString.Text = ""; this.txtDataSocketXMLString.Text = data.XMLDataString; }
public void AddSameKeyResultsInException() { var customHashTable = new CustomHashTable <string, Person>(); var person = new Person { Name = "Vaibhav", Age = 35 }; var personTwo = new Person { Name = "Vaibhav", Age = 33 }; customHashTable.Add(person.Name, person); customHashTable.Add(person.Name, personTwo); }
public void GivenAnElementWhenAddToHashTableThenGet() { //Given CustomHashTable <string> hashTable = new CustomHashTable <string>(); //When hashTable.Add(3, "teste 1"); hashTable.Add(4378, "teste 2"); hashTable.Add(999999999, "teste 3"); var actual = hashTable.Search(4378); //Then Assert.Equal("teste 2", actual); }
static void Main(string[] args) { var hashFunctions = new HashFunctions(); var hashTable = new CustomHashTable <string, string>(hashFunctions.HashObject); hashTable.Add("12", "Stefan Peev"); hashTable.Add("abc", "Ivan Gabrovski"); System.Console.WriteLine(hashTable.Find("12")); System.Console.WriteLine(hashTable.Find("abc")); foreach (var item in hashTable) { System.Console.WriteLine($"{item.Key}, {item.Value}"); } }
public void TestCustomHashTableRemove(string rawTestDict) { var hashTable = new CustomHashTable(TestSize); var testDict = GetDictionaryFromString(rawTestDict); foreach (var dicItem in testDict) { hashTable.Add(dicItem.Key, dicItem.Value); } foreach (var dictItem in testDict) { hashTable.Remove(dictItem.Key); try { var dummy = hashTable[dictItem.Key]; } catch (HashTableElementAbsenceException ex) { continue; } catch (Exception ex) { Assert.Fail("Method Remove doesn't remove hashteble item correctly"); } Assert.Fail("Method Remove doesn't remove hashteble item correctly"); } }
public void GivenAValidHashTableWhenSearchAInexistentKeyThenReturnEmpty() { //Given CustomHashTable <string> hashTable = new CustomHashTable <string>(); //When hashTable.Add(3, "teste 1"); hashTable.Add(4378, "teste 2"); hashTable.Add(999999999, "teste 3"); hashTable.Add(28359889863, "document of person"); var actual = hashTable.Search(4859540); //Then Assert.Equal(null, actual); }
public void GivenAnValidKeyWhenAddToHashTableThenSearchKeyAValueIsFound() { //Given CustomHashTable <string> hashTable = new CustomHashTable <string>(); //When hashTable.Add(3, "teste 1"); hashTable.Add(4378, "teste 2"); hashTable.Add(999999999, "teste 3"); hashTable.Add(28359889863, "document of person"); var actual = hashTable.Search(28359889863); //Then Assert.Equal("document of person", actual); }
internal void PostPublicationOnServer(DPE_ClientPublicationDefinition PublicationDefinition) { //crates the publication definition into a P2PData to send to the server CustomHashTable varsToPublish = new CustomHashTable(); string variableName = ""; DPE_ServerDefs.PublicationVariableDataType variableDataType = default(DPE_ServerDefs.PublicationVariableDataType); string variableDataTypeAsString = ""; IEnumerator enumm = PublicationDefinition.VariablesToPublishTable.GetEnumerator(); while (enumm.MoveNext()) { variableName = System.Convert.ToString(((DictionaryEntry)enumm.Current).Key); variableDataType = (DPE_ServerDefs.PublicationVariableDataType)(((DictionaryEntry)enumm.Current).Value); variableDataTypeAsString = DPE_ServerDefs.Get_String_FromPublicationVariableDataType(variableDataType); varsToPublish.Add(variableName, variableDataTypeAsString); } P2PData data = new P2PData(DPE_ServerDefs.DPE_CMD_CREATE_PUBLICATION, varsToPublish); data.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATIONS_GROUP, PublicationDefinition.PublicationsGroup); data.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_CLIENT_ID, this._STXDataSocketClient.ClientID); data.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_NAME, PublicationDefinition.PublicationName); Services.P2PCommunicationsScheme.P2PPortClient p2pclient = default(Services.P2PCommunicationsScheme.P2PPortClient); try { p2pclient = new Services.P2PCommunicationsScheme.P2PPortClient(this._STXDataSocketClient.DSSServerHostName, this._STXDataSocketClient.PublicationsPost_PortNumber); p2pclient.Connect(); //sends the information to the server in order to create it p2pclient.SendData(P2PDataSendMode.SyncrhonicalSend, data); p2pclient.Dispose(); //it the publication was created in the server then ists definition is saved in the publications posted manager //in order to allow it to re create ii if needed this.AddPublicationDefinitionAfterCreation(PublicationDefinition); string msg = "Publication \'" + PublicationDefinition.PublicationName + "\' -> POSTED succesfully."; CustomEventLog.WriteEntry(EventLogEntryType.SuccessAudit, msg); } catch (Exception ex) { try { this.RemovePublicationDefinition(PublicationDefinition); } catch (Exception) { } string errMSg = ""; errMSg = "Error creating the publication \'" + PublicationDefinition.PublicationName + "\' : " + ex.Message; throw (new Exception(errMSg)); } }
public void ShouldReturnDefaultValueWhenKey() { var table = new CustomHashTable<int, int>(); table.Add(1, 200); var result = 555; var found = table.Find(8, out result); Assert.AreEqual(default(int), result); Assert.IsFalse(found); }
public void ShouldReturnCorrectValueByKey() { var table = new CustomHashTable<int, int>(); table.Add(1, 200); var result = 0; var found = table.Find(1, out result); Assert.AreEqual(200, result); Assert.IsTrue(found); }
static void Main(string[] args) { Random rand = new Random(); List <Player> players = new List <Player>(); for (int i = 0; i < 10000; ++i) { if (rand.Next(0, 2) == 0) { continue; } players.Add(new Player() { playerId = i }); } List <Salary> salaries = new List <Salary>(); for (int i = 0; i < 10000; ++i) { if (rand.Next(0, 2) == 0) { continue; } salaries.Add(new Salary() { playerId = i }); } // Hash Join -> TEMP HashTable 이용 == List를 순회하면서 hash table에 저장 // NL과의 차이 : hash table의 생성 여부 //Dictionary<int, Salary> hash = new Dictionary<int, Salary>(); CustomHashTable hash = new CustomHashTable(); foreach (Salary s in salaries) { hash.Add(s.playerId); } List <int> result = new List <int>(); foreach (Player p in players) { if (hash.Find(p.playerId)) { result.Add(p.playerId); } } }
public void ShouldReturnDefaultValueWhenKey() { var table = new CustomHashTable <int, int>(); table.Add(1, 111); var result = 555; var found = table.Find(8, out result); Assert.AreEqual(default(int), result); Assert.IsFalse(found); }
public void ShouldReturnDefaultValueAfterElementIsRemoved() { var table = new CustomHashTable<int, int>(); table.Add(7, 7); int result; Assert.IsTrue(table.Find(7, out result)); table.Remove(7); Assert.IsFalse(table.Find(7, out result)); Assert.AreEqual(default(int), result); }
public void ShouldReturnCorrectValueByKey() { var table = new CustomHashTable <int, int>(); table.Add(1, 111); var result = 0; var found = table.Find(1, out result); Assert.AreEqual(111, result); Assert.IsTrue(found); }
public void ShouldReturnKeysCorrectly() { var table = new CustomHashTable<int, int>(); var keys = new[] { 1, 2, 3 }; foreach (int key in keys) { table.Add(key, key * 100); } CollectionAssert.AreEqual(keys, table.Keys); }
public void TestCustomHashTableAdd(string rawTestDict) { var hashTable = new CustomHashTable(TestSize); var testDict = GetDictionaryFromString(rawTestDict); foreach (var dicItem in testDict) { hashTable.Add(dicItem.Key, dicItem.Value); } Assert.IsTrue(CheckHashTableContainsDict(hashTable, testDict)); }
public void AddOneKeyValue() { var customHashTable = new CustomHashTable <string, Person>(); var person = new Person { Name = "Vaibhav", Age = 35 }; customHashTable.Add(person.Name, person); Assert.IsTrue(customHashTable.Contains(person.Name)); }
public void ShouldReturnDefaultValueAfterElementIsRemoved() { var table = new CustomHashTable <int, int>(); table.Add(7, 7); int result; Assert.IsTrue(table.Find(7, out result)); table.Remove(7); Assert.IsFalse(table.Find(7, out result)); Assert.AreEqual(default(int), result); }
public void ShouldReturnKeysCorrectly() { var table = new CustomHashTable <int, int>(); var keys = new[] { 1, 2, 3 }; foreach (int key in keys) { table.Add(key, key * 100); } CollectionAssert.AreEqual(keys, table.Keys); }
public static void Main() { var table = new CustomHashTable<int, string>(); for (int i = 0; i < 50; i++) { table.Add(i, i.ToString()); } System.Console.WriteLine(table); System.Console.WriteLine(table.Count); }
public static void Main() { var table = new CustomHashTable <int, string>(); for (int i = 0; i < 50; i++) { table.Add(i, i.ToString()); } System.Console.WriteLine(table); System.Console.WriteLine(table.Count); }
private CustomHashTable GetCFHashTable() { CustomHashTable table = new CustomHashTable(); int i = 0; string key = ""; for (i = 0; i <= 10; i++) { key = this._client.ClientName + System.Convert.ToString(i); table.Add(key, i); } return(table); }
static void Main() { CustomHashTable<int, int> hassTable = new CustomHashTable<int, int>(); for (int i = 0; i < 20; i++) { hassTable.Add(i, i + 1); } Console.WriteLine(hassTable.Find(6)); // should print 7 Console.WriteLine(hassTable.Count); }
public void AddALotsOfIntegerItems_ItemsAreInTheDictionary() { var hashTable = new CustomHashTable <int, int>(); for (var index = 1; index <= 1000; index++) { hashTable.Add(index, index); } for (var index = 1; index <= 1000; index++) { Assert.AreEqual(index, hashTable[index]); } }
public void Contains_SomeElement_ReturnFalse() { CustomHashTable <string, int> hashTable = new CustomHashTable <string, int>(); for (var index = 1; index <= 100; index++) { hashTable.Add(index.ToString(), index); } for (var index = 100; index <= 200; index++) { var containsItem = hashTable.Contains(new KeyValuePair <string, int>(index.ToString(), 35)); Assert.IsFalse(containsItem); } }
public void AddALotsOfStringItems_ItemsAreInTheDictionary() { var hashTable = new CustomHashTable <string, string>(); for (var index = 1; index <= 1000; index++) { hashTable.Add($"Key_{index}", $"Value_{index}"); } for (var index = 1; index <= 1000; index++) { Assert.AreEqual($"Value_{index}", hashTable[$"Key_{index}"]); } }
public void Remote_Element_ReturnFalse() { CustomHashTable <string, int> hashTable = new CustomHashTable <string, int>(); for (int i = 0; i < 100; i++) { hashTable.Add(i.ToString(), i); } for (int i = 100; i < 200; i++) { var isRemote = hashTable.Remove(i.ToString(), i); Assert.IsFalse(isRemote); } }
public void CopyTo_ArrayContainItemsWithHashTable_ReturnTrue() { CustomHashTable <int, char> hashTable = new CustomHashTable <int, char>(); KeyValuePair <int, char>[] array = new KeyValuePair <int, char> [100]; for (int i = 0; i < 100; i++) { hashTable.Add(i, i.ToString()[0]); } hashTable.CopyTo(array, 0); foreach (var item in array) { Assert.AreEqual(item.Value, hashTable[item.Key]); } }
public void ChangeItems_SetAnotherValue_GetFalse() { var hashTable = new CustomHashTable <int, int>(); for (var index = 1; index <= 100; index++) { hashTable.Add(index, index); } for (var index = 1; index <= 100; index++) { hashTable[index] = 101; } for (var index = 1; index <= 100; index++) { Assert.IsFalse(index == hashTable[index]); } }
public void Remote_ElementNotFound_ReturnTrue() { var hashTable = new CustomHashTable <int, int>(); for (var index = 1; index <= 100; index++) { hashTable.Add(index, index); } for (var index = 1; index <= 100; index++) { var isRemote = hashTable.Remove(index); var isElement = hashTable.ContainsKey(index); Assert.AreEqual(isRemote, !isElement); } }
public void TestIfAddingNewPairsWorksCorrectly() { var table = new CustomHashTable<int, int>(new List<KeyValuePair<int, int>>() { new KeyValuePair<int, int>(5, 6), new KeyValuePair<int, int>(98, 6), new KeyValuePair<int, int>(8, 56), new KeyValuePair<int, int>(10, 45) }); table.Add(87, 89); table.Add(57, 189); table.Add(51, 89); table.Add(512, 189); table.Add(52, 819); table.Add(145, 89); Assert.AreEqual(10, table.Count); }
static void Main() { //IList<object> firstInput = new List<object>(); //IList<object> secondInput = new List<object>() //{ // 5.5, 3.487362, 345.0, -323232, 3, 3, -3, 6.7, 6, 6, 6, 7, 7, 7, 7, 6, 7, 8.909, 5, 7 //}; //IList<object> thirdInput = new List<object>() //{ // 5.4, 6.6, 6.6, 6.6, 6.7, 7.6, 7.6, 7, 6.5 //}; //IList<object> stringInput = new List<object>() //{ // "C#", "SQL", "PHP", "PHP", "SQL", "SQL" //}; //// 1. Write a program that counts in a given array of double values the number of occurrences of each value. //// This checks if the validation is ok //// It should throw exeption ////var numberOfOccurrenciesCrash = FindNumberOfOccurencies(firstInput); ////Console.WriteLine(); //var numberOfOccurrencies = FindNumberOfOccurencies(secondInput); //foreach (var pair in numberOfOccurrencies) //{ // if (pair.Value != 1) // { // Console.WriteLine("{0} -> {1} times", pair.Key, pair.Value); // } // else // { // Console.WriteLine("{0} -> 1 time", pair.Key); // } //} //Console.WriteLine(); //// 2. Write a program that extracts from a given sequence of strings all elements that present in it odd number of times. //IList<object> oddlyOccuredStrings = ExtractPresentedOddNumberOfTimes(stringInput); //foreach (var text in oddlyOccuredStrings) //{ // Console.WriteLine(text); //} //Console.WriteLine(); //// 3. Write a program that counts how many times each word from given text file words.txt appears in it. //string filepath = "../../text.txt"; //IList<KeyValuePair<string, int>> countedInText = CountWordNumberInText(filepath); //Console.OutputEncoding = Encoding.UTF8; //foreach (var pair in countedInText) //{ // if (pair.Value != 1) // { // Console.WriteLine("{0} -> {1} times", pair.Key, pair.Value); // } // else // { // Console.WriteLine("{0} -> 1 time", pair.Key); // } //} //Console.WriteLine(); var testHashTable = new CustomHashTable<int, string>(); testHashTable.Add(7, "ebalosie"); testHashTable.Add(8, "tuionui"); testHashTable.Add(9, "mamata"); testHashTable.Add(10, "tintirimitiri"); testHashTable.Add(23, "ebadsadasdalosie"); foreach (var pair in testHashTable) { Console.WriteLine("Key: {0} -> Value: {1}", pair.Key, pair.Value); } }
public void ShouldIterateCorrectly() { var result = new List<KeyValuePair<int, int>>(); var keys = new[] { 1, 3, 5, 7, 9 }; var values = new[] { 10, 30, 50, 70, 90 }; var table = new CustomHashTable<int, int>(); foreach (var key in keys) { table.Add(key, key * 10); } foreach (var pair in table) { result.Add(pair); } Assert.AreEqual(keys, result.Select(x => x.Key)); Assert.AreEqual(values, result.Select(x => x.Value)); }