1 / 4

试验函数: int stringToInt ( String ) throws NumberFormatExcepti on 实现字符串转换整型

试验函数: int stringToInt ( String ) throws NumberFormatExcepti on 实现字符串转换整型 功能概述:将输入的字符串转换成 Int 整型,如果正确会输出正确数值结果,如果错误则抛出异常,每种异常对应不同异常信息。 采用 Java 编写测试用例:

Download Presentation

试验函数: int stringToInt ( String ) throws NumberFormatExcepti on 实现字符串转换整型

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 试验函数:int stringToInt(String)throws NumberFormatException实现字符串转换整型 • 功能概述:将输入的字符串转换成Int整型,如果正确会输出正确数值结果,如果错误则抛出异常,每种异常对应不同异常信息。 • 采用Java编写测试用例: • public static void main(String args[]){    //(1)1~6个数字try{   if(stringToInt("     1")==1)    System.out.println("(1)--ok");  }  catch(NumberFormatException e){   System.out.println(e.getMessage());  } • …//(8)左部既不是0也不是空格try{   if(stringToInt("sdfdf2")==2)    System.out.println("(8)--ok");  }  catch(NumberFormatException e){   System.out.println(e.getMessage());  }…

  2. 测试用例: 测试程序: public static void main(String args[]){     try{       System.out.println(stringToInt(args[1]);   }  catch(NumberFormatException e){   System.out.println(e.getMessage());  } }

  3.  void Test(){    //(1)地区码为空,前缀不为0或1开头//预期结果true    if(CityPhoneFunction(“2341111”)) System.out.println("(1)--ok");    else System.out.println("(1)--false");    //(2)地区码为3位,前缀不为0或1开头//预期结果true   if(CityPhoneFunction(“5552341111”)) System.out.println("(2)--ok");    else System.out.println("(2)--false");    //(3)长度不为七位或着十位//预期结果false   if(CityPhoneFunction(“3333441”)) System.out.println("(3)--ok");    else System.out.println("(3)--false");    //(4)前缀为0开头//预期结果false if(CityPhoneFunction(“5550341111”)) System.out.println("(4)--ok");    else System.out.println("(4)--false");    //(5)前缀为1开头//预期结果false   if(CityPhoneFunction(“5551341111”)) System.out.println("(5)--ok");    else System.out.println("(5)--false");    //(6)含有非数字字符//预期结果false   if(CityPhoneFunction(“5r52341111”)) System.out.println("(6)--ok");    else System.out.println("(6)--false");     //(7)在非开头处含有空格//预期结果false   if(CityPhoneFunction(555   1111)) System.out.println("(7)--ok");    else System.out.println("(7)--false");  }

  4. 有效等价类: (1)地区码空白 (2)地区码为3位数字 (3)前缀是200到999之间的3位数字 (4)后缀4位数字无效等价类 无效等价类: (1) 地区码有非数字字符 (2) 地区码少于3位数字 (3) 地区码多于3位数字 (4) 前缀有非数字字符 (5) 前缀起始位为0 (6) 前缀起始位为1 (7) 前缀少于3位数字 (8) 前缀多于3位数字 (9) 后缀有非数字字符 (10) 后缀少于4位数字 (11) 后缀多于4位数字。

More Related