Скачиваний:
51
Добавлен:
02.05.2014
Размер:
478.72 Кб
Скачать

8.3 Тестирование функции формирования выходного файла f3 и f4.

Тест 1.

Цель теста: проверить функционирование программы при безошибочных данных в файлах F1 и F2.

Содержание теста:

  1. Вывод.

Данная программа была протестирована для всех представленных в таблице решений входных условий. Тесты не обнаружили ошибок в работе программы. Следовательно, программа отвечает заявленным внешним спецификациям.

Приложение А. Текст программы.

//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

#include "Unit2.h"

#include "Unit3.h"

# include <stdio.h>

# include <string.h>

# include <stdlib.h>

# include <conio.h>

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

int l1,l2;

TForm1 *Form1;

AnsiString s1,s2,s3,s4;

bool fl,sg1;

//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)

{

StringGrid1->Cells[0][0]="Аббревиатура";

StringGrid1->Cells[1][0]="Название факультета";

StringGrid2->Cells[0][0]="Аббревиатура";

StringGrid2->Cells[1][0]="Название кафедры";

StringGrid2->Cells[2][0]="Количество работающих";

StringGrid3->Cells[0][0]="Название факультета";

StringGrid3->Cells[1][0]="Название кафедры";

StringGrid3->Cells[2][0]="Количество работающих";

StringGrid4->Cells[0][0]="Название факультета";

StringGrid4->Cells[1][0]="Общее количество людей";

fl=false;

sg1=false;

l1=-1;

l2=-1;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N2Click(TObject *Sender)

{int i,j,k;

char c;

AnsiString s;

Op->Execute() ;

if(Op->FileName!="")

{

if(Op->FilterIndex ==1) //input F1

{ for(i=1;i<StringGrid1->RowCount;i++)StringGrid1->Rows[i]->Clear();

StringGrid1->RowCount =2;

LB->Items->LoadFromFile(Op->FileName);

for(i=0;i<LB->Items->Count;i++) //первое слово

{s1=LB->Items->Strings[i];

j=1;

c=s1[j];s2="";

while(c!=' ')

{s2+=c;

j++;

c=s1[j];

}//while

while(c==' ')

{j++;

c=s1[j];

}

s3=c;j++;

while(j<=s1.Length())

{c=s1[j];

s3+=c;

j++;

}//while

for(k=1;k<StringGrid1->RowCount-1;k++)

if(StringGrid1->Cells[0][k]==s2)fl=true;

if(!fl)

{StringGrid1->Cells[0][StringGrid1->RowCount-1]=s2;

StringGrid1->Cells[1][StringGrid1->RowCount-1]=s3;

StringGrid1->RowCount++;

}//if

else//открываем окно и запрашиваем на редактирование

{fl=false;

Form2->Caption="Измените аббревиатуру";

Form2->Show() ;

Form2->Tag =1;

Form1->Tag=-3;

Form2->Edit1->Text=s2;

Form2->Edit2->Text=s3;

//Form3->Edit4->Text=s5;

while(Form1->Tag==-3)Application->ProcessMessages();

Form2->Close() ;

}

} //for

//Prov1;

}

else //input F2

{for(i=1;i<StringGrid2->RowCount;i++)StringGrid2->Rows[i]->Clear();

StringGrid2->RowCount =2;

LB->Items->LoadFromFile(Op->FileName);

for(i=0;i<LB->Items->Count;i++) //первое слово

{s1=LB->Items->Strings[i];

j=1;

c=s1[j];s2="";

while(c!=' ') //первое слово

{s2+=c;

j++;

c=s1[j];

}//while

while(c==' ') //пробелы между первым и вторым

{j++;

c=s1[j];

}

s4="";

while(c!=' ') //второе слово

{s4+=c;

j++;

c=s1[j];

}//while

while(c==' ') //пробелы м/у ними

{j++;

c=s1[j];

}

s3=c;j++;

while(j<=s1.Length()) //последнее слово

{c=s1[j];

s3+=c;

j++;

}//while

for(k=1;k<StringGrid2->RowCount-1;k++)

if(StringGrid2->Cells[1][k]==s4)fl=true;

for(k=1;k<=s3.Length();k++)

switch(s3[k])

{

case '1':continue ;

case '2':continue ;

case '3':continue ;

case '4':continue ;

case '5':continue ;

case '6':continue ;

case '7':continue ;

case '8':continue ;

case '9':continue ;

case '0':continue ;

default: fl=true;

}

if(!fl)

{StringGrid2->Cells[0][StringGrid2->RowCount-1]=s2;

StringGrid2->Cells[1][StringGrid2->RowCount-1]=s4;

StringGrid2->Cells[2][StringGrid2->RowCount-1]=s3;

StringGrid2->RowCount++;

}//if

else//открываем окно и запрашиваем на редактирование

{fl=false;

Form3->Caption="Измените данные";

Form3->Show() ;

Form3->Tag =1;

Form1->Tag=-3;

Form3->Edit1->Text=s2;

Form3->Edit2->Text=s4;

Form3->Edit3->Text=s3;

//Form3->Edit4->Text=s5;

while(Form1->Tag==-3)Application->ProcessMessages();

Form3->Close() ;

}

} //for

}

}//if filename

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N4Click(TObject *Sender)

{

Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button7Click(TObject *Sender)

{int i,j,k,sum;

for(i=1;i<StringGrid3->RowCount;i++)StringGrid3->Rows[i]->Clear();

StringGrid3->RowCount =2;

k=1;

for(i=1;i<StringGrid1->RowCount-1;i++)

for(j=1;j<StringGrid2->RowCount-1;j++)

if(StringGrid1->Cells[0][i]==StringGrid2->Cells[0][j])

{StringGrid3->Cells[0][k]=StringGrid1->Cells[1][i];

StringGrid3->Cells[1][k]=StringGrid2->Cells[1][j];

StringGrid3->Cells[2][k]=StringGrid2->Cells[2][j];

k++;

StringGrid3->RowCount++;

}

//SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

//SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1);

for(i=1;i<StringGrid4->RowCount;i++)StringGrid4->Rows[i]->Clear();

StringGrid4->RowCount =2;

sum=0;

k=1;

for(i=1;i<StringGrid3->RowCount;i++)

for(j=i;j<StringGrid3->RowCount;j++)

if(StringGrid3->Cells[0][i]==StringGrid3->Cells[0][j])

{//Application->MessageBoxA("","",1);

sum+=atoi(StringGrid3->Cells[2][j].c_str() );

}

else

{StringGrid4->Cells[0][k]=StringGrid3->Cells[0][i];

StringGrid4->Cells[1][k]=sum;

StringGrid4->RowCount++;

k++;sum=0;

i=j-1;break;

}

//}

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{

Form2->Caption ="Добавить данные";

Form2->Show() ;

Form2->Tag =1;

Form2->Edit1->Text="";

Form2->Edit2->Text="";

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)

{

if(l1>0 && l1<StringGrid1->RowCount-1)

{

Form2->Caption ="Редактировать данные";

Form2->Show() ;

Form2->Tag =2;

Form2->Edit1->Text=StringGrid1->Cells[0][l1];

Form2->Edit2->Text=StringGrid1->Cells[1][l1];

Form1->Tag =l1;

}//if

else Application->MessageBoxA("Выберите строку","Внимание",MB_OK);

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)

{

Form3->Caption ="Добавить данные";

Form3->Show() ;

Form3->Tag =1;

Form3->Edit1->Text="";

Form3->Edit2->Text="";

Form3->Edit3->Text="";

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button5Click(TObject *Sender)

{

if(l2>0 && l2<StringGrid2->RowCount-1)

{

Form3->Caption ="Редактировать данные";

Form3->Show() ;

Form3->Tag =2;

Form3->Edit1->Text=StringGrid2->Cells[0][l2];

Form3->Edit2->Text=StringGrid2->Cells[1][l2];

Form3->Edit3->Text=StringGrid2->Cells[2][l2];

Form1->Tag =l2;

}//if

else Application->MessageBoxA("Выберите строку","Внимание",MB_OK);

}

//---------------------------------------------------------------------------

void __fastcall TForm1::StringGrid2SelectCell(TObject *Sender, int ACol,

int ARow, bool &CanSelect)

{

//Application->MessageBoxA("dg","dfg",MB_OK);

l2=ARow;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)

{int i,j;

if(l1==-1 || l1==0 || l1>StringGrid1->RowCount-2) {Application->MessageBoxA("Выберите строку","Внимание",MB_OK);return;}

StringGrid1->Rows[l1]->Clear();

for(i=l1+1;i<StringGrid1->RowCount;i++)

{ //Application->MessageBoxA("dg","dfg",MB_OK);

StringGrid1->Cells[0][i-1]=StringGrid1->Cells[0][i] ;

StringGrid1->Cells[1][i-1]=StringGrid1->Cells[1][i] ;

}

StringGrid1->RowCount--;

StringGrid1->Rows[StringGrid1->RowCount-1]->Clear();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button6Click(TObject *Sender)

{int i,j;

if(l2==-1 || l2==0 || l2>StringGrid2->RowCount-2) {Application->MessageBoxA("Выберите строку","Внимание",MB_OK);return;}

StringGrid2->Rows[l2]->Clear();

for(i=l2+1;i<StringGrid2->RowCount;i++)

{ //Application->MessageBoxA("dg","dfg",MB_OK);

StringGrid2->Cells[0][i-1]=StringGrid2->Cells[0][i] ;

StringGrid2->Cells[1][i-1]=StringGrid2->Cells[1][i] ;

StringGrid2->Cells[2][i-1]=StringGrid2->Cells[2][i] ;

}

StringGrid2->RowCount--;

StringGrid2->Rows[StringGrid2->RowCount-1]->Clear();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::StringGrid1SelectCell(TObject *Sender, int ACol,

int ARow, bool &CanSelect)

{

l1=ARow;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N3Click(TObject *Sender)

{int i,j;

if(Sa->Execute() && Sa->FileName!="")

if(Sa->FilterIndex==1)

{LB->Clear() ;

for(i=1;i<StringGrid1->RowCount-1;i++)

{s1=StringGrid1->Cells[0][i]+" "+StringGrid1->Cells[1][i];

LB->Items->Add(s1);

}

LB->Items->SaveToFile(Sa->FileName);

}

else

if(Sa->FilterIndex==2)

{LB->Clear() ;

for(i=1;i<StringGrid2->RowCount-1;i++)

{s1=StringGrid2->Cells[0][i]+" "+StringGrid2->Cells[1][i]+" "+StringGrid2->Cells[2][i];

LB->Items->Add(s1);

}

LB->Items->SaveToFile(Sa->FileName);

}

else

{LB->Clear() ;

for(i=1;i<StringGrid3->RowCount-1;i++)

{s1=StringGrid3->Cells[0][i]+" "+StringGrid3->Cells[1][i]+" "+StringGrid3->Cells[2][i];

LB->Items->Add(s1);

}

LB->Items->SaveToFile(Sa->FileName);

}

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button8Click(TObject *Sender)

{

Form1->Close();

Form2->Close();

Form3->Close();

}

//---------------------------------------------------------------------------

26

Соседние файлы в папке Курсовой - Специфицирование и тестирование программ