/** * The actual test, which asserts that ToyBot has won every round against SittingDuck. * * @param event Details about the completed battle. */ @Override public void onBattleCompleted(BattleCompletedEvent event) { // Return the results in order of getRobotNames. BattleResults[] battleResults = event.getIndexedResults(); // Sanity check that results[1] is ToyBot (not strictly necessary, but illustrative). BattleResults ToyBotResults = battleResults[1]; String robotName = ToyBotResults.getTeamLeaderName(); assertEquals("Check that results[1] is ToyBot", robotName, "lto.ToyBot*"); // Check to make sure ToyBot won every round. assertEquals("Check ToyBot winner", ToyBotResults.getFirsts(), getNumRounds()); }
private void printResultsData(BattleCompletedEvent event) { // Do not print out if no result file has been specified and the GUI is enabled if ((setup.resultsFilename == null && (!setup.exitOnComplete || windowManager.isGUIEnabled()))) { return; } PrintStream out = null; FileOutputStream fos = null; try { if (setup.resultsFilename == null) { out = Logger.realOut; } else { File f = new File(setup.resultsFilename); try { fos = new FileOutputStream(f); out = new PrintStream(fos); } catch (IOException e) { Logger.logError(e); } } if (out != null) { BattleResultsTableModel resultsTable = new BattleResultsTableModel( event.getSortedResults(), event.getBattleRules().getNumRounds()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); resultsTable.print(new PrintStream(baos)); out.append(StringUtil.toBasicLatin(baos.toString())); } } finally { FileUtil.cleanupStream(out); FileUtil.cleanupStream(fos); } }