黑盒测试实验——软测

(1)三角形问题:输入三个正整数a、b、c(1-200),分别作为三角形的三条边,通过程序判断三条边是否能构成三角形?如果能构成三角形,判断三角形的类型(等边三角形、等腰三角形、一般三角形)。 请用黑盒测试的方法设计测试用例。 

(2)NextDate问题:输入三个变量month、day和year,输出:输入日期后一天的日期,比如:输入为2000年6月9日,则该函数的输出应为2000年6月10日。年份区间为1-2050年。请用黑盒测试的方法设计测试用例。程序界面如下:

(3)实现一个登陆模块,用户名要求由字母和数字组成且第一个必须是字母,长度为6-10,密码由六位数字组成,请根据黑盒测试的方法设计测试用例。

  • 三角形问题测试设计:
         测试用例

三角形(等价类划分)

输入条件

有效等价类

无效等价类

是否三角形的三条边

(A>0)                (1)

(A<=0)               (7)

(B>0)                (2)

(B<=0)               (8)

(C>0)                (3)

(C<=0)               (9)

(A+B>C)             (4)

(A+B<=C)           (10)

(A+C>B)             (5)

(A+C<=B)           (11)

(B+C>A)             (6)

(B+C<=A)           (12)

是否等腰三角形

(A=B)               (13)

(A!=B)and(A!=C)and(B!=C)

                    (16)

(B=C)               (14)

(A=C)               (15)

是否等边三角形

(A=B)and(A=C)and(B=C)

                    (17)

(A!=B)              (18)

(B!=C)              (19)

(A!=C)              (20)

三角形测试用例,输入顺序是【A,B,C】

用例编号

【A,B,C】

覆盖等价类

输出

1

【3,4,5】

(1)~(6)

一般三角形

2

【0,1,2】

(7)

不是三角形

3

【1,0,2】

(8)

不是三角形

4

【1,2,0】

(9)

不是三角形

5

【1,2,3】

(10)

不是三角形

6

【1,3,2】

(11)

不是三角形

7

【3,1,2】

(12)

不是三角形

8

【3,3,4】

(1)~(6),(13)

等腰三角形

9

【3,3,3】

(1)~(6),(17)

等边三角形

  • NextDate问题测试设计:

 测试用例

输入条件

有效等价类

无效等价类

1到2050年的闰年(1)

年份小于1(3)

1到2050年的平年(2)

年份大于2050(4)

1到12月(5)

月份小于1(6)

月数大于12(7)

1~28天(8)

天数小于1(12)

29天(9)

2月闰年天数<30(13)

30天(10)

2月平年天数<29(14)

31天(11)

1,3,5,7,8,10,12月,天数<32(15)

<32(15)

月份为4,6,9,11,天数<31(16)

天数>31(17)

测试用例:

(1)、有效等价类设计测试用例

序号

测试数据

期望结果

覆盖范围

1

2016 2 29

2016年3月1日

(1)(5)(7)

2

2017 1 28

2017年1月29日

(2)(3)(6)

3

2017 1 31

2017年2月1日

(2)(3)(9)

4

2017 4 30

2017年5月1日

(2)(4)(8)

5

2017 12 31

2018年1月1日

(2)(3)(9)

(2)、无效等设

序号

输入数据

期望结果

覆盖范围

6

0 3 1

输入的年份无效!

(10)

7

2051 3 1

输入的年份无效!

(11)

8

205% 3 1

输入数只能为整数入!

(12)

9

1901 -1 1

输入的月份无效!

(13)

10

1901 13 1

输入的月份无效!

(14)

11

1901 1% 1

输入数只能为整数

(15)

12

1901 1 -1

输入的日子无效!

(16)

13

2016 2 30

输入的日子无效!

(17)

14

2017 2 29

        输入的日子无效!

(18)

15

2017 3 32

输入的日子无效!

(19)

16

2017 4 31

输入的日子无效!

(20)

17

2017 4 32

输入的日子无效!

(21)

18

2017 4 3%

输入数只能为整数

(22)

  • 登录问题:

 测试用例:

登录(等价类划分)

输入条件

有效等价类

无效等价类

Username

首字符为字母(1)

首字符不为字母(3)

其余5~9字符为字母和数字组合(2)              

其余输入少于5字符(4)

其余输入大于9字符(5)

其余5~9字符不为字母数字(6)

password

输入为六位数字(7)

输入不为6位字符(8)

输入不为数字(9)

登录问题测试用例:输入顺序【username,password】

用例编号

测试数据

期望结果

覆盖范围

1

A12345,123456

用户名符合规则!

密码符合规则!

(1)(2)(7)

2

A123456,a12345

用户名符合规则!

密码必须为6位数字!

(1)(2)(9)

3

A123456,12345

用户名符合规则!

密码必须为6位!

(1)(2)(8)

4

123456,123456

用户名首字符必须为字母,其余为字母和数字!

密码符合规则!

(2)(3)(7)

5

A123,abcdef

用户名长度必须为6~10位!

密码必须为6位数字!

(1)(4)(8)(9)

6

1234,a123456

用户名长度必须为6~10位!

密码必须为6位!

(3)(4)(8)(9)

 代码如下:

三角形问题:

