emory-courses / dsa-java

Data Structures and Algorithms in Java
https://emory.gitbook.io/dsa-java/
42 stars 55 forks source link

[QZ 1] Quiz 1 Zero Test Question #29

Closed TFloyd1989 closed 4 years ago

TFloyd1989 commented 4 years ago

I have a simple question for quiz 1. If we create a test for adddifferentsigns adding 0 and -0, should the result be 0 or -0?

marvinquiet commented 4 years ago

According to test3 and test4 in the LongIntegerQuizTest.java, I think the answer would be 0 if adding 0 and -0. If adding -0 and 0, the answer would be -0. It seems to depend on the first term.

TFloyd1989 commented 4 years ago

I'm having trouble getting digits to show the value -0. Even when I make a new byte test array "z" with a length of one and the value "-0" and then set digits to copy that array, the result still prints as 0.

lujiaying commented 4 years ago

According to https://emory.gitbook.io/dsa-java/java-essentials/unit-testing#test-longinteger, if the class LongInteger() is implemented correctly, new LongInter("-0") should be printed as "-0".

marvinquiet commented 4 years ago

@TFloyd1989 Please close the issue if no further question on this issue :)