In VS Express 2013, I run the following program against certain test cases written in a spec file. The code and a portion of the spec file is as follows:
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;
}
}
TEST_METHOD(isOlderinvalid)
{
Assert::AreEqual(-1, isOlder("1000", "15-07-2000"), L"isOlder: invalid input case failed", LINE_INFO());
Assert::AreEqual(-1, isOlder("15-07-2000", "000"), L"isOlder: invalid input case failed", LINE_INFO());
Assert::AreEqual(-1, isOlder("15-0A-2000", "15-07-2000"), L"isOlder: invalid input case failed", LINE_INFO());
Assert::AreEqual(-1, isOlder("15-13-2000", "15-07-2000"), L"isOlder: invalid input case failed", LINE_INFO());
Assert::AreEqual(-1, isOlder("29-02-2001", "15-07-2000"), L"isOlder: invalid input case failed", LINE_INFO());
}
When I run the following test cases on my local compiler, I get the expected output. But when I run the tests on the above code, I neither pass nor fail the above test cases. I'm honestly not sure what's wrong. It seems like a VS-specific problem rather than a problem with my code. Could someone PLEASE PLEASE help me out?
Aucun commentaire:
Enregistrer un commentaire