本文整理汇总了C#中System.Collections.Specialized.HybridDictionary.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# HybridDictionary.Clear方法的具体用法?C# HybridDictionary.Clear怎么用?C# HybridDictionary.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.HybridDictionary
的用法示例。
在下文中一共展示了HybridDictionary.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: All
public void All ()
{
HybridDictionary dict = new HybridDictionary (true);
dict.Add ("CCC", "ccc");
dict.Add ("BBB", "bbb");
dict.Add ("fff", "fff");
dict ["EEE"] = "eee";
dict ["ddd"] = "ddd";
Assert.AreEqual (5, dict.Count, "#1");
Assert.AreEqual ("eee", dict["eee"], "#2");
dict.Add ("CCC2", "ccc");
dict.Add ("BBB2", "bbb");
dict.Add ("fff2", "fff");
dict ["EEE2"] = "eee";
dict ["ddd2"] = "ddd";
dict ["xxx"] = "xxx";
dict ["yyy"] = "yyy";
Assert.AreEqual (12, dict.Count, "#3");
Assert.AreEqual ("eee", dict["eee"], "#4");
dict.Remove ("eee");
Assert.AreEqual (11, dict.Count, "Removed/Count");
Assert.IsFalse (dict.Contains ("eee"), "Removed/Contains(xxx)");
DictionaryEntry[] entries = new DictionaryEntry [11];
dict.CopyTo (entries, 0);
Assert.IsTrue (dict.Contains ("xxx"), "Contains(xxx)");
dict.Clear ();
Assert.AreEqual (0, dict.Count, "Cleared/Count");
Assert.IsFalse (dict.Contains ("xxx"), "Cleared/Contains(xxx)");
}
示例2: Test01
public void Test01()
{
HybridDictionary hd;
const int BIG_LENGTH = 100;
// simple string values
string[] valuesShort =
{
"",
" ",
"$%^#",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
// keys for simple string values
string[] keysShort =
{
Int32.MaxValue.ToString(),
" ",
System.DateTime.Today.ToString(),
"",
"$%^#"
};
string[] valuesLong = new string[BIG_LENGTH];
string[] keysLong = new string[BIG_LENGTH];
int cnt = 0; // Count
for (int i = 0; i < BIG_LENGTH; i++)
{
valuesLong[i] = "Item" + i;
keysLong[i] = "keY" + i;
}
// [] HybridDictionary is constructed as expected
//-----------------------------------------------------------------
hd = new HybridDictionary();
cnt = hd.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1} after default ctor", hd.Count, 0));
}
//
// [] Clear empty dictionary and check Count
//
hd.Clear();
cnt = hd.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1} after Clear()", hd.Count, 0));
}
cnt = hd.Keys.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, Keys.Count is {0} instead of {1} after Clear()", cnt, 0));
}
cnt = hd.Values.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, Values.Count is {0} instead of {1} after Clear()", cnt, 0));
}
// [] Add simple strings (list) - Count - Clear() - Count
//
cnt = hd.Count;
for (int i = 0; i < valuesShort.Length; i++)
{
hd.Add(keysShort[i], valuesShort[i]);
}
if (hd.Count != valuesShort.Length)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length));
}
hd.Clear();
cnt = hd.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1} after Clear()", hd.Count, 0));
}
cnt = hd.Keys.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, Keys.Count is {0} instead of {1} after Clear()", cnt, 0));
}
cnt = hd.Values.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, Values.Count is {0} instead of {1} after Clear()", cnt, 0));
}
// Hashtable
// [] Add simple strings (hashtable) - Count - Clear() - Count
//.........这里部分代码省略.........
示例3: Test01
public void Test01()
{
IntlStrings intl;
HybridDictionary hd;
const int BIG_LENGTH = 100;
// simple string values
string[] valuesShort =
{
"",
" ",
"$%^#",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
// keys for simple string values
string[] keysShort =
{
Int32.MaxValue.ToString(),
" ",
System.DateTime.Today.ToString(),
"",
"$%^#"
};
string[] valuesLong = new string[BIG_LENGTH];
string[] keysLong = new string[BIG_LENGTH];
int cnt = 0; // Count
Object itm; // Item
// initialize IntStrings
intl = new IntlStrings();
for (int i = 0; i < BIG_LENGTH; i++)
{
valuesLong[i] = "Item" + i;
keysLong[i] = "keY" + i;
}
// [] HybridDictionary is constructed as expected
//-----------------------------------------------------------------
hd = new HybridDictionary();
// [] set Item() on empty dictionary
//
cnt = hd.Count;
try
{
hd[null] = valuesShort[0];
Assert.False(true, string.Format("Error, no exception"));
}
catch (ArgumentNullException)
{
}
catch (Exception e)
{
Assert.False(true, string.Format("Error, unexpected exception: {0}", e.ToString()));
}
cnt = hd.Count;
hd["some_string"] = valuesShort[0];
if (hd.Count != cnt + 1)
{
Assert.False(true, string.Format("Error, failed to add Item(some_string)"));
}
itm = hd["some_string"];
if (String.Compare(itm.ToString(), valuesShort[0]) != 0)
{
Assert.False(true, string.Format("Error, added wrong Item(some_string)"));
}
cnt = hd.Count;
Hashtable l = new Hashtable();
ArrayList bb = new ArrayList();
hd[l] = bb;
if (hd.Count != cnt + 1)
{
Assert.False(true, string.Format("Error, failed to add Item(some_object)"));
}
itm = hd[l];
if (!itm.Equals(bb))
{
Assert.False(true, string.Format("Error, returned wrong Item(some_object)"));
}
// [] set Item() on short dictionary with simple strings
//
hd.Clear();
cnt = hd.Count;
int len = valuesShort.Length;
for (int i = 0; i < len; i++)
{
hd.Add(keysShort[i], valuesShort[i]);
//.........这里部分代码省略.........
示例4: Test01
//.........这里部分代码省略.........
//
Assert.Throws<InvalidOperationException>(() => { de = en.Entry; });
//
// Attempt to get Key should result in exception
//
Assert.Throws<InvalidOperationException>(() => { k = en.Key; });
//
// Attempt to get Value should result in exception
//
Assert.Throws<InvalidOperationException>(() => { v = en.Value; });
en.Reset();
//
// Attempt to get Current should result in exception
//
Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; });
//
// Attempt to get Entry should result in exception
//
Assert.Throws<InvalidOperationException>(() => { de = en.Entry; });
//=========================================================
// --------------------------------------------------------
//
// Modify dictionary when enumerating
//
// [] Enumerator and short modified HD (list)
//
hd.Clear();
if (hd.Count < 1)
{
for (int i = 0; i < valuesShort.Length; i++)
{
hd.Add(keysShort[i], valuesShort[i]);
}
}
en = hd.GetEnumerator();
res = en.MoveNext();
if (!res)
{
Assert.False(true, string.Format("Error, MoveNext returned false"));
}
curr = (DictionaryEntry)en.Current;
de = en.Entry;
k = en.Key;
v = en.Value;
int cnt = hd.Count;
hd.Remove(keysShort[0]);
if (hd.Count != cnt - 1)
{
Assert.False(true, string.Format("Error, didn't remove item with 0th key"));
}
// will return just removed item
DictionaryEntry curr2 = (DictionaryEntry)en.Current;
if (!curr.Equals(curr2))
{
Assert.False(true, string.Format("Error, current returned different value after modification"));
}
示例5: Test01
//.........这里部分代码省略.........
{
if (!hd.Contains(keysLong[i]))
{
Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, keysLong[i]));
}
}
// verify old keys
for (int i = 0; i < valuesShort.Length; i++)
{
if (!hd.Contains(keysShort[i]))
{
Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, keysShort[i]));
}
}
//
// [] Intl strings and Contains()
//
string[] intlValues = new string[len * 2];
// fill array with unique strings
//
for (int i = 0; i < len * 2; i++)
{
string val = intl.GetRandomString(MAX_LEN);
while (Array.IndexOf(intlValues, val) != -1)
val = intl.GetRandomString(MAX_LEN);
intlValues[i] = val;
}
hd.Clear();
for (int i = 0; i < len; i++)
{
hd.Add(intlValues[i + len], intlValues[i]);
}
if (hd.Count != (len))
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
}
for (int i = 0; i < len; i++)
{
//
if (!hd.Contains(intlValues[i + len]))
{
Assert.False(true, string.Format("Error, doesn't contain \"{1}\"", i, intlValues[i + len]));
}
}
//
// [] Case sensitivity
// by default HybridDictionary is case-sensitive
//
hd.Clear();
len = valuesLong.Length;
//
// will use first half of array as valuesShort and second half as keysShort
//
for (int i = 0; i < len; i++)
{
示例6: RemoveFromMap
/// <summary>
/// Removes from map.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="handleGameItem">if set to <c>true</c> [handle game item].</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
internal bool RemoveFromMap(RoomItem item, bool handleGameItem)
{
RemoveSpecialItem(item);
if (_room.GotSoccer())
_room.GetSoccer().OnGateRemove(item);
bool result = false;
foreach (Point current in item.GetCoords.Where(current => RemoveCoordinatedItem(item, current)))
result = true;
HybridDictionary hybridDictionary = new HybridDictionary();
foreach (Point current2 in item.GetCoords)
{
int point = CoordinatesFormatter.PointToInt(current2);
if (CoordinatedItems.Contains(point))
{
List<RoomItem> value = (List<RoomItem>) CoordinatedItems[point];
if (!hybridDictionary.Contains(current2))
hybridDictionary.Add(current2, value);
}
SetDefaultValue(current2.X, current2.Y);
}
foreach (Point point2 in hybridDictionary.Keys)
{
List<RoomItem> list = (List<RoomItem>) hybridDictionary[point2];
foreach (RoomItem current3 in list)
ConstructMapForItem(current3, point2);
}
if (GuildGates.ContainsKey(item.Coordinate))
GuildGates.Remove(item.Coordinate);
_room.GetRoomItemHandler().OnHeightMapUpdate(hybridDictionary.Keys);
hybridDictionary.Clear();
return result;
}
示例7: Test01
public void Test01()
{
HybridDictionary hd;
const int BIG_LENGTH = 100;
string[] valuesLong = new string[BIG_LENGTH];
string[] keysLong = new string[BIG_LENGTH];
int len;
for (int i = 0; i < BIG_LENGTH; i++)
{
valuesLong[i] = "Item" + i;
keysLong[i] = "keY" + i;
}
// [] HybridDictionary is constructed as expected
//-----------------------------------------------------------------
hd = new HybridDictionary();
if (hd == null)
{
Assert.False(true, string.Format("Error, dictionary is null after default ctor"));
}
if (hd.Count != 0)
{
Assert.False(true, string.Format("Error, Count = {0} after default ctor", hd.Count));
}
if (hd["key"] != null)
{
Assert.False(true, string.Format("Error, Item(some_key) returned non-null after default ctor"));
}
System.Collections.ICollection keys = hd.Keys;
if (keys.Count != 0)
{
Assert.False(true, string.Format("Error, Keys contains {0} keys after default ctor", keys.Count));
}
System.Collections.ICollection values = hd.Values;
if (values.Count != 0)
{
Assert.False(true, string.Format("Error, Values contains {0} items after default ctor", values.Count));
}
//
// [] Add(string, string)
//
hd.Add("Name", "Value");
if (hd.Count != 1)
{
Assert.False(true, string.Format("Error, Count returned {0} instead of 1", hd.Count));
}
if (String.Compare(hd["Name"].ToString(), "Value") != 0)
{
Assert.False(true, string.Format("Error, Item() returned unexpected value"));
}
// by default should be case sensitive
if (hd["NAME"] != null)
{
Assert.False(true, string.Format("Error, Item() returned non-null value for uppercase key"));
}
//
// [] Clear()
//
hd.Clear();
if (hd.Count != 0)
{
Assert.False(true, string.Format("Error, Count returned {0} instead of 0 after Clear()", hd.Count));
}
if (hd["Name"] != null)
{
Assert.False(true, string.Format("Error, Item() returned non-null value after Clear()"));
}
//
// [] numerous Add(string, string)
//
len = valuesLong.Length;
hd.Clear();
for (int i = 0; i < len; i++)
{
hd.Add(keysLong[i], valuesLong[i]);
}
if (hd.Count != len)
{
Assert.False(true, string.Format("Error, Count returned {0} instead of {1}", hd.Count, len));
}
for (int i = 0; i < len; i++)
{
if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i]) != 0)
{
Assert.False(true, string.Format("Error, Item() returned unexpected value", i));
}
if (hd[keysLong[i].ToUpper()] != null)
//.........这里部分代码省略.........
示例8: AllTopicsForNewsletter
// Updated 2004-01-29 by CraigAndera
public IEnumerable AllTopicsForNewsletter(AbsoluteTopicName newsletter)
{
// HybridDictionary switches between using a ListDictionary and a Hashtable
// depending on the size of the collection - should be a good choice since we don't
// know how big the collection of topic names will be
HybridDictionary answer = new HybridDictionary();
ContentBase cb = ContentBaseForNewsletter(newsletter);
foreach (string s in TheFederation.GetTopicListPropertyValue(newsletter, "Topics"))
{
// If the wildcard appears, ignore all the other topics listed - include every topic
if (s == "*")
{
answer.Clear();
foreach (AbsoluteTopicName atn in cb.AllTopics(false))
{
answer.Add(atn.Fullname, atn);
}
// No need to continue iterating after we find the wildcard
break;
}
else
{
RelativeTopicName rel = new RelativeTopicName(s);
foreach (AbsoluteTopicName atn in cb.AllAbsoluteTopicNamesThatExist(rel))
{
answer.Add(atn.Fullname, atn);
}
}
}
// Now we need to remove any topics that appear in the Exclude field
foreach (string s in TheFederation.GetTopicListPropertyValue(newsletter, "Exclude"))
{
RelativeTopicName rel = new RelativeTopicName(s);
foreach (AbsoluteTopicName atn in cb.AllAbsoluteTopicNamesThatExist(rel))
{
answer.Remove(atn.Fullname);
}
}
// Do the same for "Excludes", since it's hard to remember which one to use
foreach (string s in TheFederation.GetTopicListPropertyValue(newsletter, "Excludes"))
{
RelativeTopicName rel = new RelativeTopicName(s);
foreach (AbsoluteTopicName atn in cb.AllAbsoluteTopicNamesThatExist(rel))
{
answer.Remove(atn.Fullname);
}
}
return answer.Values;
}
示例9: Test01
public void Test01()
{
IntlStrings intl;
HybridDictionary hd;
const int BIG_LENGTH = 100;
// simple string values
string[] valuesShort =
{
"",
" ",
"$%^#",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
// keys for simple string values
string[] keysShort =
{
Int32.MaxValue.ToString(),
" ",
System.DateTime.Today.ToString(),
"",
"$%^#"
};
string[] valuesLong = new string[BIG_LENGTH];
string[] keysLong = new string[BIG_LENGTH];
int cnt = 0; // Count
// initialize IntStrings
intl = new IntlStrings();
for (int i = 0; i < BIG_LENGTH; i++)
{
valuesLong[i] = "Item" + i;
keysLong[i] = "keY" + i;
}
// [] HybridDictionary is constructed as expected
//-----------------------------------------------------------------
hd = new HybridDictionary();
cnt = hd.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1} after default ctor", hd.Count, 0));
}
// [] Clear() on empty dictionary
//
hd.Clear();
cnt = hd.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1} after Clear()", hd.Count, 0));
}
cnt = hd.Keys.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, Keys.Count is {0} instead of {1} after Clear()", cnt, 0));
}
cnt = hd.Values.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, Values.Count is {0} instead of {1} after Clear()", cnt, 0));
}
// [] Add simple strings and Clear()
//
cnt = hd.Count;
for (int i = 0; i < valuesShort.Length; i++)
{
hd.Add(keysShort[i], valuesShort[i]);
}
if (hd.Count != valuesShort.Length)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length));
}
hd.Clear();
cnt = hd.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1} after Clear()", hd.Count, 0));
}
cnt = hd.Keys.Count;
if (cnt != 0)
{
Assert.False(true, string.Format("Error, Keys.Count is {0} instead of {1} after Clear()", cnt, 0));
}
cnt = hd.Values.Count;
if (cnt != 0)
//.........这里部分代码省略.........
示例10: Test01
public void Test01()
{
HybridDictionary hd;
const int BIG_LENGTH = 100;
string[] valuesLong = new string[BIG_LENGTH];
string[] keysLong = new string[BIG_LENGTH];
int len;
for (int i = 0; i < BIG_LENGTH; i++)
{
valuesLong[i] = "Item" + i;
keysLong[i] = "keY" + i;
}
// [] HybridDictionary is constructed as expected
//-----------------------------------------------------------------
// [] Capacity 0, Case-sensitive ctor
hd = new HybridDictionary(0, false);
if (hd == null)
{
Assert.False(true, string.Format("Error, dictionary is null after default ctor"));
}
if (hd.Count != 0)
{
Assert.False(true, string.Format("Error, Count = {0} after default ctor", hd.Count));
}
if (hd["key"] != null)
{
Assert.False(true, string.Format("Error, Item(some_key) returned non-null after default ctor"));
}
//
// [] Add(string, string)
//
// should be able to add keys that differ only in casing
hd.Add("Name", "Value");
if (hd.Count != 1)
{
Assert.False(true, string.Format("Error, Count returned {0} instead of 1", hd.Count));
}
if (String.Compare(hd["Name"].ToString(), "Value") != 0)
{
Assert.False(true, string.Format("Error, Item() returned unexpected value"));
}
hd.Add("NaMe", "Value");
if (hd.Count != 2)
{
Assert.False(true, string.Format("Error, Count returned {0} instead of 2", hd.Count));
}
if (String.Compare(hd["NaMe"].ToString(), "Value") != 0)
{
Assert.False(true, string.Format("Error, Item() returned unexpected value"));
}
// by default should be case sensitive
if (hd["NAME"] != null)
{
Assert.False(true, string.Format("Error, Item() returned non-null value for uppercase key"));
}
//
// [] Clear() short dictionary
//
hd.Clear();
if (hd.Count != 0)
{
Assert.False(true, string.Format("Error, Count returned {0} instead of 0 after Clear()", hd.Count));
}
if (hd["Name"] != null)
{
Assert.False(true, string.Format("Error, Item() returned non-null value after Clear()"));
}
//
// [] numerous Add(string, string)
//
len = valuesLong.Length;
hd.Clear();
for (int i = 0; i < len; i++)
{
hd.Add(keysLong[i], valuesLong[i]);
}
if (hd.Count != len)
{
Assert.False(true, string.Format("Error, Count returned {0} instead of {1}", hd.Count, len));
}
for (int i = 0; i < len; i++)
{
if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i]) != 0)
{
Assert.False(true, string.Format("Error, Item() returned unexpected value", i));
}
if (hd[keysLong[i].ToUpper()] != null)
{
//.........这里部分代码省略.........
示例11: Test01
public void Test01()
{
IntlStrings intl;
HybridDictionary hd;
const int BIG_LENGTH = 100;
// simple string values
string[] valuesShort =
{
"",
" ",
"$%^#",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
// keys for simple string values
string[] keysShort =
{
Int32.MaxValue.ToString(),
" ",
System.DateTime.Today.ToString(),
"",
"$%^#"
};
string[] valuesLong = new string[BIG_LENGTH];
string[] keysLong = new string[BIG_LENGTH];
int cnt = 0; // Count
Object itm; // Item
// initialize IntStrings
intl = new IntlStrings();
for (int i = 0; i < BIG_LENGTH; i++)
{
valuesLong[i] = "Item" + i;
keysLong[i] = "keY" + i;
}
// [] HybridDictionary is constructed as expected
//-----------------------------------------------------------------
hd = new HybridDictionary();
// [] get Item() on empty dictionary
//
cnt = hd.Count;
Assert.Throws<ArgumentNullException>(() => { itm = hd[null]; });
cnt = hd.Count;
itm = hd["some_string"];
if (itm != null)
{
Assert.False(true, string.Format("Error, returned non-null for Item(some_string)"));
}
cnt = hd.Count;
itm = hd[new Hashtable()];
if (itm != null)
{
Assert.False(true, string.Format("Error, returned non-null for Item(some_object)"));
}
// [] get Item() on short dictionary with simple strings
//
cnt = hd.Count;
int len = valuesShort.Length;
for (int i = 0; i < len; i++)
{
hd.Add(keysShort[i], valuesShort[i]);
}
if (hd.Count != len)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length));
}
//
for (int i = 0; i < len; i++)
{
cnt = hd.Count;
itm = hd[keysShort[i]];
if (String.Compare(itm.ToString(), valuesShort[i]) != 0)
{
Assert.False(true, string.Format("Error, returned wrong item", i));
}
}
// [] get Item() on long dictionary with simple strings
//
hd.Clear();
cnt = hd.Count;
len = valuesLong.Length;
for (int i = 0; i < len; i++)
{
//.........这里部分代码省略.........
示例12: Test01
public void Test01()
{
IntlStrings intl;
HybridDictionary hd;
const int BIG_LENGTH = 100;
// simple string values
string[] valuesShort =
{
"",
" ",
"$%^#",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
// keys for simple string values
string[] keysShort =
{
Int32.MaxValue.ToString(),
" ",
System.DateTime.Today.ToString(),
"",
"$%^#"
};
string[] valuesLong = new string[BIG_LENGTH];
string[] keysLong = new string[BIG_LENGTH];
int cnt = 0; // Count
// initialize IntStrings
intl = new IntlStrings();
for (int i = 0; i < BIG_LENGTH; i++)
{
valuesLong[i] = "Item" + i;
keysLong[i] = "keY" + i;
}
// [] HybridDictionary is constructed as expected
//-----------------------------------------------------------------
// [] simple strings
hd = new HybridDictionary();
for (int i = 0; i < valuesShort.Length; i++)
{
cnt = hd.Count;
hd.Add(keysShort[i], valuesShort[i]);
if (hd.Count != cnt + 1)
{
Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, hd.Count, cnt + 1));
}
// access the item
//
if (String.Compare(hd[keysShort[i]].ToString(), valuesShort[i]) != 0)
{
Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, hd[keysShort[i]], valuesShort[i]));
}
}
// increase the number of items
for (int i = 0; i < valuesLong.Length; i++)
{
cnt = hd.Count;
hd.Add(keysLong[i], valuesLong[i]);
if (hd.Count != cnt + 1)
{
Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, hd.Count, cnt + 1));
}
// access the item
//
if (String.Compare(hd[keysLong[i]].ToString(), valuesLong[i]) != 0)
{
Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, hd[keysLong[i]], valuesLong[i]));
}
}
//
// [] Intl strings
//
int len = valuesShort.Length;
hd.Clear();
string[] intlValues = new string[len * 2];
// fill array with unique strings
//
for (int i = 0; i < len * 2; i++)
{
string val = intl.GetRandomString(MAX_LEN);
while (Array.IndexOf(intlValues, val) != -1)
val = intl.GetRandomString(MAX_LEN);
intlValues[i] = val;
}
//.........这里部分代码省略.........
示例13: Test01
public void Test01()
{
IntlStrings intl;
HybridDictionary hd;
const int BIG_LENGTH = 100;
// simple string values
string[] valuesShort =
{
"",
" ",
"$%^#",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
// keys for simple string values
string[] keysShort =
{
Int32.MaxValue.ToString(),
" ",
System.DateTime.Today.ToString(),
"",
"$%^#"
};
string[] valuesLong = new string[BIG_LENGTH];
string[] keysLong = new string[BIG_LENGTH];
// string [] destination;
Array destination;
int cnt = 0; // Count
// initialize IntStrings
intl = new IntlStrings();
for (int i = 0; i < BIG_LENGTH; i++)
{
valuesLong[i] = "Item" + i;
keysLong[i] = "keY" + i;
}
// [] HybridDictionary is constructed as expected
//-----------------------------------------------------------------
hd = new HybridDictionary();
// [] Copy empty dictionary into empty array
//
destination = Array.CreateInstance(typeof(Object), 0);
Assert.Throws<ArgumentOutOfRangeException>(() => { hd.CopyTo(destination, -1); });
hd.CopyTo(destination, 0);
// exception even when copying empty dictionary
Assert.Throws<ArgumentException>(() => { hd.CopyTo(destination, 1); });
// [] Copy empty dictionary into filled array
//
destination = Array.CreateInstance(typeof(Object), valuesShort.Length);
for (int i = 0; i < valuesShort.Length; i++)
{
destination.SetValue(valuesShort[i], i);
}
hd.CopyTo(destination, 0);
if (destination.Length != valuesShort.Length)
{
Assert.False(true, string.Format("Error, altered array after copying empty dictionary"));
}
if (destination.Length == valuesShort.Length)
{
for (int i = 0; i < valuesShort.Length; i++)
{
if (String.Compare(destination.GetValue(i).ToString(), valuesShort[i]) != 0)
{
Assert.False(true, string.Format("Error, altered item {0} after copying empty dictionary", i));
}
}
}
// [] few simple strings and CopyTo(Array, 0)
//
hd.Clear();
cnt = hd.Count;
int len = valuesShort.Length;
for (int i = 0; i < len; i++)
{
hd.Add(keysShort[i], valuesShort[i]);
}
if (hd.Count != len)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length));
}
destination = Array.CreateInstance(typeof(Object), len);
hd.CopyTo(destination, 0);
//.........这里部分代码省略.........
示例14: RemoveFromMap
internal bool RemoveFromMap(RoomItem item, bool handleGameItem)
{
if (handleGameItem)
{
this.RemoveSpecialItem(item);
}
if (this.room.GotSoccer())
{
this.room.GetSoccer().onGateRemove(item);
}
bool result = false;
foreach (Point current in item.GetCoords)
{
if (this.RemoveCoordinatedItem(item, current))
{
result = true;
}
}
HybridDictionary HybridDictionary = new HybridDictionary();
foreach (Point current2 in item.GetCoords)
{
Point point = new Point(current2.X, current2.Y);
if (this.mCoordinatedItems.Contains(point))
{
List<RoomItem> value = (List<RoomItem>)this.mCoordinatedItems[point];
if (!HybridDictionary.Contains(current2))
{
HybridDictionary.Add(current2, value);
}
}
this.SetDefaultValue(current2.X, current2.Y);
}
foreach (Point point2 in HybridDictionary.Keys)
{
if (HybridDictionary.Contains(point2))
{
List<RoomItem> list = (List<RoomItem>)HybridDictionary[point2];
foreach (RoomItem current3 in list)
{
this.ConstructMapForItem(current3, point2);
}
}
}
room.GetRoomItemHandler().OnHeightmapUpdate(HybridDictionary.Keys);
HybridDictionary.Clear();
HybridDictionary = null;
return result;
}
示例15: Test01
public void Test01()
{
const int BIG_LENGTH = 100;
HybridDictionary hd;
// simple string values
string[] valuesShort =
{
"",
" ",
"$%^#",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
// keys for simple string values
string[] keysShort =
{
Int32.MaxValue.ToString(),
" ",
System.DateTime.Today.ToString(),
"",
"$%^#"
};
string[] valuesLong = new string[BIG_LENGTH];
string[] keysLong = new string[BIG_LENGTH];
Array arr;
ICollection vs; // Values collection
int ind;
for (int i = 0; i < BIG_LENGTH; i++)
{
valuesLong[i] = "Item" + i;
keysLong[i] = "keY" + i;
}
// [] HybridDictionary is constructed as expected
//-----------------------------------------------------------------
hd = new HybridDictionary();
// [] for empty dictionary
//
if (hd.Count > 0)
hd.Clear();
if (hd.Values.Count != 0)
{
Assert.False(true, string.Format("Error, returned Values.Count = {0}", hd.Values.Count));
}
// [] for short filled dictionary
//
int len = valuesShort.Length;
hd.Clear();
for (int i = 0; i < len; i++)
{
hd.Add(keysShort[i], valuesShort[i]);
}
if (hd.Count != len)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
}
vs = hd.Values;
if (vs.Count != len)
{
Assert.False(true, string.Format("Error, returned Values.Count = {0}", vs.Count));
}
arr = Array.CreateInstance(typeof(Object), len);
vs.CopyTo(arr, 0);
for (int i = 0; i < len; i++)
{
ind = Array.IndexOf(arr, valuesShort[i]);
if (ind < 0)
{
Assert.False(true, string.Format("Error, Values doesn't contain \"{1}\" value. Search result: {2}", i, valuesShort[i], ind));
}
}
// [] for long filled dictionary
//
len = valuesLong.Length;
hd.Clear();
for (int i = 0; i < len; i++)
{
hd.Add(keysLong[i], valuesLong[i]);
}
if (hd.Count != len)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
}
vs = hd.Values;
if (vs.Count != len)
{
//.........这里部分代码省略.........