For the Program1,

  For Question1:

  The fault is that in the loop condition, ' i ' should be not less than(>=) 0 rather than just greater than(>) 0. This will result in the problem that if the target is just in the position 0 and then the program cannot return the correct answer.

  The original one is like this,  

    for (int i=x.length-1; i > 0; i--)

  However, it should be like this,

    for (int i=x.length-1; i >= 0; i--)

  For Question2:

  Test: x = [2], y = 2 

  In this test case, the length of the ' x ' is just 1 and then it cannot suit the condition of the loop. In the other word, it will not go into the loop and then the program will return -1. And this is not the correct answer obversely.

  For Question3:

  Test: x = [3,2,5], y = 2

  In this test case, the original program will not occur a failure because the target is not in the position 0. As a result, this will not make a mistake even if it has the reachability.

  But it will be in a error state.

  For Question4:

  Test: x=[2, 2, 5]; y = 2

  Expected = 1

  As a result, the program do not check the x[0] and this is an error condition but the answer is correct and this is not a failure.

For the Program2,

  For Question1:

  The fault is that the origenal program return the first 0 that occurs in ' x ' but not the last.

  The original one is like this,  

    for (int i = 0; i < x.length; i++)

  However, it should be like this,

    for (int i=x.length-1; i >= 0; i--)

  For Question2:

  I think it is impossible or maybe ' x ' is an empty array (that may throw a NullPointerException). And then this may not execute the fault.

  For Question3:

  Test case: x = [3]

  Or maybe it is impossible.

  For Question4:

  Test: x = [0,1,1] return is 0 and this is right.

  Because the 0 is the only one in the array and then the first and the last is the same.

【SoftwareTesting】Homework2的更多相关文章

  1. 【SoftwareTesting】Lab 2

    一.    在火狐浏览器上安装selenium插件 点击“开发者”的选项,然后点击“获取更多工具”,输入seleniumIDE进行搜索,找到后进行安装即可.安装完成后火狐浏览器的右上角会多出一个小的带 ...

  2. 【SoftwareTesting】Homework3

    (a) (b) 数组越界问题 (c) n=0 (d) 点覆盖:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] 边覆盖:[(1,2),(2,3),(3,4),(4,5) ...

  3. 【SoftwareTesting】Lab 1

    1.  安装junit, hamcrest 和 eclemma 分别下载  hamcrest-core-1.3.jar和junit-4.12.jar这两个jar包,并加入到新建的项目中 具体步骤为:右 ...

  4. 【SoftwareTesting】Homework1

    The errors I will mention after are from the project in the last semester. The project is a Java pro ...

  5. Python高手之路【六】python基础之字符串格式化

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  6. 【原】谈谈对Objective-C中代理模式的误解

    [原]谈谈对Objective-C中代理模式的误解 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这篇文章主要是对代理模式和委托模式进行了对比,个人认为Objective ...

  7. 【原】FMDB源码阅读(三)

    [原]FMDB源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 FMDB比较优秀的地方就在于对多线程的处理.所以这一篇主要是研究FMDB的多线程处理的实现.而 ...

  8. 【原】Android热更新开源项目Tinker源码解析系列之一:Dex热更新

    [原]Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Tinker是微信的第一个开源项目,主要用于安卓应用bug的热修复和功能的迭代. Tinker github地址:http ...

  9. 【调侃】IOC前世今生

    前些天,参与了公司内部小组的一次技术交流,主要是针对<IOC与AOP>,本着学而时习之的态度及积极分享的精神,我就结合一个小故事来初浅地剖析一下我眼中的“IOC前世今生”,以方便初学者能更 ...

随机推荐

  1. Jvm类的加载机制

    1.概述 虚拟机加载Class文件(二进制字节流)到内存,并对数据进行校验.转换解析和初始化,最终形成可被虚拟机直接使用的Java类型,这一系列过程就是类的加载机制. 2.类的加载时机 类从被虚拟机加 ...

  2. 小程序之 input框设置placeholder的style

    <input placeholder='></input>

  3. vue-router 中踏过的坑

    1.做完页面滚动,然后再加上路由,发现路由一直跳转不了,经历千辛万苦才发现是BScroll没有配置click:true,当看过文档时心里一万只草泥马奔腾而过,我预感到成长道路上还有多少坑在等着我. 2 ...

  4. y

    switch(update_state) { : switch(num){ : window.progressn=num $('#h_progress_bar .ui-progress').anima ...

  5. Docker报错 WARNING: IPv4 forwarding is disabled. Networking will not work.

    问题:创建容器的时候报错WARNING: IPv4 forwarding is disabled. Networking will not work. # docker run -it -p 3000 ...

  6. Caused by : java.io.IOException: Cleartext HTTP traffic to 《“url”》 not permitted

    一.问题原因: 根本原因是从Android9.0开始,出于完全因素考虑,默认不再支持http网络请求,需要使用 https. 二.解决方案: 解决的基本思路是:对指定的网址进行过滤,强制允许指定网址继 ...

  7. setTimeout异步

    同步任务和异步任务 同步和异步操作的区别就是是否阻碍后续代码的执行. 同步任务是那些没有被引擎挂起.在主线程上排队执行的任务.只有前一个任务执行完毕,才能执行后一个任务. 异步任务是那些被引擎放在一边 ...

  8. requests库详解 --Python3

    本文介绍了requests库的基本使用,希望对大家有所帮助. requests库官方文档:https://2.python-requests.org/en/master/ 一.请求: 1.GET请求 ...

  9. es6中promise ALL Race Resolve Reject finish的实现

    function mypromise(func){ this.statue = "pending"; this.data = null; this.resolveCallback ...

  10. python webdriver api-对启动的火狐浏览器添加配置

    Webdriver启用的火狐不带插件,可以自已进行配置 先找到火狐的安装路径 C:\Program Files\Mozilla Firefox 步骤说明 在CMD中使用cd命令进入firefox.ex ...