public static void DeserializeProjects() { try { Projects = Serializer.ReadJsonData <AVLHashMap <string, Project> >("../projects.json"); } catch (Exception e) { Logger.LogError(e.SafeToString()); } }
public void TestAvlHashMaps() { hashmap = new AVLHashMap <string, string>(1); ExecuteTestHashMap(); hashmap.Clear(); hashmap = new AVLHashMap <string, string>(10); ExecuteTestHashMap(); hashmap.Clear(); hashmap = new AVLHashMap <string, string>(1024); ExecuteTestHashMap(); hashmap.Clear(); }
public TestWebRequestFactory() : base(false) { PremadeResponses = new AVLHashMap <string, string>() { { "http://www.bla.com/", "<html><head></head><body><a href='http://www.bla.com/blob'>hello</a><a href='/blob'><a href='./xyz'>hello</a><a href='secure/'>hello</a><b>Test</b><a href=\"http://www.bla.com/xyz\">abcd</a><a href='http://www.xyz.com/123'>hello</a></body></html>" }, { "http://www.bla.com/blob", "<html><head></head><body><a href='http://www.bla.com/'>back</a><b>Test</b><a href='/'><a href=\"http://www.bla.com/xyz\">abcd</a><a href='http://www.bla.com/secure/'>hello</a></body></html>" }, { "http://www.bla.com/xyz", "<html><head></head><body><a href='http://www.bla.com/blob'>hello</a><b>Test</b><a href=\"http://www.bla.com/xyz\">abcd</a><a href='http://www.xyz.com/123'>hello</a></body></html>" }, { "http://www.bla.com/secure/", "<html><head></head><body><a href='http://www.xyz.com/123'>hello</a><a href='/xyz'>hello</a><a href='../xyz'>hello</a></body></html>" }, }; }
public void ExecuteTestHashMap() { List <string> hashes = new List <string>(); List <string> values = new List <string>(); const int size = 1000; Console.WriteLine("Small Tests..."); Assert.IsTrue(hashmap.Count == 0); hashmap.Add(new KeyValuePair <string, string>("key", "value")); Assert.IsTrue(hashmap.ContainsKey("key")); Assert.IsFalse(hashmap.ContainsKey("value")); Assert.IsTrue(hashmap["key"] == "value"); Assert.IsTrue(hashmap.Count == 1); hashmap.Validate(); hashmap.Add(new KeyValuePair <string, string>("key", "value2")); Assert.IsTrue(hashmap.ContainsKey("key")); Assert.IsFalse(hashmap.ContainsKey("value")); Assert.IsTrue(hashmap["key"] == "value2"); Assert.IsTrue(hashmap.Count == 1); hashmap.Validate(); hashmap.Add(new KeyValuePair <string, string>("key", "avalue")); Assert.IsTrue(hashmap.ContainsKey("key")); Assert.IsFalse(hashmap.ContainsKey("value")); Assert.IsTrue(hashmap["key"] == "avalue"); Assert.IsTrue(hashmap.Count == 1); hashmap.Validate(); Assert.IsFalse(hashmap.Remove("value")); Assert.IsTrue(hashmap.Remove("key")); hashmap.Validate(); Assert.IsTrue(hashmap.Count == 0); hashmap.Add(new KeyValuePair <string, string>("key", "value2")); Assert.IsTrue(hashmap.Count == 1); hashmap.Clear(); Assert.IsTrue(hashmap.Count == 0); hashmap.Add(new KeyValuePair <string, string>("key", "value")); Assert.IsTrue(hashmap.ContainsKey("key")); Assert.IsFalse(hashmap.ContainsKey("value")); Assert.IsTrue(hashmap["key"] == "value"); Assert.IsTrue(hashmap.Count == 1); hashmap.Validate(); hashmap.Clear(); Assert.IsFalse(hashmap.Remove("")); Assert.IsFalse(hashmap.Remove(new KeyValuePair <string, string>("", ""))); Console.WriteLine("Adding..."); for (int i = 0; i < size; i++) { Assert.IsTrue(hashmap.Count == i); hashes.Add(Hash.GetHash()); values.Add(Hash.GetHash()); hashmap[hashes[i]] = values[i]; Assert.IsTrue(hashmap[hashes[i]] == values[i]); Assert.IsTrue(hashmap.Keys.Contains(hashes[i])); Assert.IsTrue(hashmap.Values.Contains(values[i])); hashmap.Validate(); } Console.WriteLine("Overriding..."); for (int i = 0; i < size; i++) { Assert.IsTrue(hashmap[hashes[i]] == values[i]); values[i] = Hash.GetHash(); hashmap[hashes[i]] = values[i]; Assert.IsTrue(hashmap.Count == size); } Console.WriteLine("Checking..."); for (int i = 0; i < size; i++) { Assert.IsTrue(hashmap[hashes[i]] == values[i]); Assert.IsTrue(hashmap.Keys.Contains(hashes[i])); Assert.IsTrue(hashmap.Values.Contains(values[i])); } Console.WriteLine("Validating..."); hashmap.Validate(); Serializer.WriteXmlData(hashmap, nameof(hashmap)); hashmap = Serializer.ReadXmlData <AVLHashMap <string, string> >(nameof(hashmap)); hashmap.Validate(); Console.WriteLine("Deleting..."); for (int i = 0; i < size; i++) { Assert.IsTrue(hashmap.Count == size - i); Assert.IsTrue(hashmap.ContainsKey(hashes[i])); Assert.IsTrue(hashmap[hashes[i]] != default(string)); Assert.IsTrue(hashmap.Remove(hashes[i])); Assert.IsFalse(hashmap.Keys.Contains(hashes[i])); Assert.IsFalse(hashmap.Values.Contains(values[i])); if (true) { for (int j = i + 1; j < size; j++) { Assert.IsFalse(hashmap[hashes[j]].Contains(hashes[j])); } for (int j = 0; j < i; j++) { Assert.IsFalse(hashmap.Remove(hashes[j])); } } Assert.IsTrue(hashmap[hashes[i]] == default(string)); hashmap.Validate(); } Serializer.WriteXmlData(hashmap, nameof(hashmap)); hashmap = Serializer.ReadXmlData <AVLHashMap <string, string> >(nameof(hashmap)); hashmap.Validate(); }
public void TestSerializeClassAvlHashMap() { Console.WriteLine("Building Class AVLHashMap..."); AVLHashMap <Person, Couple> hashmap = new AVLHashMap <Person, Couple>(); int count = 1000; for (int i = 0; i < count; i++) { Person a = new Person() { age = i, name = "a" + i }; Person b = new Person() { age = i, name = "b" + i }; Couple c = new Couple() { man = a, woman = b }; hashmap.Add(a, c); hashmap.Add(b, c); } Console.WriteLine("Serializing..."); Serializer.WriteXmlData(hashmap, "hashmap"); Console.WriteLine("Deserializing..."); hashmap = Serializer.ReadXmlData <AVLHashMap <Person, Couple> >("hashmap"); Console.WriteLine("Validating..."); for (int i = 0; i < count; i++) { Assert.IsTrue(hashmap[new Person() { age = i, name = "a" + i }].woman.Equals(new Person() { age = i, name = "b" + i })); Assert.IsTrue(hashmap[new Person() { age = i, name = "b" + i }].woman.Equals(new Person() { age = i, name = "b" + i })); Assert.IsTrue(hashmap[new Person() { age = i, name = "a" + i }].man.Equals(new Person() { age = i, name = "a" + i })); Assert.IsTrue(hashmap[new Person() { age = i, name = "b" + i }].man.Equals(new Person() { age = i, name = "a" + i })); } }
/// <summary> /// Constructs a new WebCrawlerState object and initializes the internal collecions. /// </summary> public WebCrawlerState() { VisitedPages = new AVLHashMap <string, bool>(); ToGo = new List <string>(); }