zoukankan      html  css  js  c++  java
  • 第二次作业 105032014005

    1、测试帖链接:http://www.cnblogs.com/xiaojuangao/p/6605968.html

    2、源代码链接:http://www.cnblogs.com/ChenXh123/p/6530437.html

    3、测试人员提出的问题、发现的缺陷以及建议:

      1)针对测试人员提出的“无法判断非润年2月29号存在的错误”这种情况,我检查过,是可以出现预期结果的,测试人员可以再次检查一下我之前的代码是否真的存在这种问题。

      2)针对代码优化建议,我将可复用的语句提到了判断分支之外,并删减了一些重复代码;

      3)针对代码优化建议,补充了一个菜单,可以实现操作和退出的功能。

    4、修正后的代码清单:

     1 import java.util.Scanner;
     2 
     3 public class NextDate {
     4 
     5     //nextdate函数
     6     public static String nextdate(int month,int day,int year){
     7         int isleap[]={31,29,31,30,31,30,31,31,30,31,30,31};
     8         int noleap[]={31,28,31,30,31,30,31,31,30,31,30,31};
     9         int m,d,y;
    10         
    11         if (month<1 || month>12){
    12             return "月份超出范围";
    13         }
    14         if (day<1 || day>31){
    15             return "日期超出范围";
    16         }
    17         if (year<1912 || year>2050){
    18             return "年份超出范围";
    19         }
    20 
    21         if ((year%4==0 && year%100!=0) || year%400==0){//闰年
    22             if (day<isleap[month-1]){
    23                 d = day+1;
    24                 m = month;
    25                 y = year;
    26             } 
    27             else if (day==isleap[month-1]){//该月的最后一天
    28                 d=1;
    29                 if (month==12){//一年的最后一天
    30                     m = 1;
    31                     y = year+1;
    32                 }
    33                 else{
    34                     m = month+1;
    35                     y = year;
    36                 }
    37             }
    38             else{//针对31天以内,但是超出该月最大天数
    39                 return "日期超出范围";
    40             }    
    41         }
    42         
    43         else{//非闰年
    44             if (day<noleap[month-1]){
    45                 d = day+1;
    46                 m = month;
    47                 y = year;
    48             } 
    49             else if (day==noleap[month-1]){//该月的最后一天
    50                 d = 1;
    51                 if (month==12){//一年的最后一天    
    52                     m = 1;
    53                     y = year+1;
    54                 }
    55                 else{
    56                     m = month+1;
    57                     y = year;
    58                 }
    59             }
    60             else{//针对31天以内,但是超出该月最大天数
    61                 return "日期超出范围";
    62             }
    63         }
    64         return y + "年" + m + "月" + d + "日";
    65     }
    66     
    67     public static void main(String[] args) {
    68         
    69         while(true){
    70             
    71             System.out.println("1、请输入日期(格式:月  日  年)");
    72             System.out.println("2、退出");
    73             System.out.println("请输入序号 :");
    74             Scanner scan = new Scanner(System.in);
    75             String num = scan.next();
    76             if(num.equals("1")){
    77                 if(scan.hasNextInt()){
    78                     int   m = scan.nextInt();
    79                     int   d = scan.nextInt();
    80                     int   y = scan.nextInt();    
    81                     System.out.println(nextdate(m,d,y));
    82                 }
    83                 else{
    84                     System.out.println("输入格式错误!!!");
    85                 }
    86             }
    87             else if(num.equals("2")){
    88                 scan.close();
    89                 System.out.println("谢谢使用!");
    90                 break;
    91             }
    92         }    
    93         
    94     }

    5、修正后心得体会:

    • 在nextdate函数中,在判断每月最后一天的情况中,将12月和非12月的情况的相同代码提到了分支的外部,并删减了不必要的return语句,统一在函数结束前return.
    • 在这段学习中,发现软件测试覆盖的学习面很广,目前只是在学习白盒测试的逻辑覆盖法,就有这么多的覆盖方法,在实际设计测试用例的时候,会发现有些覆盖方法,如:语句覆盖、判定覆盖等并不能涵盖测试的所有方面,在这几种逻辑覆盖里面,路径覆盖的效果最好。但是当程序大起来的时候,实际中很难做到所有的路径覆盖。因此,要对程序的可靠性要求采取不同的逻辑覆盖标准,不断补充测试用例,以达到逻辑覆盖标准。
  • 相关阅读:
    阿里--面经 搜集
    阿里一面经验总结
    System对象
    JDBC-oracle(登陆)
    博客静态页面
    设计模式(1)---Factory Pattern
    软件设计师备考经验(含新旧版本对比)
    第九课,ROS仿真1
    参数服务器相关的问题
    3.空域图像处理的洪荒之力
  • 原文地址:https://www.cnblogs.com/ChenXh123/p/6622262.html
Copyright © 2011-2022 走看看