Computer test unit test example, [computer] software test unit test case.doc

[Computer] Software testing unit test case

Unit Test Object: Embedded Software System - Tetris

Submodule name: leaderboard

Source code:

private void _gameOver() //The game is over

{

// Display game over.

string s = "Your score is:";

string a1="";

char[] A ={ };

int i=1;

_blockSurface.FontStyle = new Font(FontFace, BigFont);_blockSurface.FontFormat.Alignment = StringAlignment.Near;

_blockSurface.DisplayText = "GAME OVER !!";

string sc = Convert.ToString(_score); //Get the current player's score

//write into file;

string path = "D:\\test1.txt"; //File path

try

{

FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);

StreamReader strmreader = new StreamReader(fs); //Create a read file stream

String[] str=new String[5];

String[] split=new String[5];

while (strmreader.Peek()!=-1) //When the data read from the file is not empty

{

for (i = 0; i < 5; i++)

{

str[i] = strmreader.ReadLine(); //Read in line units, assign array str[i]

split[i] = str[i].Split(':')[1];split[i]

}

}

person1 = Convert.ToInt32(split[0]); // split[0]的值赋予第一名

person2 = Convert.ToInt32(split[1]); // split[1]的值赋予第二名

person3 = Convert.ToInt32(split[2]); // split[2]的值赋予第三名

person4 = Convert.ToInt32(split[3]); // split[3]的值赋予第四名

person5 = Convert.ToInt32(split[4]); // split[4]的值赋予第五名

strmreader.Close(); //关闭流

fs.Close();

FileStream ffs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);

StreamWriter sw = new StreamWriter(ffs); //建立写文件流

if (_score > person1) { person5 = person4; person4 = person3; person3 = person2; person2 = person1; person1 = _score; } //如果当前分数大于第一名,排序

else if (_score > person2) {person5 = person4; person4 = person3; person3 = person2;person2 = _score; } //如果当前分数大于第二名,排序

//如果当前分数大于第三名,排序

else if (_score > person3) { person5 = person4; person4 = person3;person3 = _score; }

//如果当前分数大于第四名,排序

else if (_score > person4) { person5 = person4; person4 = _score; }

//If the current score is greater than the fifth place, sort

else if (_score > person5) { person5 = _score; }

/