This does not work
int blueInt = Color.Blue.ToArgb();
Color fred = Color.FromArgb(blueInt);
Assert.AreEqual(Color.Blue,fred);
Any suggestions?
[Edit]
I'm using NUnit and the output is
failed:
Expected: Color [Blue]
But was: Color [A=255, R=0, G=0, B=255]
[Edit]
This works!
int blueInt = Color.Blue.ToArgb();
Color fred = Color.FromArgb(blueInt);
Assert.AreEqual(Color.Blue.ToArgb(),fred.ToArgb());
I would have expected this with Assert.AreSame because of the boxing with the value types, but AreEqual should not have this problem.
Could you add which language (I'm assuming C#) your using and which testing framework?
What does
Assert.AreEqual(true, Color.Blue == fred);
result in?From the MSDN documentation on
Color.operator ==
:I'm guessing the state flags are different.
They won't equal the same, as Color.Blue doesn't equal your colour object, it equals something stored internally, a "new Color(KnownColor.Blue);" to be exact.
Alternatively, this also works, and I think it's more intuitive