movetest.java

来自「实现火星车,全部由java写成」· Java 代码 · 共 52 行

JAVA
52
字号
package cn.nasa;

import junit.framework.TestCase;

public class MoveTest extends TestCase {
	private Move move;
	private Coordinate coordinate;
	private Direction N, S, W, E;

	protected void setUp() throws Exception {
		super.setUp();
		move = new Move();

		N = new Direction();
		S = new Direction();
		W = new Direction();
		E = new Direction();

		N.setLeft(W);
		W.setLeft(S);
		S.setLeft(E);
		E.setLeft(N);

		N.setRight(E);
		E.setRight(S);
		S.setRight(W);
		W.setRight(N);
			
		coordinate=new Coordinate(2,1);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testExec() {
		move.setdirection(N);
		move.setcoordinate(coordinate);
		coordinate=(Coordinate) move.exec();
		assertEquals(2+N.getX_offset(), coordinate.getX_coordinate());
		assertEquals(1+N.getY_offset(), coordinate.getY_coordinate());
	}

	public void testSetcoordinate() {
		move.setcoordinate(coordinate);
	}

//	public void testSetdirection() {
//	}

}

⌨️ 快捷键说明

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