IronPython/C# Float data comparison
- by Gopalakrishnan Subramani
We have WPF based application using Prism Framework. We have embedded IronPython and using Python Unit Test framework to automate our application GUI testing.
It works very well. We have difficulties in comparing two float numbers.
Example
class MyClass
{
public object Value { get; set;}
public MyClass()
{
Value = (float) 12.345;
}
}
In IronPython When I compare the MyClass Instance's Value property with python float value(12.345), it says it doesn't equal
This statement raises assert error
self.assertEqual(myClassInstance.Value, 12.345)
This statement works fine.
self.assertEqual(float(myClassInstance.Value.ToString()), 12.345)
When I check the type of the type(myClassInstance.Value), it returns Single in Python where as type(12.345) returns float. How to handle the C# float to Python comparison without explicit conversions?