private P2PDataRequest(string dataNameToRequest, CustomHashTable parametersTable) { this._DataNameToRequest = dataNameToRequest.ToUpper(); this._operationID = Guid.NewGuid().ToString(); this._parametersTable = parametersTable; this._XMLDataString = ""; }
public P2PDataRequest(string dataNameToRequest) { this._DataNameToRequest = dataNameToRequest.ToUpper(); this._operationID = Guid.NewGuid().ToString(); this._parametersTable = new CustomHashTable(); this._XMLDataString = ""; }
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); }
public DPE_PublicationData(string PublicationName, string dataname, CustomHashTable data) { this._publicationName = PublicationName; this._dataname = dataname.ToUpper(); this._data = data; this._dataType = DPE_ServerDefs.PublicationVariableDataType.DPE_DT_CFHashTable; }
public void CopyTo_ArrayContainItemsWithHashTable_ReturnFalse() { CustomHashTable <int, char> hashTable = new CustomHashTable <int, char> { { 1, 't' }, { 2, 'y' }, { 4, 'i' }, { 5, 'c' }, { 6, 'r' }, { 13, 'o' } }; KeyValuePair <int, char>[] array = new KeyValuePair <int, char> [5]; array[0] = new KeyValuePair <int, char>(0, 'v'); try { hashTable.CopyTo(array, 1); Assert.IsTrue(true); } catch { Assert.IsFalse(false); } }
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 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 GetEnumerator_GetAllElements_GetTrue() { CustomHashTable <int, string> hashTable = new CustomHashTable <int, string> { { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" }, { 5, "5" }, { 6, "6" } }; KeyValuePair <int, string>[] sameElements = new KeyValuePair <int, string>[] { new KeyValuePair <int, string>(1, "1"), new KeyValuePair <int, string>(2, "2"), new KeyValuePair <int, string>(3, "3"), new KeyValuePair <int, string>(4, "4"), new KeyValuePair <int, string>(5, "5"), new KeyValuePair <int, string>(6, "6") }; foreach (var element in hashTable) { Assert.IsTrue(sameElements.Contains(element)); } }
public void TestConstructorAsItShuoldCreateTableWithInitialCapacityOf16() { var table = new CustomHashTable<int, int>(); PrivateObject accessor = new PrivateObject(table); LinkedList<KeyValuePair<int, int>>[] dataPrivateField = (LinkedList<KeyValuePair<int, int>>[])accessor.GetField("data"); Assert.AreEqual(16, dataPrivateField.Length); }
public DiscoverableServiceDefinitionParametersContainer() { this._parameters = new CustomHashTable(); this._serviceParametersDataTable = new DataTable(SERVICE_PARAMETERS); this._serviceParametersDataTable.Columns.Add(PARAMETER_NAME, System.Type.GetType("System.String")); this._serviceParametersDataTable.Columns.Add(PARAMETER_VALUE, System.Type.GetType("System.String")); }
private Boolean TryParse(SocketData data, out ALDSData ALDS_Data) { MachineStatusData machineStatus; if (MachineStatusData.TryParse(data, out machineStatus)) { ALDS_Data = machineStatus; return(true); } else { try { //creates an ALDS data using ALDS_Data = new ALDSData(data.DataName); CustomHashTable table = (CustomHashTable)data.Value; foreach (System.Collections.DictionaryEntry dice in table) { ALDS_Data.AttachDataAttribute((string)dice.Key, (string)dice.Value); } } catch (Exception ex) { ALDS_Data = null; return(false); } return(true); } }
public void TestConstructorAsItShuoldCreateTableWithInitialCapacityOf16() { var table = new CustomHashTable <int, int>(); PrivateObject accessor = new PrivateObject(table); LinkedList <KeyValuePair <int, int> >[] dataPrivateField = (LinkedList <KeyValuePair <int, int> >[])accessor.GetField("data"); Assert.AreEqual(16, dataPrivateField.Length); }
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 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); }
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 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 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); }
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 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 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 TestIfFindThrowsExeptionWhenInvalidKeyIsEntered() { 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>(7, 56), new KeyValuePair<int, int>(9, 45) }); table.Find(21); }
public void TestConstructorWithListOfPairs() { 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>(7, 56), new KeyValuePair<int, int>(8, 45) }); Assert.AreEqual(4, table.Count); }
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); }
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); } } }
internal DiscoverableServiceDefinitionParametersContainer(CustomHashTable parametersTable) : this() { IEnumerator enumm = parametersTable.GetEnumerator(); DictionaryEntry dicentry; while (enumm.MoveNext()) { dicentry = (DictionaryEntry)enumm.Current; this.AddParameter(Convert.ToString(dicentry.Key), Convert.ToString(dicentry.Value)); } }
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); }
private void RemoveClientConnectionToAPublicationRegister(DPE_Client client, DPE_Publication publication) { if (this._referenceTableOFConnectionsToPublicationsOfASTXDSSClient.ContainsKey(client.ClientID)) { CustomHashTable list = default(CustomHashTable); list = (CustomHashTable)this._referenceTableOFConnectionsToPublicationsOfASTXDSSClient[client.ClientID]; if (list.ContainsKey(publication.PublicationName)) { list.Remove(publication.PublicationName); } } }
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 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 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 TestIfRemoveThrowsExeptionWhenInvalidKeyIsEntered() { 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>(22, 45) }); table.Remove(21); }
internal static CNDAddressingReg GetAddressingRegister(CustomHashTable table) { if (!table.Contains(CNDServiceDefinitions.CND_TABLE_COMPONENT_NAME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Component Name]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_HOST_NAME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Hostname]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_P2P_PORT_NUMBER)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[P2PPortNumber]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_IP_ADDRESS)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[IPAddress]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_APPLICATION_NAME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Application Name]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_APPLICATION_PROCESS_ID)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Application Process ID]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_REGISTRATION_DATETIME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Registration Date Time]\' is missing.")); } string compName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_COMPONENT_NAME)); compName = compName.ToUpper(); string hostName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_HOST_NAME)); string P2PPortNumber = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_P2P_PORT_NUMBER)); string IPAddress = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_IP_ADDRESS)); string ApplicationName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_APPLICATION_NAME)); string ApplicationProcessID = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_APPLICATION_PROCESS_ID)); string RegistrationDateTime = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_REGISTRATION_DATETIME)); int PortNumber = Convert.ToInt32(P2PPortNumber); CNDAddressingReg reg = new CNDAddressingReg(compName, hostName, IPAddress, PortNumber, ApplicationName, ApplicationProcessID, RegistrationDateTime); return(reg); }
public void TestIfKeysPropertyReturnsAdequateValues() { 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>(9, 56), new KeyValuePair <int, int>(28, 45) }); Assert.AreEqual(4, table.Keys.Count); }
public void TestConstructorWithListOfPairs() { 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>(7, 56), new KeyValuePair <int, int>(8, 45) }); Assert.AreEqual(4, 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); }
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 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 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 TestIfIndexerWorksCorrectly() { 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>(7, 56), new KeyValuePair<int, int>(9, 45) }); var foundByIndex = table[9]; Assert.AreEqual(45, foundByIndex); }
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 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); }
public void TestConstructorAsItShuoldCreateEmptyHashTableW() { var table = new CustomHashTable<int, int>(); Assert.AreEqual(0, table.Count); }
public void ShouldCreateHashTableInstanceWithRightDefaultParameters() { var table = new CustomHashTable<int, int>(); Assert.AreEqual(0, table.Count); }
public void TestIfRemovingPairsWorksCorrectly() { 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>(9, 56), new KeyValuePair<int, int>(10, 45) }); table.Remove(5); Assert.AreEqual(3, table.Count); }
public void TestIfKeysPropertyReturnsAdequateValues() { 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>(9, 56), new KeyValuePair<int, int>(28, 45) }); Assert.AreEqual(4, table.Keys.Count); }
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)); }
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); } }