等价类划分的延伸

1 问题描述

在第二篇博客描述的问题上,在增加两个输入框,使三个输入同时进行等价类判断,只有当三个输入全部有效时才可判定成功,若存在某个输入或者多个输入非法,则判定失败,因此我们需要重新划分等价类,并重新确定测试用例,使之符合这次的问题要求,测试用例要同时考虑到三个输入的情况。

2 有效等价类的划分

  有效等价类 编号 无效等价类 编号
字符长度 输入1:1-6 1 输入1:0||>>7 7
  输入2:1-6 2 输入2:0||>7 8
  输入3:1-6 3 输入3:0||>7 9
字符类型 输入1:a-z,A-Z,0-9 4 输入1 非字母数字 10
 

输入2:a-z,A-Z,0-9

5 输入2 非字母数字 11
 

 输入3:a-z。A-Z.0-9

6

输入3:非字母数字

12

3测试用例

测试用例 覆盖等价类 结果
183e yur 7ufA 123456 succeed
183, yu4 eud4 1 2 3 10 5 6 failed
183e yu4;e r4 1 2 3 4 11 6 failed
eyd rdr rud. 1 2 3 4 5 12 failed
1234567 ee rr 7 2 3 4 5 6 failed
erd 12345rt 4 1 8 3 4 5 6 failed
ed erfd eeeeeeee 1 2 9 4 5 6 failed
we re, 1 8 3 4 11 12 failed
wer, 34d. er5d 1 2 3 10 11 6 failed
efffffe3 e r 1 2 3 4 7 8 faied
哈哈 ndn ee 1 3 8 10 11 6 failed
null 10 11 12 7 8 9 failed

4代码实现

依然选择javascrip+html进行前台输入框的编写和后台的对输入的判断

<html>
<head>
<script type="text/javascript">
function foo(){
   var str=document.getElementById('str').value;
   var str1=document.getElementById('str1').value;
   var str2=document.getElementById('str2').value;
       var st=/^[a-zA-Z0-9][a-zA-Z0-9]{0,5}$/; 
        if(st.test(str)&&st.test(str1)&&st.test(str2))       
       {
           window.alert("succeed");
       } 
       else{
        window.alert("failed");
       }
   
}
</script>
</head>

<body>
<br><input type="text" name="str" id="str" /></br>
<br><input type="text" name="str1" id="str1" /></br>
<br><input type="text" name="str2" id="str2"/></br>
<button type="button" name="button" id="button" onclick="foo();">OK</button> 
</body>
</html>

5 部分结果展示

原文地址:https://www.cnblogs.com/lichongjie/p/4375260.html