一、测试帖链接
二、测试人员提出的问题和发现的缺陷
用例:1900年2月2日年份超出了范围,但还是没有停止计算。
三、修正后的代码清单
package examOne;import java.util.Scanner;public class Date { String ia, ib, ic; int y, m, d; private boolean Read(){ Scanner sc = new Scanner(System.in); System.out.println("请输入年份"); ia = sc.nextLine(); if( "-1".equals(ia) ){ sc.close(); return false; } System.out.println("请输入月份"); ib = sc.nextLine(); System.out.println("请输入日期"); ic = sc.nextLine(); return true; } private boolean isInputInteger(){ try{ y = Integer.valueOf(ia).intValue(); m = Integer.valueOf(ib).intValue(); d = Integer.valueOf(ic).intValue(); return true; } catch( Exception e){ System.out.println("输入不符合要求,请输入三个整数"); return false; } } private boolean isInRange(){ if( m < 1 || m > 12 ){ System.out.println("月份超出范围"); return false; } if( d < 1 || d > 31 ){ System.out.println("日期超出范围"); return false; } if( y < 1912 || y > 2050 ){ System.out.println("年份超出范围"); return false; } return true; } private int isLeapYear(){ if( ( y % 4 == 0 && y % 100 != 0 ) || ( y % 400 == 0 ) ){ return 1; } return 0; } private boolean EndOfMouth( int flg ){ if( ( m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12 ) && d == 31 ){ return true; } if( m == 2 && d == (28 + flg) ){ return true; } if( ( m == 4 || m == 6 || m == 9 || m == 11 ) && d == 30 ){ return true; } return false; } private String NextDate(){ int tag = 0; if( EndOfMouth( isLeapYear() ) ){ tag = 1; } if( m == 12 && tag == 1 ){ y++; m = 1; d = 1; } else if( tag == 1 ){ m++; d = 1; } else{ d++; } String ret = y + "年" + m + "月" + d + "日"; return ret; } public static void main( String args[]){ Date solve = new Date(); while( solve.Read() ){ if( solve.isInputInteger() && solve.isInRange() ){ System.out.println( solve.NextDate() ); } } }}
四、修正后心得体会:
将C++代码转变为JAVA代码,主逻辑不变。针对注释不够的问题,新版的代码采用了变量名代表注释的方式,帮助读者读懂代码
缺陷出现的原因:在逻辑判断的过程中,漏break,自己构造的测试样例并没有测出对应结果
通过这部分教材的学习,了解了软件测试的一些简答测试方式和测试采用思路。