关于上次等价类测试的进一步深化

  本周,我将尝试对上次所写的用于等价类测试的小程序作进一步的修改,使其更加复杂具体的新的要求是将上次的一个输入框改为三个输入框,

并要求对于每个数入框都满足:

                                               允许1到6个英文字符或数字,按OK结束

  首先,在程序上的改动并不是太多,由于我是用的是java,首先在布局上做出改变,增加gridlayout,增加两个输入文本框。其次,在逻辑判断上,

并没有太多的改变,无非是综合对三个框的输入判断结果来做出最后的判断,决定输入是否合法

这是对界面布局做出改变的部分

private JButton sure = new JButton("ok");
    private JTextField input = new JTextField(10);
    private JTextField input1 = new JTextField(10);
    private JTextField input2 =new JTextField(10);

    hellow() {
        BorderLayout borderLayout = new BorderLayout(5, 5);
        this.setLayout(borderLayout);
        GridLayout grid = new GridLayout(3,1);
        FlowLayout f1 = new FlowLayout(FlowLayout.CENTER, 10, 10);
        FlowLayout f2 = new FlowLayout(FlowLayout.CENTER, 10, 10);
        FlowLayout f3 = new FlowLayout(FlowLayout.CENTER, 10, 10);
        JPanel p1 = new JPanel(f1);
        p1.add(new JLabel("NAME1: "));
        p1.add(input);
        JPanel p2 =new JPanel(f2);
        p2.add(new JLabel("NAME2: "));
        p2.add(input1);
        JPanel p3 = new JPanel(f3);
        p3.add(new JLabel("NAME3: "));
        p3.add(input2);
        JPanel p4 = new JPanel(grid);
        p4.add(p1);
        p4.add(p2);
        p4.add(p3);
        add(p4, borderLayout.CENTER);
        JPanel login_Button = new JPanel(new FlowLayout(FlowLayout.RIGHT, 120,
                10));
        login_Button.add(sure);
        add(login_Button, borderLayout.SOUTH);

其次在逻辑判断上代码如下

int num = input.getText().length();
                int num1 =input1.getText().length();
                int num2 =input2.getText().length();
                if (num == 0 || num > 6|| num1==0||num1 > 6|| num2==0||num2>6) {
                    wronginput();
                    return;
                }
                String temp = input.getText();
                String temp1 = input1.getText();
                String temp2 = input2.getText();
                if (temp.matches("[0-9A-Za-z]*")&&temp1.matches("[0-9A-Za-z]*")&&temp2.matches("[0-9a-zA-Z]*"))    
                System.out.println("OK");
                else
                    wronginput();

  首先判断是否每个输入框都满足输入的字符顺长度在1-6之间,否则直接提示非法,然后对每个输入框的输入内容都进行判断,如果有一个框的

输入内容不合法,则给出非法提示,如果正确,最后则输出ok。

  有效类 无效类
第一行输入框字符长度 长度为1-6 空串
    长度大于6
第一行输入框字符内容 属于数字,大小写字母 控制字符
    标点符号
第二行输入框字符长度 长度为1-6 空串
    长度大于6
第二行输入框字符内容 属于数字,大小写字母 控制字符
    标点符号
第三行输入框字符长度 长度为1-6 空串
    长度大于6
第三行输入框字符内容 属于数字,大小写字母 控制字符
    标点符号

得到测试用例

1. 第一行 Aa1  2.第一行 空串  3.第一行 AaAaAa1  4.第一行Aa1!  5.第一行 Aa1  6.第一行Aa1

    第二行 Bb2     第二行 Bb2           第二行 Bb2      第二行Bb2    第二行空串   第二行AaAaAa1 

    第三行 Cc3     第三行 Cc3      第三行 Cc3                   第三行Cc3    第三行Cc3   第三行Cc3

7.第一行Aa1    8.第一行Aa1   9.第一行Aa1    10.第一行Aa1 

   第二行Bb2!        第二行Bb2              第二行Bb2                   第二行Bb2

   第三行Cc1         第三行空串             第三行AaAaAa1   第三行Cc3! 

原文地址:https://www.cnblogs.com/huaxiao/p/4375695.html