结对编程之Fault、Error、Failure
1.结对说明
结对对象:刘世麟 博客地址:http://www.cnblogs.com/liushilin/
2.题目要求
3.题目概述
提示用户输入两个值,两个值必须在[0,100],若不满足条件各自有自己的提示,若两个值都小于5,则输出all input less than 5,程序退出。否则根据输入的值判断使用加法还是减法,若输入的第一个数小于第二个数,则使用减法计算,结果小于0,不然就使用加法,结果一定大于0。
4.结对照片
5.源码

1 package com.nanchen.jieduibiancheng;
2
3 import java.util.Scanner;
4
5 public class ErrorFault {
6 private static Scanner in = new Scanner(System.in);
7 private static final int RANGE_LOW = 0;// 允许用户输入的最小值
8 private static final int RANGE_HIGH = 100;// 允许用户输入的最大值
9 private static final int LIMIT = 5;
10 private static int result;// 返回结果
11
12 /**
13 * 获得用户输入,输入值必须是0到100的整数
14 *
15 * @return
16 */
17 public static int getUserInput() {
18 int number = -1;
19 System.out.println("please input a integer number,range in [0,100] !");
20 while (true) {
21 if (in.hasNextInt()) {
22 number = in.nextInt();
23 if (number > RANGE_HIGH || number < RANGE_LOW) {
24 System.out.println("The input integer number not in [0,100],please input again!");
25 } else {
26 break;
27 }
28 } else {
29 in.nextLine();// 刷新输入流
30 System.out.println("illegal input!!!the input must be a integer!please input again!");
31 }
32 }
33 return number;
34 }
35
36 /**
37 * 获得返回结果
38 *
39 * @param num1
40 * @param num2
41 * @return
42 */
43 public static int getResult(int num1, int num2) {
44 if (num1 < num2) {
45 return num1 + num2;// 此处存在fault,应该是减法
46 }
47 return num1 + num2;
48 }
49 // 如上,无论如何输入都会执行加法而不会执行减法。
50
51 public static void main(String[] args) {
52 int op1 = getUserInput();
53 int op2 = getUserInput();
54 System.out.println("******************************************************");
55 System.out.println("The user input num1 is " + op1 + " the num2 is " + op2);
56 if (op1 < LIMIT && op2 < LIMIT) {
57 System.out.println("All input less than 5!!!");
58 return;
59 }
60 result = getResult(op1, op2);
61 if (result > 0) {
62 if (result > 100) {
63 System.out.println("Illegal!");
64 } else {
65 System.out.println("The system uses the addition,and the result is " + result);
66 }
67 } else {
68 if (result < -50) {
69 System.out.println("Illegal!");
70 } else {
71 System.out.println("The system uses subtraction,and the result is " + result);
72 }
73 }
74 }
75
76 }

6.存在fault的代码说明

/**
* 获得返回结果
* @param num1
* @param num2
* @return
*/
public static int getResult(int num1,int num2) {
if(num1 < num2){
return num1 + num2;//此处存在fault,应该是减法
}
return num1 + num2;
}
//如上,无论如何输入都会执行加法而不会执行减法。

如上,无论用户输入的第一个数和第二个数的大小,都会触发加法计算,而不会进行减法的运算
7.测试用例
1)存在fault但不能触发fault。
由于本程序存在分支,所以只要不进入fault分支,就不能触发fault!
2)触发fault,但不能触发error。
如上,由于用户输入的第一个值大于第二个值,会触发正确的得到加法运算,所以触发了fault,但是并没有触发error。
3)触发Error,但是不能触发Failure。
8.总结
现在已经进入软件测试方面的学习,通过该程序,对软件中fault,error,failure 有了很直观的认识和理解,也让我们明白了,测试有一定的局限性,如何高效的测试,如何科学的测试,如何能得到较高的测试回报率,这也是本门课程中最重要的核心学习的内容。这是本门课程的开头,也让我们认识到软件测试有有趣性,对软件测试领域有了不一样的认识。
结对编程之Fault、Error、Failure的更多相关文章
- 结对编程2—Fault&Error&Failure
学习进度表 点滴成就 学习时间 新编写代码行数 博客量(篇) 学到知识点 第一周 8 0 0 了解软件工程 第二周 10 0 1 博文一篇 第三周 15 0 2 选择项目.调查问卷 第四周 20 80 ...
- 软件测试中的fault,error,failure
问题:给定两段代码,设计fault,error,failure的测试用例. fault:即引起错误的原因,类似病因. error:类似疾病引起的内部结果. failure:类似疾病引起的症状. 代码1 ...
- 结对编程--fault,error,failure的程序设计
一.结对编程内容: 1.不能触发Fault. 2.触发Fault,但是不触发Error. 3.触发Error,但不触发Failure. 二.结对编程人员 1.周浩,周宗耀 2.结对截图: 三.结对项目 ...
- 结对项目——fault,error,failure的程序设计
一.结对编程内容: 1.不能触发Fault. 2.触发Fault,但是不触发Error. 3.触发Error,但不触发Failure. 二.结对编程人员 1.周宗耀.周浩: 2.结对截图: 三.结对项 ...
- ST HW2 fault & error & failure
Software Testing 3014218128 牛菲菲 Below are two faulty programs. Each includes a test case that result ...
- 结对编程之<GoldPointGame>
我们结对项目的名称是GoldPointGame,这是一个非常经典的老游戏,其规则大致是:N个同学每个人依次报一个(1-100)的有理数,交给裁判算出其平均值,然后乘以黄金点数0.618,最后得到G值. ...
- 软件测试作业 - fault error failure
给出的题目如下: 我的解答如下: For program 1:1. where i > 0 is the fault , it should be changed to i>= 0 to ...
- 结对编程——关于Fault、Error、Failure程序设计
一.问题描述: 构造程序,分别是: •不能触发Fault •触发Fault,但是不能触发Error •触发Error,但是不能产生Fai ...
- 网络编程之C10K
网络编程之C10K 虽然在过去的十几年里C10K问题已经可以很好的解决,但学习网络编程时研究C10K问题仍然价值巨大,因为技术的发展都是有规律和线索可循的,了解C10K问题及其解决思路,通过举一反三, ...
随机推荐
- SMON功能(二):合并空闲区间
SMON的作用还包括合并空闲区间(coalesces free extent) 触发场景 早期Oracle采用DMT字典管理表空间,不同于今时今日的LMT本地管理方式,DMT下通过对FET$和UET$ ...
- Android 解压boot.img
其实解压.打包boot.img没什么难度一看就会咯!! 1.先下附件:工具. 点击打开链接 6.0 KB, 下载次数: 60) 解压到bin文件夹里,方便以后使用. 2.解压boot ...
- highcharts插件使用总结和开发中遇到的问题及解决办法
这里使用的highchart是2014-01-09从官网下载的版本,版本号是3.0.8, 当过了几天后,发现版本号变成了3.0.9,不由得的感叹highchart的版本更新之快. 在jsp中使用hig ...
- 关于meta知多少
本来打算写关于手机端的知识,想了想先从meta着手.接下来请大家看几个网站的例子. 一.天猫(http://m.tmall.com) <title>天猫触屏版</title> ...
- WWDC2016-session402-whatsNewInSwift3
Dock 应用的介绍:1.设计到的东西多2.使用 swift 设计3.Dock 的代码量: 200,000行4.更少的重写相同功能的代码 swift.org 官网介绍 Swift Open Sourc ...
- ch2 MySQL 架构组成
第 2 章 MySQL 架构组成 前言 麻雀虽小,五脏俱全.MySQL 虽然以简单著称,但其内部结构并不简单.本章从 MySQL 物理组成.逻辑组成,以及相关工具几个角度来介绍 MySQL ...
- file_get_contents()获取https出现这个错误Unable to find the wrapper “https” – did
file_get_contents()获取https出现这个错误Unable to find the wrapper “https” – did 解决办法 ,如果你是用的服务器,可以参考这个办法,修改 ...
- js后退一直停留在当前页面或者禁止后退
//禁用后退按钮 function stopHistoryGo() { //禁用回退 window.location.hash="no-back-button"; window.l ...
- java对过反射调用方法
public class InvokeTester { public InvokeTester() { } String str; public InvokeTester(String str) ...
- CentOS 6.6 配置PuTTY远程登录
1. 下载与安装 可以下载putty-0.63-installer.exe(http://www.chiark.greenend.org.uk/~sgtatham/putty/download.htm ...