Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. // (7b)
  2. // You are writing a unit test to confirm the correctness of a function which
  3. // takes 3 float values as arguments. You decide to stress test it by testing
  4. // 1000000 'random' inputs.
  5. // You find that the function will fail, but very rarely, so you include code
  6. // to print out all failure cases, hoping to grab a simple repro case which you
  7. // can debug into.
  8. // Note: All code here is run in a single-threaded environment.
  9.  
  10.     //...
  11.     // Some code sets a,b,c
  12.     //...
  13.     if ( testPasses(a,b,c) )
  14.     {
  15.         printf("Pass\n");
  16.     }
  17.     else // someFunc fails, print the values so we can reproduce
  18.     {
  19.         printf("Fail: %f %f %f\n", a, b, c);
  20.     }
  21.  
  22. // where testPasses has the following signature and executes deterministically
  23. // with no side effects:
  24. bool testPasses(float f1, float f2, float f3);
  25.  
  26. void testRepro()
  27. {
  28.     float a = // fill in from value printed by above code
  29.     float b = // fill in from value printed by above code
  30.     float c = // fill in from value printed by above code
  31.     bool result = testPasses(a,b,c);
  32. };
  33.  
  34. // Surprisingly, when you type in the 3 values printed out in testRepro()
  35. // the test does not fail!
  36. // Modify the original code and test bed to reproduce the problem reliably.  [4 marks]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement