Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 测试用例在VS中既不通过也不失败_Visual Studio_Unit Testing_Visual Studio 2013_Vs Unit Testing Framework - Fatal编程技术网

Visual studio 测试用例在VS中既不通过也不失败

Visual studio 测试用例在VS中既不通过也不失败,visual-studio,unit-testing,visual-studio-2013,vs-unit-testing-framework,Visual Studio,Unit Testing,Visual Studio 2013,Vs Unit Testing Framework,在VS Express 2013中,我针对规范文件中编写的某些测试用例运行以下程序。代码和等级库文件的一部分如下所示: struct DOB { int date; int month; int year; }; int stringToValue(char* temp) { int num = 0; while (*temp != '-' && *temp != '\0') { if (((*temp) >= '0

在VS Express 2013中,我针对规范文件中编写的某些测试用例运行以下程序。代码和等级库文件的一部分如下所示:

struct DOB {
    int date;
    int month;
    int year;
};

int stringToValue(char* temp) {
    int num = 0;
    while (*temp != '-' && *temp != '\0') {
        if (((*temp) >= '0') && ((*temp) <= '9')) {
            num = num * 10 + ((*temp) - '0');
            ++temp;
        }
    }
    return num;
}

int isValidFormat(char* dob) {
    int length = 0;
    for (int i = 0; dob[i] != '\0'; ++i) {
        if (!((dob[i] >= '0' && dob[i] <= '9' || dob[i] == '-')))
            return 0;
        ++length;
    }
    return length;
}

int function(int value1, int value2) {
    if (value1>value2) {
        return 2;
    }

    else if (value1<value2) {
        return 1;
    }
    else
        return 0;
}

int isLeap(int year) {
    if ((year % 4 == 0) && !(year % 100)) {
        return 1;
    }

    else {
        if (year % 400 == 0)
            return 1;
        else
            return 0;
    }
}

int isValid(struct DOB d) {
    if (d.year>0) {
        if (d.month>0 && d.month <= 12) {
            if (d.month == 2 && isLeap(d.year) == 1) {
                if (d.date>0 && d.date <= 29) {
                    return 1;
                }
                else if (d.date > 0 && d.date <= 28) {
                    return 1;
                }
                else
                    return 0;
            }
            else if (d.date == 1 || d.date == 3 || d.date == 5 || d.date == 7 || d.date == 8 || d.date == 10 || d.date == 12){
                if (d.date > 0 && d.date <= 31) {
                    return 1;
                }
                else
                    return 0;
            }
            else {
                if (d.date > 0 && d.date <= 30) {
                    return 1;
                }
                else
                    return 0;
            }
        }
        else {
            return 0;
        }
    }
    else {
        return 0;
    }
}

int isOlder(char* dob1, char* dob2) {
    struct DOB d1, d2;

    if (isValidFormat(dob1)!= 10 && isValidFormat(dob2) != 10)
        return -1;

    d1.date = stringToValue(dob1);
    d2.date = stringToValue(dob2);
    d1.month = stringToValue(dob1 + 3);
    d2.month = stringToValue(dob2 + 3);
    d1.year = stringToValue(dob1 + 6);
    d2.year = stringToValue(dob2 + 6);

    if (isValid(d1) == 1 && isValid(d2) == 1) {
        if (function(d1.year, d2.year) != 0)
            return function(d1.year, d2.year);
        else if (function(d1.month, d2.month) != 0)
            return function(d1.month, d2.month);
        else
            return function(d1.date, d2.date);
    }

    else {
        return -1;
    }
}
当我在本地编译器上运行以下测试用例时,我得到了预期的输出。但是当我在上面的代码上运行测试时,我既不会通过也不会失败上面的测试用例。老实说,我不确定出了什么问题。这似乎是VS特定的问题,而不是我的代码的问题。

错误的错误条件

// if (isValidFormat(dob1)!= 10 && isValidFormat(dob2) != 10)
if (isValidFormat(dob1)!= 10 || isValidFormat(dob2) != 10)
    return -1;
当只有1种格式无效时,代码称为弱函数
stringToValue()
,它有一个带有无效输入的无限循环

int stringToValue(char* temp) {
    int num = 0;
    while (*temp != '-' && *temp != '\0') {
        if (((*temp) >= '0') && ((*temp) <= '9')) {
            num = num * 10 + ((*temp) - '0');
            ++temp;  //  Move this to outside `if()` test
        }
    }
    return num;
}
int-stringToValue(char*temp){
int num=0;
而(*temp!='-'&&&*temp!='\0'){
如果((*temp)>='0')&(*temp)错误的错误条件

// if (isValidFormat(dob1)!= 10 && isValidFormat(dob2) != 10)
if (isValidFormat(dob1)!= 10 || isValidFormat(dob2) != 10)
    return -1;
当只有1种格式无效时,代码称为弱函数
stringToValue()
,它有一个带有无效输入的无限循环

int stringToValue(char* temp) {
    int num = 0;
    while (*temp != '-' && *temp != '\0') {
        if (((*temp) >= '0') && ((*temp) <= '9')) {
            num = num * 10 + ((*temp) - '0');
            ++temp;  //  Move this to outside `if()` test
        }
    }
    return num;
}
int-stringToValue(char*temp){
int num=0;
而(*temp!='-'&&&*temp!='\0'){

如果((*temp)>='0')&(*temp)您是否尝试在VS上进行一些调试,以了解代码的哪一部分没有按预期进行分支?
isValidFormat(“0000000000”)
isValidFormat(-->-”
都返回非零。没有太多的格式检查。
stringToValue()
是一个无限循环,如果它被非数字、非
-
字符调用。建议将函数
设为静态
,因为它仅在受控使用时有用。
Assert::AreEqual
-->无效的C代码。您使用的是C编译器吗?不要垃圾邮件标记!这显然不是C代码。您是否尝试过对VS to k进行调试现在,代码的哪一部分没有像您预期的那样分支?
isValidFormat(“0000000000”)
isValidFormat(“------------”)都返回非零。格式检查不多。
stringToValue()
是一个无限循环,如果它被非数字、非
-
字符调用。建议将函数
设为静态
,因为它只在受控使用时有用。
Assert::AreEqual
-->无效的C代码。您使用的是C编译器吗?不要垃圾标签!这显然不是C代码。谢谢!这还有一些其他小问题,是原因。但是,有没有更好的方式来格式化检查,你会建议吗?我很想知道你的想法!谢谢!这是原因,还有其他一些小问题。但是,有没有更好的方式来格式化检查,你会建议吗?我很想知道你的想法!