public void GetCollision1() { Hashtables hashTables = new Hashtables(); hashTables.Add("abc", "Josie"); hashTables.Add("cba", 22); hashTables.Add("acb", true); Assert.Equal("Josie", hashTables.GetValue("abc")); }
public void GetNull3() { Hashtables hashTables = new Hashtables(); hashTables.Add("abc", "Josie"); hashTables.Add("Dog", "Woof"); hashTables.Add("333", "ponies"); hashTables.Add("moons", "44"); Assert.Null(hashTables.GetValue("three")); }
public void GetFalse3() { Hashtables hashTables = new Hashtables(); hashTables.Add("abc", "Josie"); hashTables.Add("Dog", "Woof"); hashTables.Add("333", "ponies"); hashTables.Add("moons", "44"); Assert.False(hashTables.Contains("three")); }
public static void displayHashes() { Hashtables hashTables = new Hashtables(); hashTables.Add("abc", "Josie"); hashTables.Add("Dog", "Woof"); hashTables.Add("333", "ponies"); hashTables.Add("moons", "44"); hashTables.Add("cba", "Doctor"); //Collision abc same as cba Console.WriteLine($"Should return as 'True' for contains: {hashTables.Contains("moons")}"); Console.WriteLine($"Should return as 'False' for contains: {hashTables.Contains("planet")}"); Console.WriteLine($"Should return the value 'Woof' from key: {hashTables.GetValue("Dog")}"); Console.WriteLine($"Should return the value 'Doctor' from collision: {hashTables.GetValue("cba")}"); }
public static List <int> TreeIntersection(BinaryTree one, BinaryTree two) { //Final output as List instead of int array. List <int> output = new List <int>(); Hashtables hashTables = new Hashtables(); //Pass Binary trees into List<> List <int> treeOneList = one.PreOrder(one.Root); List <int> treeTwoList = two.PreOrder(two.Root); //Add all of tree one into hashtable foreach (var item in treeOneList) { hashTables.Add(item.ToString(), item); } //compare tree two if buckets in hashtable are already occupied. //If collision occurs add that number to the List output. foreach (var item in treeTwoList) { if (hashTables.Contains(item.ToString())) { output.Add(item); } } /* * foreach (var item in output) * { * Console.WriteLine(item); * }*/ return(output); }
public void GetValue(string key, object value) { Hashtables hashTables = new Hashtables(); hashTables.Add(key, value); Assert.Equal(value, hashTables.GetValue(key)); }
public void GetTrue(string key, object value) { Hashtables hashTables = new Hashtables(); hashTables.Add(key, value); Assert.True(hashTables.Contains(key)); }
public void Test3() { Hashtables tableOne = new Hashtables(); tableOne.Add("fond", "enamored"); tableOne.Add("wrath", "anger"); Hashtables tableTwo = new Hashtables(); tableTwo.Add("fond", "averse"); tableTwo.Add("wrath", "delight"); List <string> expected = new List <string>() { "fond", "enamored", "averse", "wrath", "anger", "delight" }; Assert.Equal(expected, Program.LeftJoin(tableOne, tableTwo)); }
static void Main(string[] args) { Console.WriteLine("Hello Left Join"); Console.WriteLine(""); Hashtables tableOne = new Hashtables(); tableOne.Add("abc", "enamored"); tableOne.Add("abcd", "anger"); tableOne.Add("qwerty", "employed"); tableOne.Add("outfit", "garb"); tableOne.Add("guide", "usher"); tableOne.Add("extremetomax", "end"); Hashtables tableTwo = new Hashtables(); tableTwo.Add("abc", "averse"); tableTwo.Add("abcd", "delight"); tableTwo.Add("qwerty", "idle"); tableTwo.Add("empty", "gone"); tableTwo.Add("nope", "never"); tableTwo.Add("extremetomax", "jam"); List <string> result = LeftJoin(tableOne, tableTwo); Console.WriteLine($"[{string.Join(",", result)}]"); Console.ReadLine(); }
public static string RepeatedWord(string input) { string[] listOfWord = input.ToLower().Split(',', ' ', '.'); Hashtables hashWords = new Hashtables(); for (int i = 0; i < listOfWord.Length; i++) { string temp = listOfWord[i]; if (hashWords.Contains(temp)) { return(temp); } else { hashWords.Add(temp, temp); } } return("No repeated word found."); }
private static Hashtables DBExecuteReader(String SQLCommand, Parameters SQLParams) { Hashtables lstHashtable; DbCommand DbComm = GETDBCommand(DBCore.SQLDBType); try { DbComm.CommandText = SQLCommand; GETDBParams(DbComm, SQLParams); DbComm.Connection.Open(); using (DbDataReader dr = DbComm.ExecuteReader(CommandBehavior.CloseConnection)) { lstHashtable = new Hashtables(); while (dr.Read()) { Hashtable h = new Hashtable(); for (int i = 0; i < dr.FieldCount; i++) h.Add(dr.GetName(i).ToLower(), dr[i]); lstHashtable.Add(h); } } } catch (Exception) { throw; } finally { if (DbComm.Connection.State == ConnectionState.Open) DbComm.Connection.Close(); } return lstHashtable; }