import java.util.InputMismatchException;
import java.util.Scanner;

public class Judge {
    public int a;
    public int b;
    public int c;
    public int type;
    Judge(int a,int b,int c){
        this.a = a;
        this.b = b;
        this.c = c;
    }
    public boolean JudgeTriangle(){
        boolean flag = false;
        if(a>1&&b>1&&c>1&&a<200&&b<200&&c<200){
            if(a+b>c&&b+c>a&&a+c>b){
                flag = true;
            }
        }
        return flag;
    }
    public void JudgeTriangleType(){
        if(JudgeTriangle()){
            System.out.println("是一般三角形");
            if(a==b||a==c||b==c){
                System.out.println("是等腰三角形");
                if(a==b&&b==c){
                    System.out.println("是等边三角形");
                }
            }
        }
    }
    public static void main(String[] args) {
        // 定义输入正确判断,不正确则一直输入;
        while (true) {
            try {
                System.out.println("请输入三个整数,为三角形三边:");
                int[] a = new int[3];
                for(int i=0;i<3;i++){
                    a[i] = new Scanner(System.in).nextInt();
                }
                Judge judge = new Judge(a[0],a[1],a[2]);
                if(judge.JudgeTriangle()){
                    System.out.println("是三角形");
                    judge.JudgeTriangleType();
                }
                else {
                    System.out.println("不是三角形,请重新输入!");
                }
            } catch (InputMismatchException e) {
                System.out.println("输入的数只能为整数,请重新输入!");
            }
        }
    }

}

NextData问题:

import java.util.InputMismatchException;
import java.util.Scanner;

public class NextData {
    int day;
    int month;
    int year;
    int[] commonYear = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int[] leapYear = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int typeOfYear;

    public NextData(int day, int month, int year) {
        this.day = day;
        this.month = month;
        this.year = year;
    }
    public void judgeYearClass() {
        // 判断闰年平年
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
            typeOfYear = 1;
        } else {typeOfYear = 2;}
    }
    public void NextDataCul(){
        if(judge()){
            int Day = day + 1;
            int[] Year;
            if(typeOfYear == 1){Year = leapYear;}
            else {Year = commonYear;}
            if (Day > Year[month-1]) {
                day = 1;
                month = month + 1;
                if (month > 12) {
                    month = 1;
                    year = year + 1;
                }
                System.out.println(year + "年" + month + "月" + day + "日");
            } else {
                day = day + 1;
                System.out.println(year + "年" + month + "月" + day + "日");
            }
        }
    }
    public boolean judge(){ // 判断输入是否有效的
        Boolean boolJudge = true;
        judgeYearClass();
        if(month>12||month<1){boolJudge = false;System.out.println("输入的月份无效!");} // 判断月份
        else if(day>leapYear[month-1] && typeOfYear == 1 || day<1){// 判断日子
            boolJudge = false;
            System.out.println("输入的日子无效!");
        } else if (day>commonYear[month-1] && typeOfYear == 2 || day<1) {
            boolJudge = false;
            System.out.println("输入的日子无效!");}
        else if(year<1||year>2050){boolJudge = false;System.out.println("输入的年份无效!");} // 判断年份

        return boolJudge;
    }
    public static void main(String[] args) {
        while (true) {
            try {
                System.out.println("请输入三个整数,按年,月,日输入:");
                int[] a = new int[3];
                for (int i = 0; i < 3; i++) {
                    a[i] = new Scanner(System.in).nextInt();
                }
                NextData nextData = new NextData(a[2], a[1], a[0]);
                nextData.NextDataCul();
            } catch (InputMismatchException e) {
                System.out.println("输入的数只能为整数,请重新输入!");
            }
        }
    }
}

登录问题:

import java.util.Scanner;
public class login {
    private String username;
    private String password;
    public login(String username, String password) {
        this.username = username;
        this.password = password;
    }
    public Boolean CheckOutUesrnameLength(String username){ // 检验用户名长度
        if(username.length()>=6 && username.length()<=10){
            return true;
        }
        else {return false;}
    }
    public Boolean CheckOutPasswordLength(String password){
        if(password.length() == 6){
            return true;
        }
        else {return false;}
    }
    public void CheckOutUsername(){
        if(CheckOutUesrnameLength(username)){
            String regix = "[A-Z_a-z]{1}\\w{5,9}";
            boolean flag = username.matches(regix);
            if(flag){System.out.println("用户名符合规则!");}
            else {System.out.println("用户名首字符必须为字母,其余为为字母和数字!");}
        }else {System.out.println("用户名长度必须为6~10位!");}
    }
    public void CheckOutPassword(){
        if(CheckOutPasswordLength(password)){
            String regix = "\\d{6}";
            if(password.matches(regix)){System.out.println("密码符合规则!");}
            else {System.out.println("密码必须为6位数字!");}
        }
        else {System.out.println("密码必须为6位!");}
    }
    public static void main(String[] args) {
        while (true){
            String username,password;
            System.out.println("请输入用户名:");
            username = new Scanner(System.in).next();
            System.out.println("请输入密码:");
            password = new Scanner(System.in).next();
            login login = new login(username,password);
            login.CheckOutUsername();
            login.CheckOutPassword();
        }
    }
}

  • 4
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值