package nav;
import BasicDataType.Map;
import BasicDataType.Position;
import BasicDataType.Rect;
import BasicDataType.Vector;
import junit.framework.TestCase;
public class SearchTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testSearchAlgorithm() {
//Search search = new Search();
fail("Not yet implemented");
}
public void testGetNext() {
Map map = new Map((byte)10);
Position currentPos = new Position();
currentPos.setPosition(new Vector(5,5),0);
//Position destinationPos = new Position(new Vector(2,0),0);
// for(int y=1; y < 4; y++){
// map.propagateOccupied((byte)1, (byte)y);
// }
// for(int y=1; y < 5; y++){
// map.propagateEmpty((byte)0, (byte)y);
// }
// for(int x=1; x < 3; x++){
// map.propagateEmpty((byte)x, (byte)0);
// }
Rect bound = new Rect(5, 6, 6,5);
Search search = new Search(map);
for(int i = 0; i < 5 ; i++) {
currentPos = search.getNext(currentPos, map, bound);
if (currentPos == null) {
bound.setRect(0, 9, 9, 0);
currentPos = new Position(new Vector(5,5), 3);
for(int j = 0; j < 5 ; j++) {
currentPos = search.getNext(currentPos, map, bound);
map.propagateEmpty((byte)currentPos.pos.x,(byte)currentPos.pos.y);
map.showMap();
System.out.println();
}
return;
}
map.propagateEmpty((byte)currentPos.pos.x,(byte)currentPos.pos.y);
map.showMap();
System.out.println();
}
//map.showMap();
//System.out.println(search.getNext(currentPos, map, bound).pos.x);
//System.out.println(search.getNext(currentPos, map, bound).pos.y);
//System.out.println();
//System.out.println(search.getNext(currentPos, map, bound).pos.y);
//map.getVisitedSquares();
}
public void testClosestPath() {
Map map = new Map((byte)5);
Position currentPos = new Position(new Vector(0,0),0);
Position destinationPos = new Position(new Vector(2,0),0);
for(int y=0; y < 3; y++){
map.propagateOccupied((byte)1, (byte)y);
}
Position nextPosition = new Position();
Search search = new Search(map);
//search.closestPath(map, currentPos, destinationPos,nextPosition);
//map.showMap();
//System.out.println(search.closestPath(map, currentPos, destinationPos,nextPosition));
//assertTrue(search.closestPath(map, currentPos, destinationPos, nextPosition) == 16);
}
public void testCheckZero() {
Map map = new Map((byte)5);
// Position curPosition = new Position(new Vector(0,0),0);
// Position pos = new Position(new Vector(1,1),0);
// int step = 3;
// int min = Integer.MAX_VALUE;
// Rect bound = new Rect(0,0,4,4);
// Position minPos = new Position();
// Search search = new Search(map);
//search.checkZero(map, pos, curPosition, step, min, bound, minPos);
}
public void testAllSearched() {
Map map = new Map((byte)5);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
map.propagateOccupied((byte)i, (byte)j);
}
}
//map.showMap();
Rect bound = new Rect(0,0,3,3);
Search search = new Search(map);
//assertTrue(search.allSearched(map, bound));
//assertEquals(search.allSearched(map, bound), true);
bound.setRect(2, 2, 4, 4);
//System.out.println(search.allSearched(map, bound));
//assertTr(search.allSearched(map, bound) == false);
//assertFalse(search.allSearched(map, bound));
}
}