ST:(homework 2)
Below are two faulty programs. Each includes a test case that results in failure. Answer the following questions (in the next slide) about each program.
Questions:
1.Identify the fault.
The left one : i should >= 0,not only > 0;
The right one : is should be " for( int i = x.lenght -1; i >= 0; i--)"
2.If possible, identify a test case that does not execute the fault. (Reachability)
the left one : test: x = []; y =1; expected = -1; actual = -1
the right one : test: x = [] ; expected = -1; actual = -1
3.If possible, identify a test case that executes the fault, but does not result in an error state.
the left one : test: x = [2,3,4];y = 4;expected = 2; actual = 2
the right one: test: x = [0]; expected = 0; actual = 0
4.If possible identify a test case that results in an error, but not a failure.
the left one : test: x = [2,3,4];y = 5;expected = -1; actual = -1
the right one: test: x = [0,3,4]; expected = 0; actual = 0
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步