0


软件测试技术 实验一:黑盒测试1

实验一 实验报告

文章目录

小组成员

小组成员结对测试组成员

实验目的

能熟练应用黑盒测试技术进行测试用例设计,能对测试用例进行优化设计。

实验内容

“隔一天问题”程序要求如下:输入为年、月、日三个变量,输出为输入的隔一天后的年、月、日。例如,输入为2001年2月10日,则输出为2001年2月12日;输入为2000年2月29日,则输出为2000年3月2日等。输入年份要求在1922-2030之间。

程序的主要算法

关键代码

//将string转为char数组并判断输入是否为正整数
int checkNum(string s) {
    int flag = 1;
    for (int i = 0; i < s.length(); i++) {
        if ((int)s[i] < 48 || (int)s[i] > 57) {
            flag = 0;
            break;
        }
    }
    return flag;
}
//获取用户输入
    string n0;
    int year = 0, month = 0, day = 0, isLeap = 0;
    cout << "请输入年月日" << endl;
    cout << "年:";
    //判断输入的n0是否符合要求
    while (year < 1922 || year > 2030) {
        cin >> n0;
        //判断输入的n0是否符合要求
        while (!checkNum(n0)) {
            cout << "Year取值无效\n请输入正整数,不要输入负数或者小数或字母:" ;
            cin >> n0;
        }
        year = s2i(n0);//string转为int存储 
        if (year < 1922 || year > 2030) {
            cout << "Year取值无效\n请输入1922到2030之间的数字:";
        }
    }
    year = s2i(n0);//string转为int存储 
    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) isLeap = 1;
    cout << "月:";
    while (month < 1 || month>12) {
        cin >> n0;
        //判断输入的n0是否符合要求
        while (!checkNum(n0)) {
            cout << "Month取值无效\n请输入正整数,不要输入负数或者小数或字母:" ;
            cin >> n0;
        }
        month = s2i(n0);//string转为int存储 
        if (month < 1 || month>12) {
            cout << "Month取值无效\n请输入1到12之间的数字:" ;
        }
    }
    cout << "日:";
    if (month == 1 || month == 3 || month == 7 || month == 8 || month == 10 || month == 12) {//大月
        while (day < 1 || day > 31) {
            cin >> n0;
            //判断输入的n0是否符合要求
            while (!checkNum(n0)) {
                cout << "Day取值无效\n请输入正整数,不要输入负数或者小数或字母:" ;
                cin >> n0;
            }
            day = s2i(n0);//string转为int存储 
            if (day < 1 || day > 31) {
                cout << "Day取值无效\n请输入1到31之间的整数:";
            }
        }
    }
    else if (month == 4 || month == 5 || month == 6 || month == 9 || month == 11) {//小月
        while (day < 1 || day > 30) {
            cin >> n0;
            //判断输入的n0是否符合要求
            while (!checkNum(n0)) {
                cout << "Day取值无效\n请输入正整数,不要输入负数或者小数或字母:";
                cin >> n0;
            }
            day = s2i(n0);//string转为int存储 
            if (day < 1 || day > 30) {
                cout << "Day取值无效\n请输入1到30之间的整数:" << endl;
            }
        }
    }
    else if (month == 2 && isLeap) {//闰年2月
        while (day < 1 || day > 29) {
            cin >> n0;
            //判断输入的n0是否符合要求
            while (!checkNum(n0)) {
                cout << "Day取值无效\n请输入正整数,不要输入负数或者小数或字母:";
                cin >> n0;
            }
            day = s2i(n0);//string转为int存储 
            if (day < 1 || day > 29) {
                cout << "Day取值无效\n请输入1到29之间的整数:";
            }
        }
    }
    else {//平年二月
        while (day < 1 || day > 28) {
            cin >> n0;
            //判断输入的n0是否符合要求
            while (!checkNum(n0)) {
                cout << "Day取值无效\n请输入正整数,不要输入负数或者小数或字母:";
                cin >> n0;
            }
            day = s2i(n0);//string转为int存储 
            if (day < 1 || day > 28) {
                cout << "Day取值无效\n请输入1到28之间的整数:";
            }
        }
    }
