// TODO: add tests for Comparer and HashCodeProvider
// NOTE: add MCS prefix to Hashtable.cs to use this test.
using System;
using MCS.System.Collections;
using System.Collections;
using NUnit.Framework;
namespace Testsuite.System.Collections {
/// Hashtable test.
public class HashtableTest {
public static ITest Suite {
get {
TestSuite suite= new TestSuite("All Hashtable Tests");
suite.AddTest(BasicOperationsTest.Suite);
return suite;
}
}
}
public class BasicOperationsTest : TestCase {
protected MCS.System.Collections.Hashtable ht;
private static Random rnd;
public BasicOperationsTest(String name) : base(name) {}
protected override void SetUp() {
ht=new MCS.System.Collections.Hashtable();
rnd=new Random();
}
public static ITest Suite {
get {
return new TestSuite(typeof(BasicOperationsTest));
}
}
private void SetDefaultData() {
ht.Clear();
ht.Add("k1","another");
ht.Add("k2","yet");
ht.Add("k3","hashtable");
}
public void TestAddRemoveClear() {
ht.Clear();
Assert(ht.Count==0);
SetDefaultData();
Assert(ht.Count==3);
bool thrown=false;
try {
ht.Add("k2","cool");
} catch (ArgumentException) {thrown=true;}
Assert("Must throw ArgumentException!",thrown);
ht["k2"]="cool";
Assert(ht.Count==3);
Assert(ht["k2"].Equals("cool"));
}
public void TestCopyTo() {
SetDefaultData();
Object[] entries=new Object[ht.Count];
ht.CopyTo(entries,0);
Assert("Not an entry.",entries[0] is DictionaryEntry);
}
public void TestUnderHeavyLoad() {
Console.WriteLine("Testing "+ht);
ht.Clear();
int max=100000;
String[] cache=new String[max*2];
int n=0;
for (int i=0;i=r1 && i