FitSharp supports optional cell Operators
How do I use this one specifically? http://fitsharp.github.io/Fit/CompareFloatingPoint.html
I have read the bottom of this page http://fitsharp.github.io/Fit/CellOperators.html
I have tried putting the Processor.AddOperator("fitSharp.Fit.Operators.CompareFloatingPoint");
in my method under test.
public class Division
{
public double Numerator { get; set; }
public double Denominator { get; set; }
public double Quotient()
{
Processor.AddOperator("fitSharp.Fit.Operators.CompareFloatingPoint");
return Numerator / Denominator;
}
}
I have tried a suiteconfig file
<suiteConfig>
<Fit.Operators>
<Add>fitSharp.Fit.Operators.CompareFloatingPoint</Add>
</Fit.Operators>
</suiteConfig>
Including in the Fitnesse markup like this
!define COMMAND_PATTERN {%m -r fitnesse.fitserver.FitServer -c C:\fit\tests\SuiteConfig.xml %p}
Output of test currently looks like this
.fail, span.fail * {
background-color: #FFAAAA;
}
.pass, span.pass * {
background-color: #c1e2b3;
color: #081109;
}
table {
width: 100%;
margin-bottom: 20px;
border: 1px solid #dddddd;
width: auto;
}
table > thead > tr > th, table > tbody > tr > th, table > tfoot > tr > th, table > thead > tr > td, table > tbody > tr > td, table > tfoot > tr > td {
border: 1px solid #dddddd;
}
table > thead > tr > th, table > tbody > tr > th, table > tfoot > tr > th, table > thead > tr > td, table > tbody > tr > td, table > tfoot > tr > td {
padding: 5px;
}
<table>
<tbody><tr>
<td colspan="3"><span class="fit_interpreter">tests.Division</span></td>
</tr>
<tr>
<td><span class="fit_member">numerator</span></td>
<td><span class="fit_member">denominator</span></td>
<td><span class="fit_member">quotient?</span></td>
</tr>
<tr>
<td>10</td>
<td>2</td>
<td class="pass">5</td>
</tr>
<tr>
<td>12.6</td>
<td>3</td>
<td class="pass">4.2</td>
</tr>
<tr>
<td>100</td>
<td>4</td>
<td class="pass">25</td>
</tr>
<tr>
<td>22</td>
<td>7</td>
<td class="fail">3.14 <span class="fit_label">expected</span><hr>3.14285714285714 <span class="fit_label">actual</span></td>
</tr>
</tbody></table>
The cell operator is loaded correctly, the problem is the cell operator doesn't do what you hoped it does. The CompareFloatingPoint
operator doesn't use the precision of the expected value (3.14), it uses the precision of the string representation of the actual value (3.14285714285714). As you commented, fitSharp doesn't support the ~= operator, you could use >= 3.14 and < 3.15 on two rows, but not quite as nice!