| summergroup2008's profile软件实现技术小组BlogListsNetwork | Help |
软件实现技术小组 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
July 20 主要测试用例代码及注释1#include "Elevator.h"
#include <stdio.h> const int count=21; //the number of test cases
bool testcases[count]; //record whether every test case is passed or failed void main()
{ /********************************************************* basic testing according to some functions 测试电梯运行时的显示和停止时的显示 从1层到10层,又从10层下到1层 **********************************************************/ Elevator elevator; Elevator *ep=&elevator; //test case1 cout<<"test1:测试从1层到9层运行中的电梯状态是否正确"<<endl; elevator.RequireUp(1); elevator.mysleep(ONESEC*3); //3s开门等待乘客进入 elevator.CloseDoor(); elevator.mysleep(ONESEC); //等待关门 elevator.RequireGetOff(10); //请求上到10层 int num1=0; for(int i=1;i<=8;i++) { elevator.mysleep(ONESEC*3); //3s上升一层 cout<<"第"<<i+1<<"层"; if(elevator.GetElevatorState()==::ES_CLOSED&&elevator.GetElevatorDirection()==::ED_UP&&elevator.GetArrivedFloor()==i+1) { cout<<"passed"; num1++; } else cout<<"failed"; cout<<endl; } if(num1==8) testcases[0]=true; 电梯程序模拟部分代码#include "stdafx.h"
#include "Elevator.h" //: Construction function
Elevator::Elevator() { curDir=::ED_STOP; curState=::ES_CLOSED; curFloor=1; //lastTime=0; for(int i=0;i<11;i++) { up[i]=false; down[i]=false; } trend=0; tenthNum=0; thirtiethNum=0; } Elevator::~Elevator()
{ cout << "destruct" << endl; } ELEVATORDIRECTION Elevator::GetElevatorDirection() { return curDir; } //电梯的状态,确切的说是门的状态
ELEVATORSTATE Elevator::GetElevatorState() { return curState; } //: User send requirement to mount the elevator to go up /* * @parameter * floor: the floor which the user on */ void Elevator::RequireUp(int userfloor) { //if(userfloor==MAXFLOOR) return; if(userfloor==curFloor&&curDir==::ED_STOP) { OpenDoor(); trend=1; } else { if(up[userfloor]==false) up[userfloor]=true; } if(trend==0) { int internalFloor=userfloor-curFloor; if(internalFloor>0) {trend=1;curDir=::ED_UP;} else if(internalFloor<0) {trend=-1;curDir=::ED_DOWN;} } } //: User send requirement to mount the elevator to go down
/* * @parameter * floor: the floor which the user on */ void Elevator::RequireDown(int userfloor) { //if(userfloor==1) return; if(userfloor==curFloor&&curDir==::ED_STOP) { OpenDoor(); trend=-1; } else { if(down[userfloor]==false) down[userfloor]=true; } } //: User send selection on which floor they will get off
/* * @parametr * floor: the dismount floor */ void Elevator::RequireGetOff(int userfloor) { if(trend==0) { int internalFloor=userfloor-curFloor; if(internalFloor>0) trend=1; else if(internalFloor<0) trend=-1; } if(trend==1) RequireUp(userfloor); else if(trend==-1) RequireDown(userfloor); } //: Open the door
void Elevator::OpenDoor() { if(curDir==::ED_STOP) { if(curState==::ES_CLOSED||curState==::ES_CLOSING) { curState=::ES_OPENNING; } } } //: Close the door void Elevator::CloseDoor() { if(curDir==::ED_STOP) { if(curState==::ES_OPENED||curState==::ES_OPENNING) { curState=::ES_CLOSING; } } } int Elevator::GetArrivedFloor() { return curFloor; } void Elevator::mysleep(DWORD internalTime)
{ if(curState==::ES_CLOSED) { int num=internalTime/1500; int remainder=internalTime%1500; for(int i=0;i<num;i++) { Sleep(ONEHALFSEC); if(trend==1) { curDir=::ED_UP; thirtiethNum=thirtiethNum+15; if(up[curFloor]==true) { curDir=::ED_STOP; curState=::ES_OPENNING; up[curFloor]=false; down[curFloor]=false; int j; for(j=curFloor;j<=MAXFLOOR;j++) { if(up[j]==true||down[j]==true) break; } if(j==MAXFLOOR+1) { for(j=curFloor;j>0;j--) { if(up[j]==true||down[j]) break; } if(j==0) trend=0; else trend=-1; } } else { if(i%2==0) { curFloor++; if(thirtiethNum>30) thirtiethNum=15; } } } else if(trend==-1) { curDir=::ED_DOWN; thirtiethNum=thirtiethNum-15; if(down[curFloor]==true) { curDir=::ED_STOP; curState=::ES_OPENNING; up[curFloor]=false; down[curFloor]=false; int j; for(j=curFloor;j>0;j--) { if(up[j]==true||down[j]==true) break; } if(j==0) { for(j=curFloor;j<=MAXFLOOR;j++) { if(up[j]==true||down[j]==true) break; } if(j==MAXFLOOR+1) trend=0; else trend=1; } } else { if(i%2==0) { curFloor--; if(thirtiethNum<0) thirtiethNum=15; } } } } //Sleep(remainder); int numS=remainder/100; int remainderS=remainder%100; for(int k=0;k<numS;k++) { Sleep(ONESEC/10); if(curDir==::ED_UP) thirtiethNum++; else if(curDir==::ED_DOWN) thirtiethNum--; else { if(trend==-1) curDir=::ED_DOWN; else if(trend==1) curDir=::ED_UP; } } Sleep(remainderS); if(thirtiethNum>=30) { if((trend==1&&up[curFloor]==true)||(trend==-1&&down[curFloor]==true)) { curDir=::ED_STOP; curState=::ES_OPENNING; if(up[curFloor]==true) up[curFloor]=false; if(down[curFloor]==true) down[curFloor]=false; thirtiethNum=0; } } else if(thirtiethNum<=0) { if((trend==1&&up[curFloor]==true)||(trend==-1&&down[curFloor]==true)) { curDir=::ED_STOP; curState=::ES_OPENNING; if(up[curFloor]==true) up[curFloor]=false; if(down[curFloor]==true) down[curFloor]=false; thirtiethNum=0; } } } else { int num=internalTime/1000; int remainder=internalTime%1000; int done=0; if(num>0) { for(int i=0;i<num;i++) { Sleep(ONESEC); if(curState==::ES_OPENNING) { curState=::ES_OPENED; tenthNum=10; } if(curState==::ES_CLOSING) { curState=::ES_CLOSED; tenthNum=0; } if(curState==::ES_OPENED) { if(num-i>=5) done=1; } } if(done==1) curState=::ES_CLOSING; int numS=remainder/100; int remainderS=remainder%100; for(int k=0;k<numS;k++) { Sleep(ONESEC/10); if(curState==::ES_OPENNING) tenthNum++; if(curState==::ES_CLOSING) tenthNum--; } Sleep(remainderS); if(tenthNum>=10) { curState=::ES_OPENED; tenthNum=10; } if(tenthNum<=0) { curState=::ES_CLOSED; tenthNum=0; } } else if(num==0) { int numS=internalTime/100; int remainderS=internalTime%100; for(int k=0;k<numS;k++) { Sleep(ONESEC/10); if(curState==::ES_OPENNING) tenthNum++; if(curState==::ES_CLOSING) tenthNum--; } Sleep(remainderS); if(tenthNum>=10) { curState=::ES_OPENED; tenthNum=10; } if(tenthNum<=0) { curState=::ES_CLOSED; tenthNum=0; } } } } 电梯系统测试部分8其他测试
电梯系统测试部分7
电梯系统测试部分6
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|