多输入的等价类划分以及测试

一、问题描述:

   将上一次的等价类划分的应用程序拓展成为三个输入框,并设计测试用例进行测试。

二、等价类划分:

  

  有效等价类:

    (1)长度:1到6

    (2)字符:a-z,A-Z,0-9

   无效等价类

    (1)长度:0,7

    (2)字符:英文/数字以外字符,控制字符,标点符号

编号 有效等价类 编号 无效等价类
1 长度为1-6 5 长度为0
2 字符a-z 6 长度为7
3 字符A-Z 7 字符:英文/数字以外字符,控制字符,标点符号
4 字符0-9    

 三、设计测试用例

  

编号 测试用例 预计输出
1 “”   “”   “”   输入为空  输入为空  输入为空
2 “”   “123”  “1234567” 输入为空  输入正确  输入字符长度超出
3 “”   “1234¥%”  “12345”  输入为空 输入非法字符  输入正确
4

“12341”    “123q4 ”    “A12345”

输入正确  输入正确  输入正确
5

“123ac”   “ZZZZZ”  “aaaZZ$%”

 输入正确  输入正确  输入长度超出
6 “1234*(”    “AAA9a”      “” 输入非法字符  输入正确  输入为空
7 “¥%?????”   “123ASD”   “@!%¥” 输入长度超出  输入正确  输入非法字符
8 “&()”   “()”   “o9)” 输入非法字符   输入非法字符  输入非法字符
9 “123457”   “aaaaaaa”   “ZZZZZZZZZZZZZZZZ” 输入长度超出  输入长度超出   输入长度超出

  

四 代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String text1 = textBox1.Text;
            String text2 = textBox2.Text;
            String text3 = textBox3.Text;
            String str = null;
            if (test(text1) == 1)
            {
                str += "第一行输入为空
";
            }
            else if (test(text1) == 3)
            {
                str += "第一行输入长度超出
";
            }
            else if (test(text1) == 2){

                 str += "第一行输入正确
";
            }
            else if (test(text1) == 0)
            {
                str += "第一行输入特殊字符
"; 
            }
            if (test(text2) == 1)
            {
                str += "第二行输入为空
";
            }
            else if (test(text2) == 3)
            {
                str += "第二行输入长度超出
";
            }
            else if (test(text2) == 2)
            {

                str += "第二行输入正确
";
            }
            else if (test(text2) == 0)
            {
                str += "第二行输入特殊字符
";
            }

            if (test(text3) == 1)
            {
                str += "第三行输入为空
";
            }
            else if (test(text3) == 3)
            {
                str += "第三行输入长度超出
";
            }
            else if (test(text3) == 2)
            {

                str += "第三行输入正确
";
            }
            else if (test(text3) == 0)
            {
                str += "第三行输入特殊字符
";
            }
            MessageBox.Show(str);   
            
        }

        private int test(string str)
        {
            int temp=0;
            if(str.Length == 0){
                temp = 1;
            }
            else if (str.Length >= 7)
            {
                temp = 3;
            }
            else
            {
                for (int i = 0; i < str.Length; i++)
                {
                    if (!(isatoz(str[i]) || isAtoZ(str[i]) || isnum(str[i]))){
                        temp = 0;
                        break;
                    }
                    temp = 2;
                }
            }
            return temp;  
        }

        private Boolean isatoz(char s)
        {
            Boolean temp = false;
            if (s >= 'a' && s <= 'z')
            {
                temp = true;
            }
            return temp;
        }

        private Boolean isAtoZ(char s)
        {
            Boolean temp1 = false;
            if (s >= 'A' && s <= 'Z')
            {
                temp1 = true;
            }
            return temp1;
        }

        private Boolean isnum(char s)
        {
            Boolean temp2 = false;
            if (s >= '0' && s <= '9')
            {
                temp2 = true;
            }
            return temp2;
        }


    }
}

五  测试截图

           

原文地址:https://www.cnblogs.com/zzy-blogs/p/4376352.html