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. @resource、@Autowired、@Service在一个接口多个实现类中的应用

    Spring在没有引入注解之前,传统的Spring做法是使用.xml文件来对bean进行注入,所有的内容都需要配置在.xml文件中,使配置和编程分离,却增加了可读性和复杂度. Spring注解将复杂的 ...

  2. 用Python实现简单通讯录

    一个简单的通讯录例子 #!/usr/bin/python __author__ = 'fierce' #coding:utf-8 import os #引用os模块 import pickle #应用 ...

  3. python的GIL

    GIL 是python的全局解释器锁,同一进程中假如有多个线程运行,一个线程在运行python程序的时候会霸占python解释器(加了一把锁即GIL),使该进程内的其他线程无法运行,等该线程运行完后其 ...

  4. 3D视图的2D展示

    效果图:预览 :预览 如何在2d界面显示3d图形? 如果把屏幕的中心作为视点的中心位置,那由远及近的物体应该是逐渐缩小的,而且是逐渐模糊的, 我们首先获取元素相对于中心点的距离,然后抽取这个距离的百分 ...

  5. 蓝桥杯第九届省赛 sscanf(),str.c_str()函数的使用

    标题:航班时间 [问题背景]小h前往美国参加了蓝桥杯国际赛.小h的女朋友发现小h上午十点出发,上午十二点到达美国,于是感叹到“现在飞机飞得真快,两小时就能到美国了”. 小h对超音速飞行感到十分恐惧.仔 ...

  6. 简单的python购物车

                 这几天,一直在学python,跟着视频老师做了一个比较简单的python购物车,感觉不错,分享一下 products = [['Iphone8',6888],['MacPro ...

  7. Android 工程越来越大,运行变卡解决方法

    打开AS的安装目录 android-studio/bin/studio.exe.vmoptions studio64.exe.vmoptions -Xms2048m-Xmx2048m-XX:Reser ...

  8. windows+Apache+mod_wsgi+flask部署笔记

    windows是用的2008 server 64位. 照着网上教程即可:https://www.jianshu.com/p/0aa1c7097976 但是有个问题: Apache2.4怎么配置???跟 ...

  9. WinForm界面设计-Button添加背景图去边框

    转自:https://www.cnblogs.com/tommy-huang/p/4283538.html 1.既然是添加背景图片 所以这里应该使用 Button.BackgroudImage = & ...

  10. day 02 python 基础

    1.day1作业讲解 题目答案见day1 2.格式化输出 %占位符,s:字符串,d:数字 %%只是单纯的显示%(显示的%是后面的) #格式化输出 # % s d # name = input('请输入 ...