//根据合理范围的年月日得到输出
void Solution(int year, int month, int day, int isLeap) {
    int nYear = 0, nMonth = 0, nDay = 0;
    if (month == 1 || month == 3 || month == 5 || month == 8 || month == 10) {//大月
        nYear = year;
        if (day == 30 || day == 31) {
            nMonth = month + 1;
            if (day == 30) nDay = 1;
            else nDay = 2;
        }
        else {
            nMonth = month;
            nDay = day + 2;
        }
    }
    else if (month == 4 || month == 6 || month == 9 || month == 11) {//小月
        nYear = year;
        if (day == 29 || day == 30) {
            nMonth = month + 1;
            if (day == 29) nDay = 1;
            else nDay = 2;
        }
        else {
            nMonth = month;
            nDay = day + 2;
        }
    }
    else if (month == 2 && isLeap) {//闰年2月
        nYear = year;
        if (day == 28 || day == 29) {
            nMonth = month + 1;
            if (day == 28) nDay = 1;
            else nDay = 2;
        }
        else {
            nMonth = month;
            nDay = day + 2;
        }
    }
    else if (month == 2 && !isLeap) {//平年2月
        nYear = year;
        if (day == 27 || day == 28) {
            nMonth = month + 1;
            if (day == 27) nDay = 1;
            else nDay = 2;
        }
        else {
            nMonth = month;
            nDay = day + 2;
        }
    }
    else {//12月
        if (day == 30 || day == 31) {
            nYear = year + 1;
            nMonth = 1;
            if (day == 30) nDay = 1;
            else nDay = 2;
        }
        else {
            nYear = year;
            nMonth = month;
            nDay = day + 2;
        }
    }
    cout << "隔一天的年月日为:" << nYear << "-" << nMonth << "-" << nDay << endl;
}

流程图

输入检测
Created with Raphaël 2.3.0 

 checkNum 

 flag = 1 

 i<s.length()? 

 !48<s[i]<57 

 flag=0 

 return flag 

 end 

 yes 

 no 

 yes 

 no 
计算结果

测试用例

弱健壮等价类

等价类划分

输入年月日Y1:非数字M1:非数字D1:非数字Y2:整数 x<1922M2:负整数和零D2:负整数和零Y3:整数 x>2030M3:小数D3:小数Y5:小数M4:2D4:1~26Y6:闰年M5:12D5:27Y7:平年M6:month有31天,不包括12月(1 3 5 7 8 10)D6:28M7:month有30天(4 6 9 11)D7:29D8:30D9:31

弱一般等价类测试用例规则

WR16 = {M6, {D4, D5, D6, D7}, {Y6, Y7}}

WR17 = {M6, D8, {Y6, Y7}}

WR18 = {M6, D9, {Y6, Y7}}

WR19 = {M7, {D4, D5, D6}, {Y6, Y7}}

WR20 = {M7, {D7}, {Y6, Y7}}

WR21 = {M7, {D8}, {Y6, Y7}}

WR22 = {M4, {D4, D5}, {Y6}}

WR23 = {M4, {D6}, {Y6}}

WR24 = {M4, {D7}, {Y6}}

WR25 = {M4, {D4}, {Y7}}

WR26 = {M4, {D5}, {Y7}}

WR27 = {M4, {D6}, {Y7}}

WR28 = {M5, {D4, D5, D6, D7}, {Y6, Y7}}

WR29 = {M5, {D8}, {Y6, Y7}}

WR30 = {M5, {D9}, {Y6, Y7}}

弱健壮等价类测试用例

