public void TestDictionaryPlusGetTen() { DictionaryPlus<char, int> dictionary = new DictionaryPlus<char, int>(); for (int i = 0; i < 20; i++) { dictionary.Add((char)('a' + i), i); } CollectionAssert.AreEqual( new List<int>() { 6, 0, 2, 12, 4, 5, 7, 11, 1, 14 }, dictionary['g', 'a', 'c', 'm', 'e', 'f', 'h', 'l', 'b', 'o'].ToList()); }
public void TestDictionaryPlusGetTwo() { DictionaryPlus <int, string> dictionary = new DictionaryPlus <int, string>() { { 0, "zero" }, { 1, "one" }, { 2, "two" }, { 3, "three" } }; CollectionAssert.AreEqual(new List <string>() { "two", "zero" }, dictionary[2, 0].ToList()); }
public void TestDictionaryPlusGetInvalidKey() { DictionaryPlus <char, int> dictionary = new DictionaryPlus <char, int>(); for (int i = 0; i < 13; i++) { dictionary.Add((char)('a' + i), i); } CollectionAssert.AreEqual( new List <int>() { 6, 0, 2, 12, 4, 5, 7, 11, 1, 14 }, dictionary['g', 'a', 'c', 'm', 'e', 'f', 'h', 'l', 'b', 'o'].ToList()); }
public static DictionaryPlus<string, string> ArgsToDic(string[] args) { var dic = new DictionaryPlus<string, string>(); for (int i = 0; i < args.Length; i++) { if (i == 0 && args[0].ToLower().StartsWith("mapp")) { continue; } if (args[i] != "-h" && args[i] != "-help" && args[i] != "/?") { if (args[i].StartsWith("---")) { var endIndex = i + 1; var strToFindList = new List<string>(); while (true) { if (endIndex >= args.Length) { throw new ArgumentException("Something is wrong with the '---' argument you provided"); } if (args[endIndex] == "---") { dic[args[i]] = strToFindList.Aggregate((s1, s2) => s1 + " " + s2); i = endIndex; break; } strToFindList.Add(args[endIndex]); endIndex++; } } else if (args[i].StartsWith("--")) { dic[args[i]] = null; } else { dic[args[i]] = args[i + 1]; i++; } } } return dic; }
public static string DicToStr(DictionaryPlus<string, string> dic, string separator) { string str = ""; foreach (var key in dic.Keys) { if (!key.StartsWith("-") && key.CompareTo(" ") != 0) { continue; } str += separator + key; if (key.StartsWith("---")) { str += separator + dic[key] + separator + "---"; } else if (!key.StartsWith("--")) { if (dic[key].Contains("\\") && !dic[key].StartsWith("\"") && key.CompareTo(" ") != 0) { str += separator + "\"" + dic[key] + "\""; } else { str += separator + dic[key]; } } } return str; }
public static string DicToStr(DictionaryPlus<string, string> dic) { return DicToStr(dic, " "); }
public void TestDictionaryPlusGetTwo() { DictionaryPlus<int, string> dictionary = new DictionaryPlus<int, string>() { { 0, "zero" }, { 1, "one" }, { 2, "two" }, { 3, "three" } }; CollectionAssert.AreEqual(new List<string>() { "two", "zero" }, dictionary[2, 0].ToList()); }