📄 orderedmultidictionarytests.cs
字号:
}
[Test]
public void Contains()
{
OrderedMultiDictionary<string, int> dict1 = new OrderedMultiDictionary<string, int>(true);
dict1.Add("foo", 4);
dict1.Add(null, 7);
dict1.Add("bar", 11);
dict1.Add("foo", 7);
dict1.Add(null, 7);
dict1.Add("hello", 11);
dict1.Add("foo", 4);
Assert.IsTrue(dict1.Contains(null, 7));
Assert.IsTrue(dict1.Contains("foo", 4));
Assert.IsTrue(dict1.Contains("bar", 11));
Assert.IsTrue(dict1.Contains("hello", 11));
Assert.IsFalse(dict1.Contains("HELLO", 11));
Assert.IsFalse(dict1.Contains("bar", 12));
Assert.IsFalse(dict1.Contains("foo", 0));
dict1.Remove("hello", 11);
Assert.IsFalse(dict1.Contains("hello", 11));
dict1.Remove(null, 7);
Assert.IsTrue(dict1.Contains(null, 7));
dict1.Remove(null, 7);
Assert.IsFalse(dict1.Contains(null, 7));
}
[Test]
public void KeysCollection()
{
OrderedMultiDictionary<string, int> dict1 = new OrderedMultiDictionary<string, int>(false, StringComparer.InvariantCultureIgnoreCase);
dict1.Add("foo", 4);
dict1.Add(null, 2);
dict1.Add("bar", 3);
dict1.Add("sailor", 0);
dict1.Add("FOO", 9);
dict1.Add("b", 7);
dict1.Add("Foo", -1);
dict1.Add("BAR", 3);
dict1.Remove("b", 7);
InterfaceTests.TestReadonlyCollectionGeneric<string>(dict1.Keys, new string[] { null, "BAR", "Foo", "sailor" }, true, null);
Assert.IsTrue(dict1.Keys.Contains("foo"));
Assert.IsTrue(dict1.Keys.Contains("Foo"));
Assert.IsTrue(dict1.Keys.Contains(null));
Assert.IsTrue(dict1.Keys.Contains("Sailor"));
Assert.IsFalse(dict1.Keys.Contains("banana"));
OrderedMultiDictionary<string, int> dict2 = new OrderedMultiDictionary<string, int>(false, StringComparer.InvariantCultureIgnoreCase);
InterfaceTests.TestEnumerableElements(dict2.Keys, new string[] { });
}
[Test]
public void ValuesCollection1()
{
OrderedMultiDictionary<double, string> dict = new OrderedMultiDictionary<double, string>(false, Comparer<double>.Default, StringComparer.InvariantCultureIgnoreCase);
dict.Add(7, "Gizzle");
dict.Add(4, "foo");
dict.Add(6, "Foo");
dict.Add(3, "FOO");
dict.Add(3, "baz");
dict.Add(3, "bar");
dict.Add(4, "FOo");
dict.Add(3, "BAZ");
dict.Add(5, "bAZ");
dict.Add(7, "hello");
dict.Add(7, "foo");
ICollection<string> vals = dict.Values;
string[] expected = {
"bar", "BAZ", "FOO", "FOo", "bAZ", "Foo", "foo", "Gizzle", "hello"};
InterfaceTests.TestReadonlyCollectionGeneric<string>(vals, expected, true, null);
Assert.IsTrue(vals.Contains("gizzle"));
Assert.IsTrue(vals.Contains("FOO"));
Assert.IsTrue(vals.Contains("fOO"));
Assert.IsTrue(vals.Contains("hello"));
Assert.IsTrue(vals.Contains("bar"));
Assert.IsTrue(vals.Contains("BAR"));
Assert.IsFalse(vals.Contains("qatar"));
}
[Test]
public void ValuesCollection2()
{
OrderedMultiDictionary<double, string> dict = new OrderedMultiDictionary<double, string>(true, Comparer<double>.Default, StringComparer.InvariantCultureIgnoreCase);
dict.Add(7, "Gizzle");
dict.Add(4, "foo");
dict.Add(6, "Foo");
dict.Add(3, "FOO");
dict.Add(3, "baz");
dict.Add(3, "bar");
dict.Add(4, "FOo");
dict.Add(3, "BAZ");
dict.Add(5, "bAZ");
dict.Add(7, "hello");
dict.Add(7, "foo");
ICollection<string> vals = dict.Values;
string[] expected = {
"bar", "baz", "BAZ", "FOO", "foo", "FOo", "bAZ", "Foo", "foo", "Gizzle", "hello"};
InterfaceTests.TestReadonlyCollectionGeneric<string>(vals, expected, true, null);
Assert.IsTrue(vals.Contains("gizzle"));
Assert.IsTrue(vals.Contains("FOO"));
Assert.IsTrue(vals.Contains("fOO"));
Assert.IsTrue(vals.Contains("hello"));
Assert.IsTrue(vals.Contains("bar"));
Assert.IsTrue(vals.Contains("BAR"));
Assert.IsFalse(vals.Contains("qatar"));
}
[Test]
public void KeyValuesCollection1()
{
OrderedMultiDictionary<string, string> dict = new OrderedMultiDictionary<string, string>(false, StringComparer.InvariantCultureIgnoreCase, StringComparer.InvariantCultureIgnoreCase);
dict.Add("7A", "Gizzle");
dict.Add("4a", "foo");
dict.Add("6A", "Foo");
dict.Add("3a", "FOO");
dict.Add("3A", "baz");
dict.Add("3a", "bar");
dict.Add("4a", "FOo");
dict.Add("3A", "BAZ");
dict.Add("5a", "bAZ");
dict.Add("7a", "hello");
dict.Add("7A", "foo");
ICollection<KeyValuePair<string,string>> pairs = dict.KeyValuePairs;
string[] expectedKeys = {
"3a", "3A", "3a", "4a", "5a", "6A", "7A", "7A", "7a"};
string[] expectedVals = {
"bar", "BAZ", "FOO", "FOo", "bAZ", "Foo", "foo", "Gizzle", "hello"};
KeyValuePair<string, string>[] expectedPairs = new KeyValuePair<string, string>[expectedKeys.Length];
for (int i = 0; i < expectedKeys.Length; ++i)
expectedPairs[i] = new KeyValuePair<string, string>(expectedKeys[i], expectedVals[i]);
InterfaceTests.TestReadonlyCollectionGeneric<KeyValuePair<string,string>>(pairs, expectedPairs, true, null);
Assert.IsTrue(pairs.Contains(new KeyValuePair<string,string>("3a", "baz")));
Assert.IsTrue(pairs.Contains(new KeyValuePair<string,string>("3A", "baz")));
Assert.IsTrue(pairs.Contains(new KeyValuePair<string, string>("6a", "foo")));
Assert.IsFalse(pairs.Contains(new KeyValuePair<string, string>("7A", "bar")));
}
[Test]
public void KeyValuesCollection2()
{
OrderedMultiDictionary<string, string> dict = new OrderedMultiDictionary<string, string>(true, StringComparer.InvariantCultureIgnoreCase, StringComparer.InvariantCultureIgnoreCase);
dict.Add("7A", "Gizzle");
dict.Add("4A", "foo");
dict.Add("6A", "Foo");
dict.Add("3a", "FOO");
dict.Add("3A", "baz");
dict.Add("3a", "bar");
dict.Add("4a", "FOo");
dict.Add("3a", "BAZ");
dict.Add("5a", "bAZ");
dict.Add("7a", "hello");
dict.Add("7A", "foo");
ICollection<KeyValuePair<string, string>> pairs = dict.KeyValuePairs;
string[] expectedKeys = {
"3a", "3A", "3a", "3a", "4A", "4a", "5a", "6A", "7A", "7A", "7a"};
string[] expectedVals = {
"bar", "baz", "BAZ", "FOO", "foo", "FOo", "bAZ", "Foo", "foo", "Gizzle", "hello"};
KeyValuePair<string, string>[] expectedPairs = new KeyValuePair<string, string>[expectedKeys.Length];
for (int i = 0; i < expectedKeys.Length; ++i)
expectedPairs[i] = new KeyValuePair<string, string>(expectedKeys[i], expectedVals[i]);
InterfaceTests.TestReadonlyCollectionGeneric<KeyValuePair<string, string>>(pairs, expectedPairs, true, null);
Assert.IsTrue(pairs.Contains(new KeyValuePair<string, string>("3a", "baz")));
Assert.IsTrue(pairs.Contains(new KeyValuePair<string, string>("3A", "baz")));
Assert.IsTrue(pairs.Contains(new KeyValuePair<string, string>("6a", "foo")));
Assert.IsFalse(pairs.Contains(new KeyValuePair<string, string>("7A", "bar")));
}
[Test]
public void Indexer()
{
OrderedMultiDictionary<string, string> dict1 = new OrderedMultiDictionary<string, string>(true, StringComparer.InvariantCultureIgnoreCase, StringComparer.InvariantCultureIgnoreCase);
dict1.Add("foo", "BAR");
dict1.Add(null, "hello");
dict1.Add("Hello", "sailor");
dict1.Add(null, "hi");
dict1.Add("foo", "bar");
dict1.Add("HELLO", null);
dict1.Add("foo", "a");
dict1.Add("Foo", "A");
dict1.Add("trail", "mix");
InterfaceTests.TestEnumerableElements(dict1[null], new string[] { "hello", "hi" });
InterfaceTests.TestEnumerableElements(dict1["hELLo"], new string[] { null, "sailor" });
InterfaceTests.TestEnumerableElements(dict1["foo"], new string[] { "a", "A", "BAR", "bar" });
InterfaceTests.TestEnumerableElements(dict1["trail"], new string[] { "mix" });
InterfaceTests.TestEnumerableElements(dict1["nothing"], new string[] { });
}
[Test]
public void GetValueCount()
{
OrderedMultiDictionary<string, string> dict1 = new OrderedMultiDictionary<string, string>(true, StringComparer.InvariantCultureIgnoreCase, StringComparer.InvariantCultureIgnoreCase);
dict1.Add("foo", "BAR");
dict1.Add(null, "hello");
dict1.Add("Hello", "sailor");
dict1.Add(null, "hi");
dict1.Add("foo", "bar");
dict1.Add("HELLO", null);
dict1.Add("foo", "a");
dict1.Add("Foo", "A");
dict1.Add("hello", null);
dict1.Add("trail", "mix");
Assert.AreEqual(2, dict1[null].Count);
Assert.AreEqual(3, dict1["hELLo"].Count);
Assert.AreEqual(4, dict1["foo"].Count);
Assert.AreEqual(1, dict1["trail"].Count);
Assert.AreEqual(0, dict1["nothing"].Count);
dict1 = new OrderedMultiDictionary<string, string>(false, StringComparer.InvariantCultureIgnoreCase, StringComparer.InvariantCultureIgnoreCase);
dict1.Add("foo", "BAR");
dict1.Add(null, "hello");
dict1.Add("Hello", "sailor");
dict1.Add(null, "hi");
dict1.Add("foo", "bar");
dict1.Add("HELLO", null);
dict1.Add("foo", "a");
dict1.Add("Foo", "A");
dict1.Add("hello", null);
dict1.Add("trail", "mix");
Assert.AreEqual(2, dict1[null].Count);
Assert.AreEqual(2, dict1["hELLo"].Count);
Assert.AreEqual(2, dict1["foo"].Count);
Assert.AreEqual(1, dict1["trail"].Count);
Assert.AreEqual(0, dict1["nothing"].Count);
}
[Test]
public void IMultiDictionaryInterface()
{
OrderedMultiDictionary<string, string> dict1 = new OrderedMultiDictionary<string, string>(true);
dict1.Add("foo", "bar");
dict1.Add(null, "hello");
dict1.Add("hello", "sailor");
dict1.Add(null, "hi");
dict1.Add("foo", "bar");
dict1.Add("hello", null);
dict1.Add("foo", "a");
dict1.Add("foo", "a");
dict1.Add("hello", null);
dict1.Add("trail", "mix");
CheckOrderedMultiDictionaryContents<string, string>(dict1,
new string[] { null, "foo", "hello", "trail" },
new string[][] { new string[] { "hello", "hi" }, new string[] { "a", "a", "bar", "bar" }, new string[] { null, null, "sailor" }, new string[] { "mix" } },
"zippy", "pinhead", null, null);
dict1 = new OrderedMultiDictionary<string, string>(false);
dict1.Add("foo", "bar");
dict1.Add(null, "hello");
dict1.Add("hello", "sailor");
dict1.Add(null, "hi");
dict1.Add("foo", "bar");
dict1.Add("hello", null);
dict1.Add("foo", "a");
dict1.Add("foo", "a");
dict1.Add("hello", null);
dict1.Add("trail", "mix");
CheckOrderedMultiDictionaryContents<string, string>(dict1,
new string[] { null, "foo", "hello", "trail" },
new string[][] { new string[] { "hello", "hi" }, new string[] { "a", "bar" }, new string[] { null, "sailor" }, new string[] { "mix" } },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -