CS代考 package finalproject;

package finalproject;

import finalproject.system.Tile;
import finalproject.system.TileType;

Copyright By PowCoder代写 加微信 powcoder

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;

import finalproject.tiles.PlainTile;
import finalproject.tiles.DesertTile;
import finalproject.tiles.MountainTile;
import finalproject.tiles.FacilityTile;
import finalproject.tiles.MetroTile;
import finalproject.tiles.ZombieInfectedRuinTile;
import finalproject.TilePriorityQ;
import finalproject.GraphTraversal;

public class MiniTester {

public static void main(String[] args) {
// TODO Auto-generated method stub
String testName = “”;
if (args.length > 0)
testName = args[0];

// run all tests if no arguments
boolean pass = true;
int total = 0, passed = 0;
if (testName.isEmpty() || testName.equals(“testTile1”)) {
System.out.println(“Testing testTile1.”);
boolean ret;
pass &= (ret = testTile1());
System.out.println(“Test testTile1 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testTile2”)) {
System.out.println(“Testing testTile2.”);
boolean ret;
pass &= (ret = testTile2());
System.out.println(“Test testTile2 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testBFS1”)) {
System.out.println(“Testing testBFS1.”);
boolean ret;
pass &= (ret = testBFS1());
System.out.println(“Test testBFS1 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testDFS1”)) {
System.out.println(“Testing testDFS1.”);
boolean ret;
pass &= (ret = testDFS1());
System.out.println(“Test testDFS1 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testBFS2”)) {
System.out.println(“Testing testBFS2.”);
boolean ret;
pass &= (ret = testBFS2());
System.out.println(“Test testBFS2 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testDFS2”)) {
System.out.println(“Testing testDFS2.”);
boolean ret;
pass &= (ret = testDFS2());
System.out.println(“Test testDFS2 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testEdges”)) {
System.out.println(“Testing testEdges.”);
boolean ret;
pass &= (ret = testEdges());
System.out.println(“Test testEdges done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testNeighbors1”)) {
System.out.println(“Testing testNeighbors1.”);
boolean ret;
pass &= (ret = testNeighbors1());
System.out.println(“Test testNeighbors1 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testNeighbors2”)) {
System.out.println(“Testing testNeighbors2.”);
boolean ret;
pass &= (ret = testNeighbors2());
System.out.println(“Test testNeighbors2 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testPathCost”)) {
System.out.println(“Testing testPathCost.”);
boolean ret;
pass &= (ret = testPathCost());
System.out.println(“Test testPathCost done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testRemoveMin”)) {
System.out.println(“Testing testRemoveMin.”);
boolean ret;
pass &= (ret = testRemoveMin());
System.out.println(“Test testRemoveMin done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testUpdateKeys”)) {
System.out.println(“Testing testUpdateKeys.”);
boolean ret;
pass &= (ret = testUpdateKeys());
System.out.println(“Test testUpdateKeys done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testSPathGenerateGraph1”)) {
System.out.println(“Testing testSPathGenerateGraph1.”);
boolean ret;
pass &= (ret = testSPathGenerateGraph1());
System.out.println(“Test testSPathGenerateGraph1 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testSPathGenerateGraph2”)) {
System.out.println(“Testing testSPathGenerateGraph2.”);
boolean ret;
pass &= (ret = testSPathGenerateGraph2());
System.out.println(“Test testSPathGenerateGraph2 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testFindPath1Arg1”)) {
System.out.println(“Testing testFindPath1Arg1.”);
boolean ret;
pass &= (ret = testFindPath1Arg1());
System.out.println(“Test testFindPath1Arg1 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testFindPath1Arg2”)) {
System.out.println(“Testing testFindPath1Arg2.”);
boolean ret;
pass &= (ret = testFindPath1Arg2());
System.out.println(“Test testFindPath1Arg2 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testFindPath2Args”)) {
System.out.println(“Testing testFindPath2Args.”);
boolean ret;
pass &= (ret = testFindPath2Args());
System.out.println(“Test testFindPath2Args done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testFindPath3Args”)) {
System.out.println(“Testing testFindPath3Args.”);
boolean ret;
pass &= (ret = testFindPath3Args());
System.out.println(“Test testFindPath3Args done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testFPathGenerateGraph1”)) {
System.out.println(“Testing testFPathGenerateGraph1.”);
boolean ret;
pass &= (ret = testFPathGenerateGraph1());
System.out.println(“Test testFPathGenerateGraph1 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testFPathGenerateGraph2”)) {
System.out.println(“Testing testFPathGenerateGraph2.”);
boolean ret;
pass &= (ret = testFPathGenerateGraph2());
System.out.println(“Test testFPathGenerateGraph2 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testSPathGenerateGraphWithMetro”)) {
System.out.println(“Testing testSPathGenerateGraphWithMetro.”);
boolean ret;
pass &= (ret = testSPathGenerateGraphWithMetro());
System.out.println(“Test testSPathGenerateGraphWithMetro done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testFPathGenerateGraphWithMetro”)) {
System.out.println(“Testing testFPathGenerateGraphWithMetro.”);
boolean ret;
pass &= (ret = testFPathGenerateGraphWithMetro());
System.out.println(“Test testFPathGenerateGraphWithMetro done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testSSPathGenerateGraph”)) {
System.out.println(“Testing testSSPathGenerateGraph.”);
boolean ret;
pass &= (ret = testSSPathGenerateGraph());
System.out.println(“Test testSSPathGenerateGraph done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testSafeFindPath1”)) {
System.out.println(“Testing testSafeFindPath1.”);
boolean ret;
pass &= (ret = testSafeFindPath1());
System.out.println(“Test testSafeFindPath1 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testSafeFindPath2”)) {
System.out.println(“Testing testSafeFindPath2.”);
boolean ret;
pass &= (ret = testSafeFindPath2());
System.out.println(“Test testSafeFindPath2 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testSafeFindPath3”)) {
System.out.println(“Testing testSafeFindPath3.”);
boolean ret;
pass &= (ret = testSafeFindPath3());
System.out.println(“Test testSafeFindPath3 done.”);
passed += ret ? 1 : 0;
if (testName.isEmpty() || testName.equals(“testSafeFindPath4”)) {
System.out.println(“Testing testSafeFindPath4.”);
boolean ret;
pass &= (ret = testSafeFindPath4());
System.out.println(“Test testSafeFindPath4 done.”);
passed += ret ? 1 : 0;

if (pass) {
System.out.println(“Pass all.”);
System.exit(0);
System.out.println(“Pass ” + passed + “/” + total + “.”);
System.exit(1);

public static class TestTile extends Tile {
// For testing

public static boolean testTile1() { // 1 point

t = new PlainTile();
if (t.distanceCost != 3 || t.timeCost != 1 || t.damageCost != 0) {
System.out.println(“Wrong costs for PlainTile.”);
return false;

t = new DesertTile();
if (t.distanceCost != 2 || t.timeCost != 6 || t.damageCost != 3) {
System.out.println(“Wrong costs for DesertTile.”);
return false;

t = new MountainTile();
if (t.distanceCost != 100 || t.timeCost != 100 || t.damageCost != 100) {
System.out.println(“Wrong costs for MountainTile.”);
return false;

return true;

public static boolean testTile2() { // 1 point

t = new FacilityTile();
if (t.distanceCost != 1 || t.timeCost != 2 || t.damageCost != 0) {
System.out.println(“Wrong costs for FacilityTile.”);
return false;

t = new MetroTile();
if (t.distanceCost != 1 || t.timeCost != 1 || t.damageCost != 2) {
System.out.println(“Wrong costs for MetroTile.”);
return false;

t = new ZombieInfectedRuinTile();
if (t.distanceCost != 1 || t.timeCost != 3 || t.damageCost != 5) {
System.out.println(“Wrong costs for ZombieInfectedRuinTile.”);
return false;

return true;

// 0 — 1 — 2 — 3 — 4
public static boolean testBFS1() { // 1 point
Tile[] tiles = new Tile[5];
for (int i = 0; i < tiles.length; ++i) { tiles[i] = new TestTile(); tiles[i].nodeID = i; for (int i = 0; i < tiles.length - 1; ++i) tiles[i].addNeighbor(tiles[i + 1]); ArrayList arr = GraphTraversal.BFS(tiles[0]);

System.out.println(“Expected:”);
for (int i = 0; i < tiles.length; ++i) { System.out.print(tiles[i].nodeID + " "); System.out.println(); System.out.println("Yours:"); for (int i = 0; i < arr.size(); ++i) { System.out.print(arr.get(i).nodeID + " "); System.out.println(); if (arr.size() != tiles.length) return false; for (int i = 0; i < tiles.length; ++i) { if (tiles[i] != arr.get(i)) { return false; return true; // 0 -- 1 -- 2 -- 3 -- 4 public static boolean testDFS1() { // 1 point Tile[] tiles = new Tile[5]; for (int i = 0; i < tiles.length; ++i) { tiles[i] = new TestTile(); tiles[i].nodeID = i; for (int i = 0; i < tiles.length - 1; ++i) tiles[i].addNeighbor(tiles[i + 1]); ArrayList arr = GraphTraversal.DFS(tiles[0]);

System.out.println(“Expected:”);
for (int i = 0; i < tiles.length; ++i) { System.out.print(tiles[i].nodeID + " "); System.out.println(); System.out.println("Yours:"); for (int i = 0; i < arr.size(); ++i) { System.out.print(arr.get(i).nodeID + " "); System.out.println(); if (arr.size() != tiles.length) return false; for (int i = 0; i < tiles.length; ++i) { if (tiles[i] != arr.get(i)) { return false; return true; * 3 -- 0 -- 1 public static boolean testBFS2() { // 1 point Tile[] tiles = new Tile[5]; for (int i = 0; i < tiles.length; ++i) { tiles[i] = new TestTile(); tiles[i].nodeID = i; for (int i = 1; i < tiles.length; ++i) tiles[0].addNeighbor(tiles[i]); ArrayList arr = GraphTraversal.BFS(tiles[0]);

System.out.println(“Expected:”);
for (int i = 0; i < tiles.length; ++i) { System.out.print(tiles[i].nodeID + " "); System.out.println(); System.out.println("Yours:"); for (int i = 0; i < arr.size(); ++i) { System.out.print(arr.get(i).nodeID + " "); System.out.println(); if (arr.size() != tiles.length) return false; if (tiles[0] != arr.get(0)) { return false; return true; * 3 -- 0 -- 1 public static boolean testDFS2() { // 1 point Tile[] tiles = new Tile[5]; for (int i = 0; i < tiles.length; ++i) { tiles[i] = new TestTile(); tiles[i].nodeID = i; for (int i = 1; i < tiles.length; ++i) tiles[0].addNeighbor(tiles[i]); ArrayList arr = GraphTraversal.DFS(tiles[0]);

System.out.println(“Expected:”);
for (int i = 0; i < tiles.length; ++i) { System.out.print(tiles[i].nodeID + " "); System.out.println(); System.out.println("Yours:"); for (int i = 0; i < arr.size(); ++i) { System.out.print(arr.get(i).nodeID + " "); System.out.println(); if (arr.size() != tiles.length) return false; if (tiles[0] != arr.get(0)) { return false; return true; public static Graph graph = null; public static HashMap tile2id = null;
public static ArrayList tiles = null;
* 0 1 2 3 4
* +—————
* 0| 3 2
* 1| 1 5
* 2| 4 5
* 3| 2
public static void buildGraph() {
if (graph != null)
tiles = new ArrayList();
tile2id = new HashMap();
for (int i = 0; i < 5; ++i) { TestTile t = new TestTile(); t.nodeID = i; tile2id.put(t, i); tiles.add(t); graph = new Graph(tiles); graph.addEdge(tiles.get(0), tiles.get(1), 3); graph.addEdge(tiles.get(0), tiles.get(3), 2); graph.addEdge(tiles.get(1), tiles.get(2), 1); graph.addEdge(tiles.get(1), tiles.get(3), 5); graph.addEdge(tiles.get(2), tiles.get(3), 4); graph.addEdge(tiles.get(2), tiles.get(4), 5); graph.addEdge(tiles.get(3), tiles.get(4), 2); public static boolean testEdges() { // 2 points int[][] edges = new int[5][5]; for (int i = 0; i < 5; ++i) for(int j = 0; j < 5; ++j) edges[i][j] = 0; edges[0][1] = 3; edges[0][3] = 2; edges[1][2] = 1; edges[1][3] = 5; edges[2][3] = 4; edges[2][4] = 5; edges[3][4] = 2; buildGraph(); ArrayList allEdges = graph.getAllEdges();
if (allEdges.size() != 7) {
System.out.println(“There should be 7 edges.”);
return false;
for (Graph.Edge e: allEdges) {
Tile s = e.getStart();
Tile t = e.getEnd();
if (!tile2id.containsKey(s))
return false;
i = tile2id.get(s);
if (!tile2id.containsKey(t))
return false;
j = tile2id.get(t);
if (edges[i][j] == e.weight)
edges[i][j] = 0;
System.out.println(“Wrong edge or duplicate edge.”);
return false;

return true;

public static boolean testNeighbors1() { // 1 points
buildGraph();
ArrayList neighbors = graph.getNeighbors(tiles.get(0));
if (neighbors.size() != 2) {
System.out.println(“Tile 0 should have 2 neighbors”);
return false;
if (neighbors.get(0) == tiles.get(1) && neighbors.get(1) == tiles.get(3))
return true;
if (neighbors.get(0) == tiles.get(3) && neighbors.get(1) == tiles.get(1))
return true;
System.out.println(“Tile 0 should have tiles 1 and 3 as neighbors.”);
return false;

public static boolean testNeighbors2() { // 1 points
buildGraph();
ArrayList neighbors = graph.getNeighbors(tiles.get(3));
if (neighbors.size() != 1) {
System.out.println(“Tile 3 should have 1 neighbor”);
return false;
if (neighbors.get(0) == tiles.get(4))
return true;
System.out.println(“Tile 3 should have tile 4 as neighbor.”);
return false;

public static boolean testPathCost() { // 2 points
buildGraph();
ArrayList path = new ArrayList();
for (int i = 0; i < 5; ++i) path.add(tiles.get(i)); double cost = graph.computePathCost(path); if (cost != 10) { System.out.println("Cost of path 0-1-2-3-4 should be 10."); return false; return true; public static boolean testRemoveMin() { // 3 points ArrayList tiles = new ArrayList();
int a[] = { 3, 1, 8, 4, 9, 5, 2, 6, 10, 7 };
for (int i = 0; i < a.length; ++i) { Tile t = new TestTile(); t.costEstimate = a[i]; 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com