reset password
Author Message
Arnav98
Posts: 48
Posted 22:19 Oct 18, 2017 |

Do we have to check for example multiplication in case of fractions for all possible combinations of + and - (++,--,+-,-+)or just 1 case is fine ? Secondly do we have to check getter and setters as well ?

jhurley
Posts: 207
Posted 11:15 Oct 19, 2017 |

yes, make sure you get correct signs with all four possibilities

write tests that will fail if the getters or setters are wrong

jgarc629
Posts: 76
Posted 17:45 Oct 19, 2017 |

What does it mean by testing instance variables? Is it testing to make sure they are the right type or testing that they're not 0/null/false?

jhurley
Posts: 207
Posted 19:46 Oct 19, 2017 |

Do an operation like add(), then test the result to see

-if the numerator is correct

-if the denominator is correct

-if the sign is correct

jgarc629
Posts: 76
Posted 02:20 Oct 20, 2017 |

I am struggling with the assertion for the adding method on the MyFraction JUnit Test. I am making different objects as new MyFraction a (+1/7) and new MyFraction b (+1/7) and then calling the method in a to add object b by saying a.add(b) and then assign the outcome to  MyFraction c. MyFraction d is a new MyFraction (+2/7) and I am making the assertion assertEquals(c,d). When I print out MyFraction c and  MyFraction d I get the same outcome for both (2/7). However, the JUnit Test fails when I make the assertion. What am I doing wrong?

jhurley
Posts: 207
Posted 09:48 Oct 20, 2017 |
jgarc629 wrote:

I am struggling with the assertion for the adding method on the MyFraction JUnit Test. I am making different objects as new MyFraction a (+1/7) and new MyFraction b (+1/7) and then calling the method in a to add object b by saying a.add(b) and then assign the outcome to  MyFraction c. MyFraction d is a new MyFraction (+2/7) and I am making the assertion assertEquals(c,d). When I print out MyFraction c and  MyFraction d I get the same outcome for both (2/7). However, the JUnit Test fails when I make the assertion. What am I doing wrong?

use assertTrue(a.equals(b));
This will test whether the values are equal according to your .equals() method.

jgarc629
Posts: 76
Posted 21:51 Oct 20, 2017 |

When testing MySet, do we have to iterate through a loop to test each value of the set? Because when I try to compare the array it's only comparing the memory address from the looks of it when I print out the set.