JUnit Test confusion

Hey, i had a few questions which my professor didnt really bother explaining, but when writing a JUnit test for lets say this equation (solves quadratics) i know how to test for given variable values, for e.g: p=1, q=2. But what if i wanted to test for all variable combinations of p and q?
No description
37 Replies
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @mjstx! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
true, i was just wondering if there would be a way of doing logical checks for all p, q variables
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
alr, like upper, lower limit and one middle value?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
could give a short example
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
its for the plus and minus value of x thats the mistake that the Junit test is supposed to show task by our proff
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
alright, makes sense. What about imaginary numbers though?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
ah mb, i meant during code execution, for the Math.sqrt, not the value iself
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
I Run Code
I Run Code2y ago
Here is your java(15.0.2) output @That_Guy977
NaN
NaN
mjstx
mjstxOP2y ago
but thats a trviial error so it doesnt count towards a mistake right?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
basically a mistake as in something wrong with the code itself logically or syntax etc
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
alright, makes sense in this case then. Just one last thing though in the code there a return statement but its not connected or reffering to any variable where is the value being stored then?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
but returned to where?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
like for assertEquals, what would i check as my output variable?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
0x150
0x1502y ago
quick heads up, the formula is incorrect when x1 = false x = -(p/2) +- sqrt((p/2)² - q)
mjstx
mjstxOP2y ago
yup, theres a change in the minus sign in between the -p/2 and Math.sqr() right? or is there something else?
0x150
0x1502y ago
no, you just need to replace the first + with a -
mjstx
mjstxOP2y ago
ah alr 👍
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
yeah but you would have to calculate the expected value first and then "see" the mistake, but here the mistake is easy to spot already
mjstx
mjstxOP2y ago
kind alike this then where you call the entire method and use it value without storing it in a variable first?
No description
0x150
0x1502y ago
you're plugging the result of calculator.multiply(4, 5) into the 2nd argument of assertEquals, the multiply method is called first and the return value is used as 2nd argument or, if it throws an exception, it's propagated through testMultiply and up until someone catches it or it ends up at the top of the call stack
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mjstx
mjstxOP2y ago
alr got it chief, thanks for this i think most of my questions have been answered :GN_Dog:
JavaBot
JavaBot2y ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot2y ago
Post Closed
This post has been closed by <@290070433984806912>.

Did you find this page helpful?