I am trying to write some operation overloading and assertion routine. I have a struct named Degree, and following is my code;
public struct Degree
{
public float InnerValue;
public Degree(float value)
{
InnerValue = value;
}
public static Degree operator +(Degree a, Degree b)
{
return new Degree(a.InnerValue + b.InnerValue);
}
public static void UnitTest()
{
Random rd = new Random();
Degree lhs = rd.NextDegree(-(Degree)360, (Degree)360);
Degree rhs = rd.NextDegree(-(Degree)360, (Degree)360);
float f = rd.NextFloat(-100, 100);
float temp = lhs.InnerValue + rhs.InnerValue;
Debug.Assert((lhs + rhs).InnerValue == temp);
Debug.Assert((lhs + rhs).InnerValue == lhs.InnerValue + rhs.InnerValue);
}
}
my code seems looks very well for operator overloading, but assertion fails. The problem is only second Assert fails. I am unable to understand the reason for the same. Any help would be appreciated.