本文整理汇总了C#中ListDictionary.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# ListDictionary.Clear方法的具体用法?C# ListDictionary.Clear怎么用?C# ListDictionary.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListDictionary
的用法示例。
在下文中一共展示了ListDictionary.Clear方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
ListDictionary ld;
string [] values =
{
"",
" ",
"a",
"aA",
"text",
" SPaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
string [] keys =
{
"zero",
"oNe",
" ",
"",
"aa",
"1",
System.DateTime.Today.ToString(),
"$%^#",
Int32.MaxValue.ToString(),
" spaces",
"2222222222222222222222222"
};
int cnt = 0;
try
{
Console.WriteLine("--- create dictionary ---");
strLoc = "Loc_001_oo";
iCountTestcases++;
ld = new ListDictionary();
cnt = ld.Count;
if ( cnt != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001_, count is {0} instead of {1} after default ctor", ld.Count, 0);
}
Console.WriteLine("1. call Clear() on empty dictionary and check Count");
strLoc = "Loc_001oo";
iCountTestcases++;
ld.Clear();
cnt = ld.Count;
if ( cnt != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001a, count is {0} instead of {1} after Clear()", ld.Count, 0);
}
iCountTestcases++;
cnt = ld.Keys.Count;
if ( cnt != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001b, Keys.Count is {0} instead of {1} after Clear()", cnt, 0);
}
iCountTestcases++;
cnt = ld.Values.Count;
if ( cnt != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001c, Values.Count is {0} instead of {1} after Clear()", cnt, 0);
}
Console.WriteLine("2. add simple strings and get Count");
strLoc = "Loc_002oo";
iCountTestcases++;
cnt = ld.Count;
for (int i = 0; i < values.Length; i++)
{
ld.Add(keys[i], values[i]);
}
if (ld.Count != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, values.Length);
}
iCountTestcases++;
ld.Clear();
cnt = ld.Count;
if ( cnt != 0)
{
iCountErrors++;
Console.WriteLine("Err_0002b, count is {0} instead of {1} after Clear()", ld.Count, 0);
}
iCountTestcases++;
cnt = ld.Keys.Count;
if ( cnt != 0)
{
iCountErrors++;
Console.WriteLine("Err_0002c, Keys.Count is {0} instead of {1} after Clear()", cnt, 0);
}
//.........这里部分代码省略.........
示例2: ClearTest
public static void ClearTest(ListDictionary ld, KeyValuePair<string, string>[] data)
{
Assert.Equal(data.Length, ld.Count);
ld.Clear();
Assert.Equal(0, ld.Count);
ld.Add("key", "value");
Assert.Equal(1, ld.Count);
ld.Clear();
Assert.Equal(0, ld.Count);
}
示例3: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
ListDictionary ld;
string [] values =
{
"",
" ",
"a",
"aa",
"tExt",
" spAces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
string [] keys =
{
"zero",
"one",
" ",
"",
"aa",
"1",
System.DateTime.Today.ToString(),
"$%^#",
Int32.MaxValue.ToString(),
" spaces",
"2222222222222222222222222"
};
Array arr;
ICollection ks;
int ind;
try
{
intl = new IntlStrings();
Console.WriteLine("--- create dictionary ---");
strLoc = "Loc_001oo";
iCountTestcases++;
ld = new ListDictionary();
Console.WriteLine("1. get Keys for empty dictionary");
iCountTestcases++;
if (ld.Count > 0)
ld.Clear();
if (ld.Keys.Count != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001, returned Keys.Count = {0}", ld.Keys.Count);
}
Console.WriteLine("2. get Keys on filled dictionary");
strLoc = "Loc_002oo";
int len = values.Length;
iCountTestcases++;
ld.Clear();
for (int i = 0; i < len; i++)
{
ld.Add(keys[i], values[i]);
}
if (ld.Count != len)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, len);
}
ks = ld.Keys;
if (ks.Count != len)
{
iCountErrors++;
Console.WriteLine("Err_0002a, returned Keys.Count = {0}", ks.Count);
}
arr = Array.CreateInstance(typeof(Object), len);
ks.CopyTo(arr, 0);
for (int i = 0; i < len; i++)
{
iCountTestcases++;
ind = Array.IndexOf(arr, keys[i]);
if (ind < 0)
{
iCountErrors++;
Console.WriteLine("Err_0002b_{0}, Keys doesn't contain \"{1}\" key. Search result: {2}", i, keys[i], ind);
}
}
Console.WriteLine("3. get Keys on dictionary with different_in_casing_only values ");
strLoc = "Loc_003oo";
iCountTestcases++;
ld.Clear();
string intlStr = intl.GetString(MAX_LEN, true, true, true);
ld.Add("keykey", intlStr);
for (int i = 0; i < len; i++)
{
ld.Add(keys[i], values[i]);
}
ld.Add("keyKey", intlStr);
if (ld.Count != len+2)
{
//.........这里部分代码省略.........
示例4: runTest
//.........这里部分代码省略.........
ld.Add(intlValues[i+len], intlValues[i]);
}
if ( ld.Count != (cnt+len) )
{
iCountErrors++;
Console.WriteLine("Err_0003a, count is {0} instead of {1}", ld.Count, cnt+len);
}
for (int i = 0; i < len; i++)
{
iCountTestcases++;
if (! ld.Contains(intlValues[i+len]) )
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}b, doesn't contain key", i);
}
iCountTestcases++;
if (String.Compare(ld[intlValues[i+len]].ToString(), intlValues[i], false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}c, returned wrong value", i);
}
}
Console.WriteLine("4. case sensitivity");
strLoc = "Loc_004oo";
string [] intlValuesLower = new string [len * 2];
for (int i = 0; i < len * 2; i++)
{
intlValues[i] = intlValues[i].ToUpper();
}
for (int i = 0; i < len * 2; i++)
{
intlValuesLower[i] = intlValues[i].ToLower();
}
ld.Clear();
Console.WriteLine(" - add uppercase and access using uppercase");
for (int i = 0; i < len; i++)
{
ld.Add(intlValues[i+len], intlValues[i]);
}
for (int i = 0; i < len; i++)
{
iCountTestcases++;
if ( !ld.Contains( intlValues[i+len]) )
{
iCountErrors++;
Console.WriteLine("Err_0004_{0}b, doesn't contain key", i);
}
iCountTestcases++;
if (String.Compare(ld[intlValues[i+len]].ToString(), intlValues[i], false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0004_{0}c, returned wrong value", i);
}
}
ld.Clear();
Console.WriteLine(" - add uppercase but access using lowercase");
for (int i = 0; i < len; i++)
{
ld.Add(intlValues[i+len], intlValues[i]);
}
for (int i = 0; i < len; i++)
{
cnt = ld.Count;
iCountTestcases++;
if ( !caseInsensitive && ld[intlValuesLower[i+len]] != null )
{
示例5: runTest
//.........这里部分代码省略.........
}
Console.WriteLine("3. add simple strings and CopyTo(Array, 0)");
strLoc = "Loc_003oo";
iCountTestcases++;
cnt = ld.Count;
int len = values.Length;
for (int i = 0; i < len; i++)
{
ld.Add(keys[i], values[i]);
}
if (ld.Count != len)
{
iCountErrors++;
Console.WriteLine("Err_0003a, count is {0} instead of {1}", ld.Count, values.Length);
}
destination = Array.CreateInstance(typeof(Object), len);
ld.CopyTo(destination, 0);
for (int i = 0; i < len; i++)
{
iCountTestcases++;
if ( String.Compare(ld[keys[i]].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0 )
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), ld[keys[i]]);
}
iCountTestcases++;
if ( String.Compare(keys[i], ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0 )
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), keys[i]);
}
}
Console.WriteLine("4. add simple strings and CopyTo(Array, {0})", values.Length);
ld.Clear();
strLoc = "Loc_004oo";
iCountTestcases++;
for (int i = 0; i < len; i++)
{
ld.Add(keys[i], values[i]);
}
if (ld.Count != len)
{
iCountErrors++;
Console.WriteLine("Err_0004a, count is {0} instead of {1}", ld.Count, values.Length);
}
destination = Array.CreateInstance(typeof(Object), len*2);
ld.CopyTo(destination, len);
for (int i = 0; i < len; i++)
{
iCountTestcases++;
if ( String.Compare(ld[keys[i]].ToString(), ((DictionaryEntry)destination.GetValue(i+len)).Value.ToString(), false) != 0 )
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i+len)).Value, ld[keys[i]]);
}
iCountTestcases++;
if ( String.Compare(keys[i], ((DictionaryEntry)destination.GetValue(i+len)).Key.ToString(), false) != 0 )
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i+len)).Key, keys[i]);
}
}
Console.WriteLine("5. add intl strings and CopyTo(Array, 0)");
strLoc = "Loc_005oo";
iCountTestcases++;
string [] intlValues = new string [len * 2];
示例6: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
ListDictionary ld;
try
{
Console.WriteLine("--- default ctor ---");
strLoc = "Loc_001oo";
iCountTestcases++;
ld = new ListDictionary();
Console.WriteLine("1. compare to null");
iCountTestcases++;
if (ld == null)
{
iCountErrors++;
Console.WriteLine("Err_0001, dictionary is null after default ctor");
}
Console.WriteLine("2. check Count");
iCountTestcases++;
if (ld.Count != 0)
{
iCountErrors++;
Console.WriteLine("Err_0002, Count = {0} after default ctor", ld.Count);
}
Console.WriteLine("3. check Item(some_key)");
iCountTestcases++;
if (ld["key"] != null)
{
iCountErrors++;
Console.WriteLine("Err_0003, Item(some_key) returned non-null after default ctor");
}
Console.WriteLine("4. check ToString()");
iCountTestcases++;
string temp = ld.ToString();
Console.WriteLine(" ToString(): " + temp);
if (temp.IndexOf("ListDictionary") == -1)
{
iCountErrors++;
Console.WriteLine("Err_0004, ToString() doesn't contain \"ListDictionary\"");
}
Console.WriteLine("5. check returned Type");
iCountTestcases++;
temp = ld.GetType().ToString().Trim();
Console.WriteLine(" GetType(): " + temp);
if (temp.IndexOf("ListDictionary") == -1)
{
iCountErrors++;
Console.WriteLine("Err_0005: returned type doesn't contain \"ListDictionary\"");
}
Console.WriteLine("6. compare returned Type of two dictionary");
iCountTestcases++;
string temp1 = (new ListDictionary()).GetType().ToString().Trim();
if (String.Compare(temp, temp1) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0006: returned types of two collections differ");
}
Console.WriteLine("7. check Keys collection");
iCountTestcases++;
System.Collections.ICollection keys = ld.Keys;
if ( keys.Count != 0)
{
iCountErrors++;
Console.WriteLine("Err_0007: Keys contains {0} keys after default ctor", keys.Count);
}
Console.WriteLine("8. check Values collection");
iCountTestcases++;
System.Collections.ICollection values = ld.Values;
if ( values.Count != 0)
{
iCountErrors++;
Console.WriteLine("Err_0008: Values contains {0} items after default ctor", values.Count);
}
Console.WriteLine("9. Add(name, value)");
iCountTestcases++;
ld.Add("Name", "Value");
if (ld.Count != 1)
{
iCountErrors++;
Console.WriteLine("Err_0009a: Count returned {0} instead of 1", ld.Count);
}
if (String.Compare(ld["Name"].ToString(), "Value", false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0009b: Item() returned unexpected value");
}
Console.WriteLine("10. Clear()");
iCountTestcases++;
ld.Clear();
if (ld.Count != 0)
{
iCountErrors++;
Console.WriteLine("Err_00010a: Count returned {0} instead of 0 after Clear()", ld.Count);
}
if (ld["Name"] != null)
{
iCountErrors++;
//.........这里部分代码省略.........
示例7: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
ListDictionary ld;
int cnt;
string [] values =
{
"",
" ",
"a",
"aA",
"text",
" SPaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
string [] keys =
{
"zero",
"oNe",
" ",
"",
"aa",
"1",
System.DateTime.Today.ToString(),
"$%^#",
Int32.MaxValue.ToString(),
" spaces",
"2222222222222222222222222"
};
try
{
Console.WriteLine("--- create dictionary ---");
strLoc = "Loc_001oo";
iCountTestcases++;
ld = new ListDictionary();
Console.WriteLine("1. IsFixedSize on empty dictionary");
iCountTestcases++;
if (ld.IsFixedSize)
{
iCountErrors++;
Console.WriteLine("Err_0001, returned true for empty dictionary");
}
Console.WriteLine("2. IsFixedSize for filled dictionary");
strLoc = "Loc_002oo";
iCountTestcases++;
ld.Clear();
cnt = values.Length;
for (int i = 0; i < cnt; i++)
{
ld.Add(keys[i], values[i]);
}
if (ld.Count != cnt)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, cnt);
}
iCountTestcases++;
if (ld.IsFixedSize)
{
iCountErrors++;
Console.WriteLine("Err_0002b, returned true for filled dictionary");
}
}
catch (Exception exc_general )
{
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
return true;
}
else
{
Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例8: runTest
//.........这里部分代码省略.........
}
if (ld.Count != len)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", ld.Count, values.Length);
}
for (int i = 0; i < len; i++)
{
iCountTestcases++;
if ( ! ld.Contains(keys[i]) )
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}b, doesn't contain \"{1}\"", i, keys[i]);
}
}
Console.WriteLine("3. add intl strings check Contains()");
strLoc = "Loc_003oo";
iCountTestcases++;
string [] intlValues = new string [len * 2];
for (int i = 0; i < len*2; i++)
{
string val = intl.GetString(MAX_LEN, true, true, true);
while (Array.IndexOf(intlValues, val) != -1 )
val = intl.GetString(MAX_LEN, true, true, true);
intlValues[i] = val;
}
Boolean caseInsensitive = false;
for (int i = 0; i < len * 2; i++)
{
if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
caseInsensitive = true;
}
iCountTestcases++;
ld.Clear();
for (int i = 0; i < len; i++)
{
ld.Add(intlValues[i+len], intlValues[i]);
}
if ( ld.Count != (len) )
{
iCountErrors++;
Console.WriteLine("Err_0003a, count is {0} instead of {1}", ld.Count, len);
}
for (int i = 0; i < len; i++)
{
iCountTestcases++;
if ( ! ld.Contains(intlValues[i+len]) )
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}b, doesn't contain \"{1}\"", i, intlValues[i+len]);
}
}
Console.WriteLine("4. case sensitivity");
strLoc = "Loc_004oo";
string [] intlValuesLower = new string [len * 2];
for (int i = 0; i < len * 2; i++)
{
intlValues[i] = intlValues[i].ToUpper();
}
for (int i = 0; i < len * 2; i++)
{
intlValuesLower[i] = intlValues[i].ToLower();
}
ld.Clear();
for (int i = 0; i < len; i++)
{
示例9: runTest
//.........这里部分代码省略.........
{
if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
caseInsensitive = true;
}
Console.WriteLine(" initial number of items: " + ld.Count);
strLoc = "Loc_002oo";
for (int i = 0; i < len; i++)
{
iCountTestcases++;
cnt = ld.Count;
ld.Add(intlValues[i+len], intlValues[i]);
if (ld.Count != cnt+1)
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}a, count is {1} instead of {2}", i, ld.Count, cnt+1);
}
iCountTestcases++;
if (String.Compare(ld[intlValues[i+len]].ToString(), intlValues[i], false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}b, returned item \"{1}\" instead of \"{2}\"", i, ld[intlValues[i+len]], intlValues[i]);
}
}
Console.WriteLine("3. Case sensitivity");
string [] intlValuesLower = new string [len * 2];
for (int i = 0; i < len * 2; i++)
{
intlValues[i] = intlValues[i].ToUpper();
}
for (int i = 0; i < len * 2; i++)
{
intlValuesLower[i] = intlValues[i].ToLower();
}
ld.Clear();
Console.WriteLine(" initial number of items: " + ld.Count);
strLoc = "Loc_003oo";
for (int i = 0; i < len; i++)
{
iCountTestcases++;
cnt = ld.Count;
ld.Add(intlValues[i+len], intlValues[i]);
if (ld.Count != cnt+1)
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}a, count is {1} instead of {2}", i, ld.Count, cnt+1);
}
iCountTestcases++;
if ( ld[intlValues[i+len]] == null )
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}b, returned null", i);
}
else
{
if ( ! ld[intlValues[i+len]].Equals(intlValues[i]) )
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}c, returned item \"{1}\" instead of \"{2}\"", i, ld[intlValues[i+len]], intlValues[i]);
}
}
if ( !caseInsensitive && ld[intlValuesLower[i+len]] != null )
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}d, returned non-null", i);
}
}