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 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 UpdateTasks() { List <ProjectTask> _tasks = new List <ProjectTask>(); Files.Clear(); Repository repo = new Repository(Folder); string versionString = repo.Head.Tip.Id.Sha; var files = Directory.EnumerateFiles(Folder, "*", SearchOption.AllDirectories); foreach (string file in files) { bool anyContains = false; string fileName = file.Substring(Folder.Length); foreach (string ignored in IgnoredPaths) { if (fileName.Contains(ignored)) { anyContains = true; break; } } if (anyContains) { continue; } try { var lines = File.ReadAllLines(file); int line = 1; foreach (string l in lines) { if (l.Contains("// TODO: ")) { _tasks.Add(new ProjectTask(fileName, line, lines, versionString)); Files.Add(fileName, lines); } line++; } } catch (Exception e) { Logger.LogError($"Failed to read file '{file}' with error '{e.Message}'."); } } List <UsableProjectTask> usableTasks = (from t in _tasks select new UsableProjectTask(t)).ToList(); _tasks = null; Dictionary <ProjectTask, List <UsableProjectTask> > consumableTasks = new Dictionary <ProjectTask, List <UsableProjectTask> >(); Dictionary <ProjectTask, bool> matchedTasks = new Dictionary <ProjectTask, bool>(); foreach (var t in Tasks) { if (t.TaskState == ETaskState.Closed || t.TaskState == ETaskState.Resolved || t.TaskState == ETaskState.Dummy) { continue; } bool nothingMatched = true; for (int i = usableTasks.Count - 1; i >= 0; i--) { if (usableTasks[i].Task.Text == t.Text && usableTasks[i].Task.File == t.File) { if (!consumableTasks.ContainsKey(t)) { consumableTasks[t] = new List <UsableProjectTask>(); } usableTasks[i].LooselyMatched = true; consumableTasks[t].Add(usableTasks[i]); nothingMatched = false; } } if (nothingMatched) { t.Gone = versionString; t.TaskState = ETaskState.MaybeResolved; } } foreach (var ct in consumableTasks) { foreach (var t in ct.Value) { if (!t.Used && t.Task.Line == ct.Key.Line) { ct.Key.Consume(t.Task); matchedTasks.Add(ct.Key, true); t.Used = true; break; } else { var hunk = repo.Blame(t.Task.File, new BlameOptions() { StoppingAt = ct.Key.Version }).HunkForLine(t.Task.Line); if (hunk.InitialStartLineNumber <= ct.Key.Line && ct.Key.Line <= hunk.LineCount + hunk.InitialStartLineNumber) { ct.Key.Consume(t.Task); matchedTasks.Add(ct.Key, true); t.Used = true; break; } } } } foreach (var ct in consumableTasks) { if (matchedTasks.ContainsKey(ct.Key)) { continue; } consumableTasks[ct.Key] = (from c in ct.Value where !c.Used select c).ToList(); if (consumableTasks.Count == 1) { ct.Key.Consume(ct.Value[0].Task); matchedTasks.Add(ct.Key, true); ct.Value[0].Used = true; } else if (consumableTasks.Count > 1) { ct.Key.Gone = versionString; ct.Key.TaskState = ETaskState.MaybeResolved; } } foreach (var task in usableTasks) { if (!task.Used) { Tasks.Add(task.Task); } } SerializeProjects(); }