Coming to Java from Python. I recognize this is pretty basic, but it doesn't seem this has been asked here yet and Google is being coy with me.
In Python, I'd simply do something like this but Java objects:
assertTrue(min <= mynum and mynum <= max);
The assertSame() and assertNotSame() methods tests if two object references point to the same object or not. It is not enough that the two objects pointed to are equals according to their equals() methods. It must be exactly the same object pointed to. The calls to myUnit.
We can use the equals() method to compare two integers in Java. It returns true if both objects are equal; otherwise, it returns false.
assertEquals. public static void assertEquals(Object expected, Object actual) Asserts that two objects are equal. If they are not, an AssertionError without a message is thrown. If expected and actual are null , they are considered equal.
I'd write:
assertTrue("mynum is out of range: " + mynum, min <= mynum && mynum <= max);
but technically you just need:
assertTrue(min <= mynum && mynum <= max);
Either way, be sure to write &&
and not and
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With