我在接受采访时被问到这个问题.我完全无能为力地解决这个问题......
/* You are writing a unit test to confirm the correctness of a function which
takes 3 float values as arguments. You decide to stress test it by testing
1000000 'random' inputs.
You find that the function will fail, but very rarely, so you include code
to print out all failure cases, hoping to grab a simple repro case which you
can debug into.
Note: All code here is run in a single-threaded environment. */
//...
// Some code sets a,b,c
//...
if ( testPasses(a,b,c) )
{
printf("Pass\n");
}
else // someFunc fails, print the values so we can reproduce
{
printf("Fail: %f %f %f\n", a, b, c);
}
Run Code Online (Sandbox Code Playgroud)
你能帮助我吗?谢谢!
更新:对不起家伙我意外删除了这个问题!!
这里是
// where testPasses has the following signature and executes deterministically
// with no side effects:
bool testPasses(float f1, float f2, float f3);
void testRepro()
{
float a = // fill in from value printed by above code
float b = // fill in from value printed by above code
float c = // fill in from value printed by above code
bool result = testPasses(a,b,c);
};
// Surprisingly, when you type in the 3 values printed out in testRepro()
// the test does not fail!
// Modify the original code and test bed to reproduce the problem reliably.
Run Code Online (Sandbox Code Playgroud)
打印出代表float打印值的字节而不是打印值.然后,您可以将确切的值插入十六进制值.
char value[4] = { 0x12, 0x34, 0x56, 0x78 };
float *a = (float*)value;
// test using *a
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
524 次 |
| 最近记录: |