?? maptest.java
字號:
/**
* @(#)MapTest.java
* @Unit tests for Map class.
*
* @Link Scholes
* @version 1.00 2008/7/24
*/
package Test;
import junit.framework.*;
import Data.*;
public class MapTest extends TestCase
{
//The Map instance for test.
private Map map = null;
//Set up the testing environment.
protected void setUp()
{
map = new Map();
}
//Returns the test suite of this class.
public static Test suite()
{
return new TestSuite(Map.class);
}
//Accuracy test for contructor Map().
public void testMap()
{
assertNotNull("The instance should not be null.",map);
}
//Accuracy test for getDifficulty().
public void testGetDifficulty()
{
assertEquals("The difficulty should be correct",564,map.getDifficulty());
//Set up a new Map.
map.load(true,"absurd");
assertEquals("The difficulty should be correct",996,map.getDifficulty());
}
//Accuracy test for getFood().
public void testGetFood()
{
int food[] = map.getFood();
for (int i = 0;i < 4;i ++)
{
assertEquals("The food should be correct",25,food[i]);
}
//Set up a new Map.
map.load(true,"absurd");
food = map.getFood();
assertEquals("The food should be correct",25,food[0]);
assertEquals("The food should be correct",25,food[1]);
assertEquals("The food should be correct",35,food[2]);
assertEquals("The food should be correct",15,food[3]);
}
//Accuracy test for getInfo().
public void testGetInfo()
{
int info[][] = map.getInfo();
for (int i = 0;i < 15;i ++)
{
for (int j = 0;j < 15;j ++)
{
assertEquals("The info should be correct",0,info[i][j]);
}
}
}
//Accuracy test for getName().
public void testGetName()
{
assertEquals("The name should be correct","DEFAULT",map.getName());
//Set up a new Map.
map.load(true,"absurd");
assertEquals("The name should be correct","absurd",map.getName());
}
//Accuracy test for setMap().
public void testSetMap()
{
int food[] = new int[4];
int info[][] = new int[15][15];
for (int i = 0;i < 4;i ++)
{
food[i] = 22 + 2 * i;
}
for (int i = 0;i < 15;i ++)
{
for (int j = 0;j < 15;j ++)
{
info[i][j] = 0;
}
}
map.setMap("test",info,food);
assertEquals("The name should be correct","test",map.getName());
assertEquals("The info should be correct",info,map.getInfo());
assertEquals("The food should be correct",food,map.getFood());
}
} //end class MapTest
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -