This question already has an answer here:
- Is floating point math broken? 28 answers
I am currently discovering Visual Studio's Unix Tests and wrote a little Test Project for it. It is a simple Console Calculator with the following two methods:
public static double divide(double zahl1, double zahl2)
{
return zahl1 / zahl2;
}
public static double add(double zahl1, double zahl2)
{
return zahl1 + zahl2;
}
I automatically created the Unix Tests for those two methods. Then entered the Testing Code:
public void divideTest()
{
double zahl1 = 6.6;
double zahl2 = 8.8;
double result = 0.0;
double expected = 0.75;
result = Taschenrechner.divide(zahl1, zahl2);
Assert.AreEqual(expected, result);
}
[TestMethod()]
public void addTest()
{
double zahl1 = 10.5;
double zahl2 = 5.4;
double result = 0.0;
double expected = 15.9;
result = Taschenrechner.add(zahl1, zahl2);
Assert.AreEqual(expected, result);
}
If I now run those tests, addTest() works fine, but divideTest() fails:
Funny thing being that it says Expected: 0.75, Actual: 0.75 which should be right.
What am I doing wrong?
Edit: I may also add that the addTest() takes <1ms while divideTest() takes 131ms.
Aucun commentaire:
Enregistrer un commentaire