기능은 다음과 같습니다C++ 어떻게 함수를 테스트하여 오류가 발생합니까? 검증이 필요
int hire(Payroll * p) throw(out_of_range, logic_error)
{
// error if no holes left
if (staffcount == MAX_EMPLOYEES)
throw (out_of_range("Hire: Too many employees"));
// spin down holes looking for a hole.
for (int i = 0; i < MAX_EMPLOYEES; ++i) {
Payroll *current = staff[i].get(); // get the pointer
if (current == 0) { // it is empty
appay newpay(p); // convert *Payrollto auto_ptr
staff[i] =newpay;
staffcount++; // one more staff
return i; // return index
} else {
// do nothing. Hole is filled
}
}
// should never get here
throw (logic_error("no holes, but count ok")); }
가 나는 out_of_range
오류를 던져 테스트 할 수 있어요,하지만 난 어떤 logic_error
생각할 수 없다.
try {
for (int i = 0; i<11; i++){
hr.hire(new Payroll("Prog M. Er", 55757575));
hr.showAllStaff(" after hires");
}
} catch (out_of_range e) {
cout << "Out of range error: " << e.what() << endl;
cout << "DEBUG: carry on processing - line 177 was tested\n";
}
가이 기능을위한 logic_error 테스트를 작성하는 방법에 어떤 도움을 크게 감상 할 수있다 :
여기 out_of_range
의 주요 내 테스트입니다! 감사합니다.
C++의 예외 사양이 다소 손상되었습니다. http://www.gotw.ca/publications/mill22.htm –
MAX_EMPLOYEES를 2로 설정하고 3 번째 직원을 고용하려고하는 것처럼 보입니다.나는 이것이 논리 오류가 아니라 오버플로가되어야한다고 생각한다. –
사실 토마스입니다. 그리고 나는 이것을 위해 논리 오류를 찾기가 어렵다는 것을 알게됩니다. 이 함수에 대한 테스트를 생성해야합니다. 두 유형 모두에서 오류가 발생합니다. 다른 것을 생각할 수 있는지 알려주세요. 고맙습니다. Adri – Adri