First, I am new to Java, so hopefully this isn't something terribly simple, but I am trying to do some unit-testing and I am not getting the old green light in Eclipse. To my problem:
So, I have two Objects, both of class Fraction and I am simply trying to make sure that my method (multiplyThem) is.... uh... functioning correctly.
Code:
@Test
public void testMultiplyEm() {
System.out.println(newFraction.multiplyEm(otherFraction));
System.out.println(new Fraction(2, 15));
assertTrue("Multiplication failure", Objects.equals(newFraction.multiplyEm(otherFraction), new Fraction(2, 15)));
}
In the method multiplyEm, the return type is a Fraction and it multiplies two numerators and two denominators before calling on another function called simplify. Then it returns the simplified Fraction.
I used system.out.println on the two individually and got the exact same thing printed to screen. I know that doesn't always mean they ARE the same, but perhaps Objects.equals isn't what I should be using here. The objects are simply two ints... Fraction x = new Fraction(int y, int z)
I am not sure why this fails the test. Anyone have any ideas? Would be grateful for a way to correctly write a unit test for it!
Aucun commentaire:
Enregistrer un commentaire