StoreCredit { static List<String> convertFileToOutput(String filepath) throws IOException { FileReader fileReader = new FileReader(filepath); BufferedReader bufferedReader = new BufferedReader(fileReader); String firstLine = bufferedReader.readLine(); Integer numberOfProblems = Integer.valueOf(firstLine); List<String> rv = new ArrayList<String>(numberOfProblems); for (int i = 0; i < numberOfProblems; i++) { int credit = Integer.valueOf(bufferedReader.readLine()); bufferedReader.readLine(); String items = bufferedReader.readLine(); Problem problem = new Problem(credit, items); List<Integer> solution = problem.solveProblem(); StringBuilder output = new StringBuilder(); output.append("Case #"); output.append(i+1); output.append(":"); for (Integer index: solution) { output.append(" "); output.append(index); } rv.add(output.toString()); } bufferedReader.close(); return rv; }    }
@Test public void testFile1() throws IOException { System.out.println("testFile1"); List<String> output = StoreCredit.convertFileToOutput("/Users/ai/Programming/javakata/codejam/store_credit/src/small_example.txt"); for (String elem: output) System.out.println(elem); }
@Test public void testFile2() throws IOException { System.out.println("A-small-practice.in\n"); List<String> output = StoreCredit.convertFileToOutput("/Users/ai/Programming/javakata/codejam/store_credit/src/A-small-practice.in"); FileWriter fw = new FileWriter("/Users/ai/Programming/javakata/codejam/store_credit/src/A-small-practice.out"); BufferedWriter bw = new BufferedWriter(fw); for (String elem: output) bw.write(elem + "\n"); bw.close(); }
@Test public void testFile3() throws IOException { System.out.println("A-large-practice.in\n"); List<String> output = StoreCredit.convertFileToOutput("/Users/ai/Programming/javakata/codejam/store_credit/src/A-large-practice.in"); FileWriter fw = new FileWriter("/Users/ai/Programming/javakata/codejam/store_credit/src/A-large-practice.out"); BufferedWriter bw = new BufferedWriter(fw); for (String elem: output) bw.write(elem + "\n"); bw.close(); }