Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 1) // utility.cpp // IN THIS FILE, define any of your OWN functions you may need to // solve the problems. // For example,
1
1)
// utility.cpp // IN THIS FILE, define any of your OWN functions you may need to // solve the problems. // For example, if you need an isPrime function, you can put the function // definition in this file. Similarly, isOdd or isEven might be useful. // You will need to include the function prototype in "utility.h" and // then be sure to #include "utility.h" in the file where you use // these functions bool isOdd(int x) { return false; // REPLACE THIS STUB WITH REAL CODE } bool isEven(int x) { return false; // REPLACE THIS STUB WITH REAL CODE } bool isPrime(int x) { return false; // REPLACE THIS STUB WITH REAL CODE }
2)
#include "utility.h" #include "tddFuncs.h" int main() { assertEquals(true,isEven(2),"isEven(2)"); assertEquals(false,isEven(3),"isEven(3)"); assertEquals(true,isEven(4),"isEven(4)"); assertEquals(false,isEven(55),"isEven(55)"); assertEquals(false,isEven(-55),"isEven(-55)"); assertEquals(true,isEven(-80),"isEven(-80)"); assertEquals(false,isOdd(2),"isOdd(2)"); assertEquals(true,isOdd(3),"isOdd(3)"); assertEquals(false,isOdd(4),"isOdd(4)"); assertEquals(true,isOdd(55),"isOdd(55)"); assertEquals(true,isOdd(-55),"isOdd(-55)"); assertEquals(false,isOdd(-80),"isOdd(-80)"); assertEquals(true,isPrime(2),"isPrime(2)"); assertEquals(true,isPrime(3),"isPrime(3)"); assertEquals(false,isPrime(4),"isPrime(4)"); assertEquals(false,isPrime(55),"isPrime(55)"); assertEquals(true,isPrime(859),"isPrime(859)"); assertEquals(false,isPrime(861),"isPrime(861)"); assertEquals(true,isPrime(863),"isPrime(863)"); assertEquals(false,isPrime(1337),"isPrime(1337)"); assertEquals(true,isPrime(1373),"isPrime(1373)"); assertEquals(false,isPrime(64507),"isPrime(64507)"); assertEquals(true,isPrime(69997),"isPrime(69997)"); // Note that negative numbers are, by definition, // not Prime. http://mathforum.org/library/drmath/view/55940.html // Same for 0 and 1 assertEquals(false,isPrime(-55),"isPrime(-55)"); assertEquals(false,isPrime(-80),"isPrime(-80)"); assertEquals(false,isPrime(0),"isPrime(0)"); assertEquals(false,isPrime(1),"isPrime(1)"); return 0; }
REPLACE THE STUBS WITH ACTUAL CODE SO IT WILL RUN PASS
Step 4c: Run ity Test Next, type /utility Test t program that tests the three functions isodd, isEven and i As we noted above, some of the tests will pass, even though the implementation of the three functions is totally bogus This runs the utility (hard coded to return false always). Here is what that looks like (some output truncated -bash-4.2$ utilityTest Expected 1 Actual: 0 PASSED is Even (3) isEven FAI Expected 1 Act PASSED: Even(ss) utput tted PASSED 64507 FAILED 69997 Expected: 1 Actual: 0 PASSED isPrime (-55) PASSED: i Prime (-8%) PASSED PASSED is Prime (1) h-4.2$ Step 4d: Repeat: edit, compile, run ,until all tests pass Now do these steps, repeatedly, until all tests pass: edit utility.cpp (e.g. emacs utility.cpp, or vim utility.cpp) make utility Test run utility Test (e.g. ./utility Test) This is the starting point, because for other files you will be editing later, you will NEED functions isOdd, isEven and isPrime. Once you get them working, you will be able to call them in other files and KNOW that they work properly. You will not have to repeat the function definition. When all the tests for ut tyTi t pass, move on to the next stepStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started