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

📄 locationtest.java

📁 现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为project的文件里.安装好后用bluej打开peoject的例子,可以进行你想要的任何变化.同时可以了解大量的源码
💻 JAVA
字号:
/** * Test implementation of the Location class. *  * @author David J. Barnes and Michael K鰈ling * @version 2006.03.30 */public class LocationTest extends junit.framework.TestCase{    /**     * Default constructor for test class LocationTest     */    public LocationTest()    {    }    /**     * Sets up the test fixture.     *     * Called before every test case method.     */    protected void setUp()    {    }    /**     * Tears down the test fixture.     *     * Called after every test case method.     */    protected void tearDown()    {    }    /**     * Test the distance method of the Location class.     */    public void testDistance()    {        boolean ok = true;        int startX = 10, startY = 10;        Location startLocation = new Location(startX, startY);                // Calculate the distance from startLocation to other        // locations around it. The distance should always        // be equal to offset.        int offset = 5;        assertEquals(startLocation.distance(            new Location(startX, startY + offset)), offset);        assertEquals(startLocation.distance(            new Location(startX + offset, startY)), offset);        assertEquals(startLocation.distance(            new Location(startX + 1, startY + offset)), offset);        assertEquals(startLocation.distance(            new Location(startX + offset, startY + 1)), offset);        assertEquals(startLocation.distance(            new Location(startX + offset, startY + offset)), offset);        assertEquals(startLocation.distance(            new Location(startX + offset - 1, startY + offset)), offset);        assertEquals(startLocation.distance(            new Location(startX + offset, startY + offset - 1)), offset);    }        /**     * Run tests of the nextLocation method of the Location class.     */    public void testAdjacentLocations()    {        int startX = 10, startY = 10;        Location startLocation = new Location(startX, startY);                // Test immediate adjacency.        // (x, y) offsets for each direction from (startX, startY).        int[][] offsets = {            { 0, 1, 0, 1, -1, 0, -1, 1, -1},            { 0, 0, 1, 1, 0, -1, -1, -1, 1},        };        for(int i = 0; i < offsets[0].length; i++) {            Location destination = new Location(startX + offsets[0][i],                                       startY + offsets[1][i]);            Location nextLocation = startLocation.nextLocation(destination);            assertEquals(nextLocation.equals(destination), true);        }    }        public void testNonAdjacentLocations()    {        int startX = 10, startY = 10;        Location startLocation = new Location(startX, startY);        // (x, y) offsets for each direction from (startX, startY).        int[][] offsets = {            { 0, 1, 0, 1, -1, 0, -1, 1, -1},            { 0, 0, 1, 1, 0, -1, -1, -1, 1},        };        // Test with destination that are not adjacent.        // Use different values for xDist and yDist for more        // varied tests.        int xDist = 7;        int yDist = 3;        for(int i = 0; i < offsets[0].length; i++) {            Location destination = new Location(startX + xDist * offsets[0][i],                                       startY + yDist * offsets[1][i]);            Location expectedNextLocation =                        new Location(startX + offsets[0][i],                                     startY + offsets[1][i]);            Location nextLocation = startLocation.nextLocation(destination);                        assertEquals(expectedNextLocation.equals(nextLocation), true);        }    }}

⌨️ 快捷键说明

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