面试题功能测试

来源:互联网 发布:梦幻西游法宝算法 编辑:程序博客网 时间:2024/06/09 19:42

             三角形问题:

                        定义:任意两边之和必须大于第三边;

              等腰三角形:

                         定义:任意两边相等,而且任意两边之和必须大于第三边的三角形,是等腰三角形;

              等边三角形:

                         定义:三条边都相等,称为等边三角形;

             直角三角形:

                        定义:其中两边平方之和等于第三边的平方称之为直角三角形;

             初级版本:三角形程序将接受三个整数,输入a,b和c,分别代表三角形的三条边,程序输出为这三条边所构成的三角形的类型,机等边三角形,等腰三角形,一般

                               三角形和非三角形4类,有时也包含直角三角形;

             测试用例的设计:

非三角行: 输入 a = 2, b = 3 c = 6 , 输出非三角行

等边三角行: 输入 a = 2 b = 2 c = 2 , 输出等边三角行

等腰三角行: 输入: a = 2 b = 2 c =1 , 输出等腰三角行

直角三角行: 输入 a = 3 b = 4 c = 5 输出直角三角行

用代码实现:java

public void sendKeys(int a,int b, int c){

if(a+b <= c || a+b <= b || b+c <= a){

System.out.print("非三角形");

return;

}

if(a==b && b != c || a==c && b! = c || b==c && a!=b){

System.out.print("等腰三角形");

return;

}

if(a == b && b ==c){

System.out.print("等边三角形");

return;

}

if(a*a + b*b == c*c || a*a +c*c == b*b || b*b + c*c == a*a){

System.out.print("直角三角形");

return;

}

}

python:

年 月 日 问题:year month day

前提:年必须满足:1812 <= year <= 2017

月必须满足: 1<=month <= 12

日必须满足: 1<= day <= 31


      等价类:

             有效等价类:year 2001 month 8 day 20

                                year 2000 month 2 day 29

                                year 2000 month 1 day 31

                                year 2000 month 4 day 30

             无效等价类:year 2001 month 2 day 20

                                year 2001 month 4 day31

                                year 1800 month 1 day 30

                                year 2001 month -1 day 31

                                year 2001 month 1 day 32

      使用java代码:

            public void sendkeyYear(int year, int month, int day){

                          if(year < 1812 || year >2017){

                                     System.out.print("请输入在指定范围内的年");

                                     return;

                              }

                          if(month < 1 || month > 12){

                                   System.out.print("请输入在指定范围内的月");

                                   return;

                           }

                          if(year%4 == 0 && month == 2){

                               if(day > 29){

                                         System.out.print("今年是闰年,2月不能大于29天");

                                         return;

                               }

                            }

                      if(year %4 != 0 && month == 2){

                           if(day > 28){

                                 System.out.print("今年不是闰年,2月不能大于28天");

                                 return;

                             }

                             }

                     if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month==10 || month == 12){

                                   if(day < 1 || day > 31){

                                             System.out.print("抱歉当月有31天,请输入有效天数");

                                             return;

                                       } 

                         }

                         if(day < 1 || day > 30){

                                        System.out.print("抱歉当月有30天,请输入有效天数);

                                        return ;

 

                              }

            }    

      佣金问题:

              枪机  locks   枪托   stocks   枪管    barrels           输入销售的数量,单价是固定的;

              public void  sendGun(int  locksnumber , int stocksnumer , int  barrelsnumber){

                         int locksprice = 45;

                         int  stocksprice = 35;

                         int  barrelsprice = 25;

                         int  countnumber  =  locksnumber + stocksnumer + barrelsnumber;

                         int sum = locksprice * locksnumber + stocksprice * stocksnumer + barrelsnumber * barrelsprice;\

                         int  sums = 0;

                         if(locksnumber < 0 || stocksnumer < 0 || barrelsnumber < 0){

                                return;

                            }

                         if(0 < sum <= 1000){

                                 sums* = 0.1;

                            }

                         if(1000 < sum < 1800){

                               sums*=0.15

                             }

                         if(1800 < sum){

                            sums*=0.2;

                        }

                   }     

     SATM系统:

               针对金融测试,首先使用XMind画流程图;       

原创粉丝点击