zoukankan      html  css  js  c++  java
  • 等价类划分方法的应用

    等价类划分方法的应用

    题目:

    一个EditBox,允许输入1-6个英文字符或数字,按OK结束。


    以输入条件划分等价类:

    输入的字符串必须满足以下条件:

    条件1:长度1-6

    条件2:字符为'0'-'9'或'a'-'z'或'A'-'Z'

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

    测试用例:

    (注:EditBox不能输入控制字符,故不能测试含有控制字符的输入。)

    编号 输入 覆盖等价类 期望输出
    1 Fks143 1,2 输入正确
    2   3 输入为空
    3 fks1234 4 长度不合法
    4 fks 1 5 含有非法字符
    5 Hi,fks 7 含有非法字符

    测试结果图:

    代码:

     1 namespace SoftwareTest1
     2 {
     3     public partial class Form1 : Form
     4     {
     5         public Form1()
     6         {
     7             InitializeComponent();
     8         }
     9 
    10         private void button1_Click(object sender, EventArgs e)
    11         {
    12             string input = textBox1.Text;
    13 
    14             if (input.Length == 0)
    15             {
    16                 MessageBox.Show("输入为空");
    17                 return;
    18             }
    19             if (input.Length > 6)
    20             {
    21                 MessageBox.Show("长度不合法");
    22                 return;
    23             }
    24             else if (!legalStr(input))
    25             {
    26                 MessageBox.Show("含有非法字符");
    27                 return;
    28             }
    29             else
    30             {
    31                 MessageBox.Show("输入正确");
    32                 return;
    33             }
    34         }
    35 
    36         private bool legalStr(string str)
    37         {
    38             for (int i = 0; i < str.Length; i++)
    39             {
    40                 if ((str[i] < 'a' || str[i] > 'z') && (str[i] < 'A' || str[i] > 'Z') && (str[i] < '0' || str[i] > '9'))
    41                     return false;
    42             }
    43             return true;
    44         }
    45     }
    46 }
  • 相关阅读:
    LeetCode Flatten Binary Tree to Linked List
    LeetCode Longest Common Prefix
    LeetCode Trapping Rain Water
    LeetCode Add Binary
    LeetCode Subsets
    LeetCode Palindrome Number
    LeetCode Count and Say
    LeetCode Valid Parentheses
    LeetCode Length of Last Word
    LeetCode Minimum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/fks143/p/4357256.html
Copyright © 2011-2022 走看看