Discussion about two test cases which result in failure
Question:
1. Indentify the fault
2. Indentify a test case that does not execute the fault
3. Indentify a test case that execute the fault but does not result in an error state
4. Indentify a test case that result in an error state but not a failure
Answer:
Homework 2
For code 1:
1. The condition of the FOR LOOP must be i >= 0, otherwise it may neglect the condition of i = 0, which means the element we want to find is at the first of x.
2. eg. x[] = [1,2,3,4], y=3, then we will get 2, which is what we expected.
3. There’s no test case that executes the fault but doesn’t result in an error state, because it doesn’t check the condition i = 0, then error state happens.
4. eg. x[] = [1,2,3,4], y = 0, then we will get -1, which is what we expected.
For code 2:
1. The program doesn’t find the last 0, instead it finds the first 0.
2. eg. x[]=[1,0,2,3], then we’ll get 1, which is what we expected.
3. When you want to get the position of last 0, the program becomes always true when 0 is at the last position, which means we can give an example below: x[]=[1,2,3,0], then we will get 3 and it does not result in an error state.
4. When there’s only one 0 in the array x, it results in an error not a failure.
Eg. x[]=[1,2,0,3], then we’ll get 2, which is what we expected.