📄 multidictionarybasetests.cs
字号:
public void Remove1()
{
ReadWriteTestMultiDictionary<string, int> dict = CreateTestReadWriteDictionary();
Assert.IsTrue(dict.Remove("Eric"));
Assert.IsTrue(dict.Remove("Rules"));
Assert.IsFalse(dict.Remove("Eric"));
Assert.IsFalse(dict.Remove("foo"));
Assert.IsTrue(dict.Remove("World", 8));
Assert.IsTrue(dict.Remove("The", 2));
Assert.IsTrue(dict.Remove("The", 6));
Assert.IsFalse(dict.Remove("The", 6));
Assert.IsFalse(dict.Remove("The", 11));
string[] s_array = new string[] { "Clapton", "The" };
int[][] i_array = new int[][] {
new int[] { 6, 10},
new int[] { 1, 3, 4, 5}};
CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
}
[Test]
public void Remove2()
{
ReadWriteTestMultiDictionary<string, int> dict = CreateTestReadWriteDictionary();
Assert.IsTrue(dict.Remove(new KeyValuePair<string, ICollection<int>>("Eric", new int[] {9, 1, 11})));
Assert.IsFalse(dict.Remove(new KeyValuePair<string, ICollection<int>>("Rules", new int[] { })));
Assert.IsTrue(dict.Remove(new KeyValuePair<string, ICollection<int>>("The", new int[] { 4, 2, 11 })));
Assert.IsFalse(dict.Remove(new KeyValuePair<string, ICollection<int>>("Clapton", new int[] { 0, 1 })));
Assert.IsFalse(dict.Remove(new KeyValuePair<string, ICollection<int>>("foo", new int[] { 0, 1 })));
string[] s_array = new string[] { "Clapton", "Rules", "The", "World" };
int[][] i_array = new int[][] {
new int[] { 6, 10},
new int[] { 4},
new int[] { 1, 3, 5, 6},
new int[] { 8}};
CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
}
[Test]
public void RemoveMany()
{
ReadWriteTestMultiDictionary<string, int> dict = CreateTestReadWriteDictionary();
Assert.AreEqual(3, dict.RemoveMany("Eric", new int[] { 9, 1, 11 }));
Assert.AreEqual(0, dict.RemoveMany("Rules", new int[] { }));
Assert.AreEqual(2, dict.RemoveMany("The", new int[] { 4, 2, 11 }));
Assert.AreEqual(0, dict.RemoveMany("Clapton", new int[] { 0, 1 }));
Assert.AreEqual(0, dict.RemoveMany("foo", new int[] { 0, 1 }));
string[] s_array = new string[] { "Clapton", "Rules", "The", "World" };
int[][] i_array = new int[][] {
new int[] { 6, 10},
new int[] { 4},
new int[] { 1, 3, 5, 6},
new int[] { 8}};
CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
}
[Test]
public void Replace()
{
ReadWriteTestMultiDictionary<string, int> dict = CreateTestReadWriteDictionary();
Assert.IsTrue(dict.Replace("Eric", 18));
Assert.IsTrue(dict.Replace("The", 7));
Assert.IsFalse(dict.Replace("Fizzle", 100));
string[] s_array = new string[] { "Clapton", "Rules", "World", "Eric", "The", "Fizzle" };
int[][] i_array = new int[][] {
new int[] { 6, 10},
new int[] { 4},
new int[] { 8},
new int[] {18},
new int[] {7},
new int[] {100}};
CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
}
[Test]
public void ReplaceMany()
{
ReadWriteTestMultiDictionary<string, int> dict = CreateTestReadWriteDictionary();
Assert.IsTrue(dict.ReplaceMany("Eric", new int[] { 18, 13, 33 }));
Assert.IsTrue(dict.ReplaceMany("The", new int[0]));
Assert.IsFalse(dict.ReplaceMany("Fizzle", new int[] { 100, 2 }));
string[] s_array = new string[] { "Clapton", "Rules", "World", "Eric", "Fizzle" };
int[][] i_array = new int[][] {
new int[] { 6, 10},
new int[] { 4},
new int[] { 8},
new int[] {18, 13, 33},
new int[] {100, 2}};
CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
}
[Test]
public void ValueCollection()
{
ReadWriteTestMultiDictionary<string, int> dict = CreateTestReadWriteDictionary();
ICollection<int> valueColl = dict["Eric"];
Assert.AreEqual(3, valueColl.Count);
valueColl.Add(19);
valueColl.Add(-4);
Assert.IsTrue(valueColl.Remove(1));
Assert.IsTrue(valueColl.Remove(19));
valueColl.Add(12);
string[] s_array = new string[] { "Eric", "Clapton", "Rules", "The", "World" };
int[][] i_array = new int[][] { new int[] { 9, 11, -4, 12 },
new int[] { 6, 10},
new int[] { 4},
new int[] { 1, 2, 3, 4, 5, 6},
new int[] { 8}};
CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
dict.Remove("Eric", 12);
dict.Add("Eric", 19);
InterfaceTests.TestReadWriteCollectionGeneric(valueColl, new int[] { 9, 11, -4, 19 }, true);
dict.Remove("Eric");
InterfaceTests.TestReadWriteCollectionGeneric(valueColl, new int[] { }, true);
InterfaceTests.TestReadWriteCollectionGeneric(dict["BananaZip"], new int[] { }, true);
dict["The"].Clear();
Assert.IsFalse(dict.ContainsKey("The"));
valueColl = dict["Foo"];
valueColl.Add(3);
valueColl.Add(4);
valueColl.Add(5);
s_array = new string[] { "Clapton", "Rules", "World", "Foo"};
i_array = new int[][] {
new int[] { 6, 10},
new int[] { 4},
new int[] { 8},
new int[] { 3, 4, 5}};
CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "fizzle", 113, null, null);
ICollection<int> valueColl2 = dict["Foo"];
Assert.IsFalse(object.ReferenceEquals(valueColl, valueColl2));
valueColl2.Add(11);
valueColl.Add(19);
Assert.IsTrue(Algorithms.EqualCollections(valueColl, valueColl2));
}
[Test]
public void ReadOnlyValueCollection()
{
ReadOnlyTestMultiDictionary<string, int> dict = CreateTestReadOnlyDictionary();
ICollection<int> valueColl = dict["Eric"];
InterfaceTests.TestReadonlyCollectionGeneric(valueColl, new int[] { 1, 9, 11 }, true, null);
}
[Test]
public void ConvertToString()
{
string[] s_array = { "Eric", "null", "Rules", "The", "World" };
int[][] i_array = { new int[] { 1, 9, 11 },
new int[] { 6, 10},
new int[] { 4},
new int[] { 1, 2, 3, 4, 5, 6},
new int[] { 8}};
List<string> s_list = new List<string>(s_array);
List<List<int>> i_list = new List<List<int>>();
foreach (int[] arr in i_array) {
i_list.Add(new List<int>(arr));
}
ReadWriteTestMultiDictionary<string, int> dict = new ReadWriteTestMultiDictionary<string, int>(s_list, i_list);
string s = dict.ToString();
Assert.AreEqual("{Eric->(1,9,11), null->(6,10), Rules->(4), The->(1,2,3,4,5,6), World->(8)}", s);
ReadOnlyTestMultiDictionary<string, int> dict2 = new ReadOnlyTestMultiDictionary<string, int>(s_list, i_list);
s = dict2.ToString();
Assert.AreEqual("{Eric->(1,9,11), null->(6,10), Rules->(4), The->(1,2,3,4,5,6), World->(8)}", s);
ReadOnlyTestMultiDictionary<string, int> dict3 = new ReadOnlyTestMultiDictionary<string, int>(new List<string>(), new List<List<int>>());
s = dict3.ToString();
Assert.AreEqual("{}", s);
}
[Test]
public void DebuggerDisplay()
{
string[] s_array = { "Eric", "null", "Rules", "The", "World" };
int[][] i_array = { new int[] { 1, 9, 11 },
new int[] { 6, 10},
new int[] { 4},
new int[] { 1, 2, 3, 4, 5, 6},
new int[] { 8}};
List<string> s_list = new List<string>(s_array);
List<List<int>> i_list = new List<List<int>>();
foreach (int[] arr in i_array) {
i_list.Add(new List<int>(arr));
}
ReadWriteTestMultiDictionary<string, int> dict = new ReadWriteTestMultiDictionary<string, int>(s_list, i_list);
string s = dict.DebuggerDisplayString();
Assert.AreEqual("{Eric->(1,9,11), null->(6,10), Rules->(4), The->(1,2,3,4,5,6), World->(8)}", s);
ReadOnlyTestMultiDictionary<string, int> dict2 = new ReadOnlyTestMultiDictionary<string, int>(s_list, i_list);
s = dict2.DebuggerDisplayString();
Assert.AreEqual("{Eric->(1,9,11), null->(6,10), Rules->(4), The->(1,2,3,4,5,6), World->(8)}", s);
ReadWriteTestMultiDictionary<string, int> dict3 = new ReadWriteTestMultiDictionary<string, int>(new List<string>(), new List<List<int>>());
s = dict3.DebuggerDisplayString();
Assert.AreEqual("{}", s);
ReadOnlyTestMultiDictionary<string, int> dict4 = new ReadOnlyTestMultiDictionary<string, int>(new List<string>(), new List<List<int>>());
s = dict4.DebuggerDisplayString();
Assert.AreEqual("{}", s);
ReadWriteTestMultiDictionary<string, int> dict5 = new ReadWriteTestMultiDictionary<string, int>(new List<string>(), new List<List<int>>());
for (int i = 0; i < 20; ++i) {
for (int j = 0; j < i; ++j) {
dict5.Add(string.Format("foo{0}bar", i), j);
}
}
s = dict5.DebuggerDisplayString();
Assert.AreEqual("{foo1bar->(0), foo2bar->(0,1), foo3bar->(0,1,2), foo4bar->(0,1,2,3), foo5bar->(0,1,2,3,4), foo6bar->(0,1,2,3,4,5), foo7bar->(0,1,2,3,4,5,6), foo8bar->(0,1,2,3,4,5,6,7), foo9bar->(0,1,2,3,4,5,6,7,8), foo10bar->(0,1,2,3,4,5,6,7,8,9), foo11bar->(0,1,2,3,4,5,6,7,8,9,10), ...}", s);
s_list = new List<string>(dict5.Keys);
i_list = new List<List<int>>();
foreach (string key in s_list)
i_list.Add(new List<int>(dict5[key]));
ReadOnlyTestMultiDictionary<string, int> dict6 = new ReadOnlyTestMultiDictionary<string, int>(s_list, i_list);
s = dict6.DebuggerDisplayString();
Assert.AreEqual("{foo1bar->(0), foo2bar->(0,1), foo3bar->(0,1,2), foo4bar->(0,1,2,3), foo5bar->(0,1,2,3,4), foo6bar->(0,1,2,3,4,5), foo7bar->(0,1,2,3,4,5,6), foo8bar->(0,1,2,3,4,5,6,7), foo9bar->(0,1,2,3,4,5,6,7,8), foo10bar->(0,1,2,3,4,5,6,7,8,9), foo11bar->(0,1,2,3,4,5,6,7,8,9,10), ...}", s);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -