c# - How to add a result tolerance to a NUnit TestCase -
i have algorithm converts value between celsius , farhrenheit. test works wide range of values i'm using nunit's testcases so:
[testcase( 0, result = -17.778 )] [testcase( 50, result = 10 )] public double fahrenheittocelsius(double val) { return (val - 32) / 1.8; }
the problem first testcase fails because tests exact match.
1 solution have found this:
[testcase( 0, -17.778 )] [testcase( 50, 10 )] public void fahrenheittocelsius2(double val, double expected) { double result = (val - 32) / 1.8; assert.areequal( expected, result, 0.005 ); }
but i'm not happy it. question is:
can tolerance result defined in testcase?
update:
clarify, i'm looking along lines of:
[testcase( 0, result = 1.1, tolerance = 0.05 )]
add parameter test case:
[testcase(0, -17.778, .005)] [testcase(50, 10, 0)] public void fahrenheittocelsius2(double fahrenheit, double expected, double tolerance) { double result = (fahrenheit - 32) / 1.8; assert.areequal(expected, result, tolerance); }
Comments
Post a Comment