Unit testing Hashtables
Consider the following three tests. Without compiling, what would you expect the results to be and why? A GMail invite will be provided to the first right answer, so make sure you provide your email address or some other means of contacting you when commenting.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[TestFixture]
public class HashtableTestFixture
{
[Test]
public void TestHashtableEquals()
{
Hashtable h = new Hashtable();
h.Add("foo", "foo");
Hashtable h2 = new Hashtable();
h2.Add("foo", "foo");
Assert.IsTrue(h.Equals(h2));
}
[Test]
public void TestHashtableClone()
{
Hashtable h = new Hashtable();
h.Add("foo", "foo");
Hashtable h2 = (Hashtable)h.Clone();
Assert.AreEqual(h, h2);
}
[Test]
public void TestHashtable()
{
Hashtable h = new Hashtable();
h.Add("foo", "foo");
Hashtable h2 = new Hashtable(h);
Assert.AreEqual(h, h2);
}
}
This post is licensed under CC BY 4.0 by the author.