首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >测试Harness要求输入而不是使用所写的内容(家庭作业)。

测试Harness要求输入而不是使用所写的内容(家庭作业)。
EN

Stack Overflow用户
提问于 2015-05-05 20:03:21
回答 1查看 66关注 0票数 0

我应该用一个家庭作业测试工具来检查一个模块是否工作。到目前为止,我只做了两次测试,但是当我调试程序时,它要求我输入,而不是使用我在代码中提供的内容。我做错什么了?

代码语言:javascript
复制
void retirement_eligibility(bool full_time, int age, int service_years, bool &eligibility);

using namespace std;

int main()

{
     bool full_time,
          eligibility;

     int  age,
          service_years,
          contribution;


     full_time = 0;
     eligibility = 0;
     service_years = 0;
     age = 0;



     retirement_eligibility(1, 30, 1, eligibility);
     if (eligibility == true){
          cout << "Test 1 passed" << endl;
     }
     else {
          cout << "Test #1 FAILED!" << endl;
          cout << " - Expected eligibility 1, got" << eligibility << endl;

     }
     retirement_eligibility(1, 29, 1, eligibility);
     if (eligibility == 2){
          cout << "Test 2 passed" << endl;
     }
     else {
          cout << "Test #2 FAILED!" << endl;
          cout << " - Expected eligibility 2, got" << eligibility << endl;

     }
}

void retirement_eligibility(bool full_time, int age, int service_years, bool &eligibility)
{

     cout << "Enter age: ";
     cin >> age;
     cout << "Enter years served: ";
     cin >> service_years;
     cout << "Are you a full time eployee?(1 for yes, 2 for no): ";
     cin >> full_time;

     if (full_time == true){
          if (age >= 30 && service_years >= 1){
               eligibility = true;
          }

          else{
               eligibility = false;
          }
     }

     else{
          eligibility = false;
     }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-05 20:17:23

代码语言:javascript
复制
void retirement_eligibility(bool full_time, int age, int service_years, bool &eligibility)
{
    cout << "Enter age: ";
    cin >> age;
    cout << "Enter years served: ";
    cin >> service_years;
    cout << "Are you a full time eployee?(1 for yes, 2 for no): ";
    cin >> full_time;

    ...
}

它要求输入,因为您在函数中要求输入。传递给它的内容并不重要,因为您正在用函数本身中所要求的输入来更改它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30062237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档