zoukankan      html  css  js  c++  java
  • 《软件测试技术》课程第三周随笔

    这次的博客内容为,进一步举例解释等价类划分。大概为上一次的加强版...

    1. 问题描述

    EditBox

    在三个文本输入框内输入文字,然后按确认键。

    每个文本框允许接收的文字为:1至6个英文字符或数字。

    三个文本框的内容均为合法的的时候,才会被接收。

    2.等价类划分

      有效等价类 编号 无效等价类 编号
    包括的字符 a-z,A-Z,0-9 1 其他字符 4
    字符串长度 1-6 2 0 5
          大于6 6
    合法的文本框个数 3 3 0-2 7

    3.测试用例

    编号 输入 覆盖等价类 预期输出
    Test1

    a

    AA

    0123

    1,2,3 Accepted
    Test2

    Abd2

    ad2dA

    df12F

    1,2,3 Accepted
    Test3

    12AB34

    abAB12

    3412aa

    1,2,3 Accepted
    Test4

    11

    22

    33

    1,2,3 Accepted
    Test5

    a

    a

    5,7 Please try again.
    Test6

    abcdefg

    a

    a

    6,7 Please try again.
    Test7

    @@

    1abc

    AB12cd

    4,7 Please try again.
    Test8

    a b

    abcd

    abcd

    4,7 Please try again.
    Test9

    ab_cd

    1234567

    4,5,6,7 Please try again.

    4.代码实现及结果样例

    使用C#编写,具体代码如下。

    这是C#自动生成的,描述GUI的Form1.Designer.cs的代码:

    namespace csharptest
    {
        partial class Form1
        {
            /// <summary>
            /// 必需的设计器变量。
            /// </summary>
            private System.ComponentModel.IContainer components = null;
    
            /// <summary>
            /// 清理所有正在使用的资源。
            /// </summary>
            /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            #region Windows 窗体设计器生成的代码
    
            /// <summary>
            /// 设计器支持所需的方法 - 不要
            /// 使用代码编辑器修改此方法的内容。
            /// </summary>
            private void InitializeComponent()
            {
                this.textBox1 = new System.Windows.Forms.TextBox();
                this.label1 = new System.Windows.Forms.Label();
                this.button1 = new System.Windows.Forms.Button();
                this.textBox2 = new System.Windows.Forms.TextBox();
                this.textBox3 = new System.Windows.Forms.TextBox();
                this.SuspendLayout();
                // 
                // textBox1
                // 
                this.textBox1.Location = new System.Drawing.Point(24, 41);
                this.textBox1.Name = "textBox1";
                this.textBox1.Size = new System.Drawing.Size(185, 21);
                this.textBox1.TabIndex = 0;
                // 
                // label1
                // 
                this.label1.AutoSize = true;
                this.label1.Location = new System.Drawing.Point(22, 14);
                this.label1.Name = "label1";
                this.label1.Size = new System.Drawing.Size(191, 12);
                this.label1.TabIndex = 1;
                this.label1.Text = "请在每个框内输入1~6个字母或数字";
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(72, 127);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 2;
                this.button1.Text = "确认";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // 
                // textBox2
                // 
                this.textBox2.Location = new System.Drawing.Point(24, 68);
                this.textBox2.Name = "textBox2";
                this.textBox2.Size = new System.Drawing.Size(185, 21);
                this.textBox2.TabIndex = 3;
                // 
                // textBox3
                // 
                this.textBox3.Location = new System.Drawing.Point(24, 95);
                this.textBox3.Name = "textBox3";
                this.textBox3.Size = new System.Drawing.Size(185, 21);
                this.textBox3.TabIndex = 4;
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(227, 159);
                this.Controls.Add(this.textBox3);
                this.Controls.Add(this.textBox2);
                this.Controls.Add(this.button1);
                this.Controls.Add(this.label1);
                this.Controls.Add(this.textBox1);
                this.Name = "Form1";
                this.Text = "EditBox";
                this.ResumeLayout(false);
                this.PerformLayout();
    
            }
    
            #endregion
    
            private System.Windows.Forms.TextBox textBox1;
            private System.Windows.Forms.Label label1;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.TextBox textBox2;
            private System.Windows.Forms.TextBox textBox3;
        }
    }

    这是其他代码,有关于判断字符串是否合法的部分,文件名为Form1.cs:

    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;
    
    namespace csharptest
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private bool check(String text)
            {
                if (text.Length <= 0) return false;
                if (text.Length > 6) return false;
                for (int i = 0; i < text.Length; i++)
                {
                    char c = text[i];
                    if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c < '0' || c > '9'))
                        return false;
                }
                return true;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (check(textBox1.Text)&&check(textBox2.Text)&&check(textBox3.Text))
                    MessageBox.Show("Accepted");
                else
                    MessageBox.Show("Please try again.");
            }
    
        }
    }

    测试用例结果图:

    测试编号 EditBox 返回结果
    Test1
    Test2
    Test3
    Test4
    Test5
    Test6
    Test7
    Test8
    Test9
  • 相关阅读:
    【BZOJ2734】【HNOI2012】集合选数(状态压缩,动态规划)
    【Luogu1879】玉米田(状态压缩,动态规划)
    【BZOJ1911】【APIO2010】特别行动队(斜率优化,动态规划)
    蒟蒻关于斜率优化DP简单的总结
    【BZOJ1010】【HNOI2008】玩具装箱(斜率优化,动态规划)
    【BZOJ4196】【NOI2015】软件包管理器(树链剖分,线段树)
    【BZOJ1483】【HNOI2009】梦幻布丁(启发式合并,平衡树)
    【BZOJ1058】【ZJOI2007】报表统计(链表,堆,Splay)
    【BZOJ1012】【JSOI2008】最大数(线段树)
    【SHOI2012】魔法树(树链剖分,线段树)
  • 原文地址:https://www.cnblogs.com/jinzhao1994/p/4376442.html
Copyright © 2011-2022 走看看