⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scoretest.java

📁 一个贪吃蛇游戏
💻 JAVA
字号:
/**
 * @(#)ScoreTest.java
 * @Unit tests for Score class.
 *
 * @Link Scholes
 * @version 1.00 2008/7/24
 */

package Test;

import junit.framework.*;
import Data.*;

public class ScoreTest extends TestCase
{
	//The Score instance for test.
	private Score score = null;
	
	//Set up the testing environment.
	protected void setUp()
	{
		score = new Score();
	}
	
	//Returns the test suite of this class.
	public static Test suite()
	{
		return new TestSuite(Score.class);
	}
	
	//Accuracy test for contructor Score().
	public void testScore()
	{
		assertNotNull("The instance should not be null.",score);
	}
	
	//Accuracy test for getRankings().
	public void testGetRankings()
	{
		String normal[] = {" 1    MBP      DEFAULT         1000",
						   " 2    MBP      DEFAULT          900",
						   " 3    MBP      DEFAULT          800",
						   " 4    MBP      DEFAULT          700",
						   " 5    MBP      DEFAULT          600",
						   " 6    MBP      DEFAULT          500",
						   " 7    MBP      DEFAULT          400",
						   " 8    MBP      DEFAULT          300",
						   " 9    MBP      DEFAULT          200",
						   "10    MBP      DEFAULT          100"};
		String survival[] = {" 1    MBP    STAGE  10        10000",
							 " 2    MBP    STAGE   9         9000",
							 " 3    MBP    STAGE   8         8000",
							 " 4    MBP    STAGE   7         7000",
							 " 5    MBP    STAGE   6         6000",
							 " 6    MBP    STAGE   5         5000",
							 " 7    MBP    STAGE   4         4000",
							 " 8    MBP    STAGE   3         3000",
							 " 9    MBP    STAGE   2         2000",
							 "10    MBP    STAGE   1         1000"};
		
		String rankings[] = score.getRankings(true);
		
		for (int i = 0;i < 10;i ++)
		{
			assertEquals("The rankings should be correct",normal[i],rankings[i]);
		}
		
		rankings = score.getRankings(false);
		
		for (int i = 0;i < 10;i ++)
		{
			assertEquals("The rankings should be correct",survival[i],rankings[i]);
		}
	}
	
	//Accuracy test for getTempRanking().
	public void testGetTempRanking()
	{
		assertEquals("The tempRanking should be correct",1,score.getTempRanking(true,1000));
		assertEquals("The tempRanking should be correct",-1,score.getTempRanking(false,1000));
	}
	
	//Accuracy test for update().
	public void testUpdate()
	{
		score.getTempRanking(true,1000);
		score.update(true,"test","test",1000);
		String rankings[] = score.getRankings(true);
		assertEquals("The rankings should be correct"," 2   test         test         1000",rankings[1]);
	}
	
	//Accuracy test for reset().
	public void testReset()
	{
		score.getTempRanking(true,1000);
		score.update(true,"test","test",1000);
		score.reset();
		String rankings[] = score.getRankings(true);
		assertEquals("The rankings should be correct"," 2    MBP      DEFAULT          900",rankings[1]);
	}
}	//end class ScoreTest

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -