Assume you need to test a function named inOrder . The function inOrder receives
ID: 3655421 • Letter: A
Question
Assume you need to test a function named inOrder . The function inOrder receives three int arguments and returns true if and only if the arguments are in non-decreasing order: that is, the second argument is not less than the first and the third is not less than the second. Write the definition of driver function testInOrder whose job it is to determine whether inOrder is correct. So testInOrder returns true if inOrder is correct and returns false otherwise. For the purposes of this exercise, assume inOrder is an expensive function call, so call it as few times as possible!Explanation / Answer
{ // no calls, this is as few as you can get return true; } I would absolutely not call the function fewer times than shown below. bool testInOrder() { if (inOrder(-1,0,1) == false) return false; if (inOrder(1,1,1) == false) return false; if (inOrder(1,2,1) == true) return false; if (inOrder(2,1,2) == true) return false; // all tests passed return true; }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.