【发布时间】:2020-07-08 07:49:55
【问题描述】:
我有一个这样定义的类:
public class Monster {
public static final int ARENA_SIZE = 480;
public int health; //can be negative since it will then be removed
public int speed;
public int counter;
public int x; //current position
public int y; //current position
public mapObject next;
public void nextAlgorithm(mapObject[][] map) {
aNode[][] aNodeMap = newANodeMap(map); //1. create a new aNodeMap
PriorityQueue<aNode> pq = newPriorityMap(aNodeMap[this.x][this.y]); //2. create a new priority queue with starting point added
aNode current;
while (pq.isEmpty() == false) {
current = pq.poll();
if (endPointReached(current.x, current.y)) //3. Is the end point reached?
break;
aNode[] neighbours = findNeighbour(current.x, current.y, aNodeMap); //4. The end point isn't reached, find me the neigbours
for (aNode neighbour : neighbours) //5. process all my neighbours
processNeighbour(current, neighbour, pq);
}
next = updateNext(aNodeMap[ARENA_SIZE - 1][ARENA_SIZE - 1], this.x, this.y); //6. Update my next after all these work
}
简单来说,有一个算法需要其他类的输入,mapObject,也是我自己写的另一个包。
我的问题是,除了
import MapObject.*;
在 junit 中,我可以在其中初始化一个夹具
@Before
有没有更好的方法?
【问题讨论】:
-
它如何需要
mapObject类的对象?看起来它创建了一个(newANodeMap. -
在 nextAlgorithm 的函数签名中,需要一个 mapObject[][] 来进行复制。因此,它需要一个 mapObject 类的对象。其次,它创建一个 newANodeMap 是事实,假设它需要一个 mapObject[][] 对象来复制。因此,我需要在测试用例中使用 mapObject。请问我应该修改问题的哪一部分以使其他人更清楚?
标签: java intellij-idea junit