I'm working on a test for an interview and need to write a few classes that are then tested with Assert
statements. There is one part where two objects are tested with Assert.AreEqual()
immediately followed by a test with Assert.AreNotSame
for the same two objects. My understanding is that the first test checks that two objects have the same values (a and b in my example) and the second test checks that they point two different objects in memory. However, the first Assert
fails both in my example and in the program. Am I missing something about how those two Assert
tests should work? How can they both pass?
public class Foo
{
public int a { get; set; }
public int b { get; set; }
public Foo(int a, int b) { this.a = a; this.b = b; }
}
Foo a = new Foo();
a.a = 1;
a.b = 2;
Foo b = new Foo(1, 2);
Assert.AreEqual(a,b);//this fails
Assert.AreNotSame(a,b);