用例号yearmonthday预期输出WR12000-112Month取值无效WR220002.512Month取值无效WR32000@12Month取值无效WR420005012Month取值无效WR520006-1Day取值无效WR6200062.5Day取值无效WR720006@Day取值无效WR82000650Day取值无效WR92000230Day取值无效WR102001229Day取值无效WR112000431Day取值无效WR12-1612Year取值无效WR132.5612Year取值无效WR14@612Year取值无效WR155000612Year取值无效WR1620007292000-7-31WR1720007302000-8-1WR1820007312000-8-2WR1920006282000-6-30WR2020006292000-7-1WR2120006302000-7-2WR2220002272000-2-29WR2320002282000-3-1WR2420002292000-3-2WR2520012262001-2-28WR2620012272001-3-1WR2720012282001-3-2WR28200012292000-12-31WR29200012302001-1-1WR30200012312001-1-2

弱健壮等价类测试结果

边界值分析法

使用边界值分析法设计该问题的测试用例,并检验测试结果。此处采取五点取样法。在year、month、day的有效值范围两侧分别取样,其他两项取有效值进行测试。WN19为三项均取有效值,作为对照组。

边界值分析法测试用例

yearmonthday预期输出WN11921615Year取值无效WN219226151922-6-17WN319236151923-6-17WN420296152029-6-17WN520306152030-6-17WN62031615Year取值无效WN72000015Month取值无效WN820001152000-1-17WN920002152000-2-17WN10200011152000-11-17WN11200012152000-12-17WN1220001315Month取值无效WN13200070Day取值无效WN142000712000-7-3WN152000722000-7-4WN1620007302000-8-1WN1720007312000-8-2WN182000732Day取值无效WN1920006152000-6-17

边界值分析法测试结果

判定表测试方法

判定桩划分

M1 = {1,3,5,7,8,10} M2 = {4,6,9,11} M3 = {2} M4 = {12}

Y1 = {1922到2030间的所有闰年} Y2 = {1922到2030间的所有平年}

D1 = {1,2,…,26} D2 = {27} D3 = {28} D4 = {29} D5 = {30} D6 = {31}

判定表

条件情况1情况2情况3情况4情况5情况6情况7情况8情况9情况10情况11情况12情况13情况14情况15c1:Month是否属于M1YYYNNNNNNNNNNNNc2:Month是否属于M2NNNYYYNNNNNNNNNc3:Month是否属于M3NNNNNNYYYYYYNNNc4:Month是否属于M4NNNNNNNNNNNNYYYc5:Year是否属于Y1------YYYNNN---c6:Year是否属于Y2------NNNYYY---c7:Day是否属于D1-NN----NNYNN-NNc8:Day是否属于D2-NN----NNNYN-NNc9:Day是否属于D3-NN---NYNNNY-NNc10:Day是否属于D4-NNNYNNNYNNN-NNc11:Day是否属于D5NYNNNYNNNNNNNYNc12:Day是否属于D6NNYNNNNNNNNNNNY动作a1:Year不变 Month不变 Day+2✓✓✓✓✓a2:Year不变 Month+1 Day=1✓✓✓✓a3:Year不变 Month+1 Day=2✓✓✓✓a4:Year+1 Month=1 Day=1✓a5:Year+1 Month=1 Day=2✓

判定表测试方法测试用例

情况123456789101112131415测试用例2000-7-102000-7-302000-7-312000-6-102000-6-292000-6-302000-2-102000-2-282000-2-292001-2-102001-2-272001-2-282000-12-102000-12-302000-12-31预期输出2000-7-122000-8-12000-8-22000-6-122000-7-12000-7-22000-2-122000-3-12000-3-22001-2-122001-3-12001-3-22000-12-122001-1-12001-1-2

判定表测试方法测试结果

对所测试组程序的评价

对于闰年2月1到27日,平年2月1到26日的数据,不能得到正确的预期输出。

对于无效和未预料的输入情况,不能给出清晰的提示信息,全部是相同的提示信息。

对于输出,有“输入的日期”此项不必要的输出。

输入数据时的提示很清晰。


本文转载自: https://blog.csdn.net/m0_54082634/article/details/129345227
版权归原作者 巳弥子OUC 所有, 如有侵权,请联系我们删除。

“软件测试技术 实验一:黑盒测试1”的评论:

还没有评论