How can this educational tool be improved?
To enhance the effectiveness of this tool, consider the following suggestions:
Expand the test cases: Include a wider variety of test cases to cover more common assumptions made by programmers. Examples could include:
Which tests would be good and how should they look like?
1. Character Assumptions:
Code:
<code class="c">EXPECT("00 we have ASCII",('A'==65));</code>Copy after loginCopy after login
Code:
<code class="c">EXPECT("02 big letters come before small letters",('A'<'a'));Copy after login
Code:
<code class="c">EXPECT("04 a char is 8 bits",CHAR_BIT==8);Copy after login
2. Integer Assumptions:
Code:
<code class="c">EXPECT("06 integers are 2-complement and wrap around",(int_max+1)==(int_min));Copy after login
Code:
<code class="c">EXPECT("05 int has the size of pointers",sizeof(int)==sizeof(void*));Copy after login
3. Pointer Assumptions:
Code:
<code class="c">EXPECT("10 void* can store function pointers",sizeof(void*)>=sizeof(void(*)()));</li> </ul> <p><strong>4. Execution Assumptions:</strong></p> <ul> <li> <strong>Test:</strong> Test if the stack always grows downwards.</li> <li> <p><strong>Code:</strong></p> <blockquote><pre class="brush:php;toolbar:false"><code class="c">EXPECT("12 the stack grows downwards",check_grow(5,0)<0);</code>Copy after login
Code:
<code class="c">EXPECT("00 we have ASCII",('A'==65));</code>Copy after loginCopy after login
Would you run the tests on the platforms you can get your hands on and post the results?
We encourage community participation in testing the assumptions on different platforms. Please share your results along with the following information:
The above is the detailed content of Is Your C/C Code Making Unwarranted Assumptions?. For more information, please follow other related articles on the PHP Chinese website!