[计算机]软件测试单元测试案例
单元测试对象:嵌入式软件系统——俄罗斯方块
子模块名称:排行榜
源代码:
private void _gameOver() //游戏结束
{
// Display game over.
string s = "您的得分为:";
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); //得到当前玩家的分数
//write into file;
string path = "D:\\test1.txt"; //文件路径
try
{
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamReader strmreader = new StreamReader(fs); //建立读文件流
String[] str=new String[5];
String[] split=new String[5];
while (strmreader.Peek()!=-1) //从文件中读取数据不为空时
{
for (i = 0; i < 5; i++)
{
str[i] = strmreader.ReadLine(); //以行为单位进行读取,赋予数组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; }
//如果当前分数大于第五名,排序
else if (_score > person5) { person5 = _score; }
/