[Mono-list] Mono/.Net: object comparison

Julien Sobrier julien at sobrier.net
Fri Jun 24 11:47:34 EDT 2005


Hello,
I've compiled a program with Mono 1.1.6 under Linux, and Windows .Net,
with NAnt 0.85RC3 and NUnit 2.2.0

I see a different behavior when I compare object with NUnit:

I have a custom class MyClass with 3 public variables: String1 (string),
String2 (string) and Version1 (Version).

In one class, I do like:
ArrayList myArray = new ArrayList();
myArray.Add(new MyClass(string1, string2, version1);
myArray.Add(new MyClass(string1a, string2a, version1a);
myArray.Add(new MyClass(string1b, string2b, version1b);

Then I create MyClass foo = new MyClass(string1, string2, version1)

Then, with Nunit, I do some comparisons (note sure about the index for
myArray):
* Mono 1.1.6/Linux
myArray[0] different from foo
(MyClass) MyArray[0] different from foo
((MyClass) MyArray[0]).String1 =  foo.String1
((MyClass) MyArray[0]).String2 =  foo.String2
((MyClass) MyArray[0]).Version1 =  foo.Version1

* .Net/Windows
myArray[0] = foo
(MyClass) MyArray[0] = foo
((MyClass) MyArray[0]).String1 =  foo.String1
((MyClass) MyArray[0]).String2 =  foo.String2
((MyClass) MyArray[0]).Version1 =  foo.Version1


Who is right? I hope .Net is right :-) I wonder what cause this
different behavior


Details of the code:
[Test]
[Category("attributes")]
public void AssemblyDependTest()
{
     Assert.AreEqual(this.PluginA.Dependencies.Count, 6,
"AssemblyDepend: number of dependencies");
			
     AssemblyDepend test = new
Platine.CoreLibs.Attributes.AssemblyDepend("PluginB");

     Assert.AreEqual(test.PluginName, "PluginB", "AssemblyDepend:
PluginA depends on PluginB"); // OK
     Assert.AreEqual(test.MinVersion.ToString(), "0.0.0.0",
"AssemblyDepend: PluginA depends on PluginB"); // OK
     Assert.AreEqual(test.EventName, "*", "AssemblyDepend: PluginA
depends on PluginB"); // OK

			Assert.IsTrue(this.PluginA.Dependencies.Contains(test),
"AssemblyDepend: PluginA depends on PluginB"); // WRONG, should be OK

Assert.AreEqual(((AssemblyDepend)
this.PluginA.Dependencies[5]).PluginName, test.PluginName,
"AssemblyDepend: PluginA depends on PluginB"); // OK
Assert.AreEqual(((AssemblyDepend)
this.PluginA.Dependencies[5]).EventName, test.EventName,
"AssemblyDepend: PluginA depends on PluginB"); // OK
Assert.AreEqual(((AssemblyDepend)
this.PluginA.Dependencies[5]).MinVersion, test.MinVersion,
"AssemblyDepend: PluginA depends on PluginB"); // OK
}

Thank you
Julien


More information about the Mono-list mailing list