Updated tests

This commit is contained in:
2022-12-07 00:20:15 -05:00
parent cf45461ecb
commit 2af4da477e
53 changed files with 64 additions and 62 deletions

View File

@@ -44,6 +44,7 @@ package com.mattrixwv.project_euler.problems;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.StringJoiner;
public class Problem18 extends Problem{
@@ -211,13 +212,14 @@ public class Problem18 extends Problem{
//Returns the pyramid that was traversed as a string
public String getPyramid(){
solvedCheck("pyramid of numbers");
StringBuilder results = new StringBuilder();
StringJoiner results = new StringJoiner("\n");
//Loop through all elements of the list and print them
for(ArrayList<Integer> row : list){
StringJoiner rowJoiner = new StringJoiner(" ");
for(int column : row){
results.append(String.format("%2d ", column));
rowJoiner.add(String.format("%2d", column));
}
results.append('\n');
results.add(rowJoiner.toString());
}
return results.toString();
}
@@ -225,7 +227,7 @@ public class Problem18 extends Problem{
public String getTrail(){
solvedCheck("trail of the shortest path");
StringBuilder results = new StringBuilder();
StringJoiner results = new StringJoiner("->");
//Save the trail the algorithm took
ArrayList<Location> trail = new ArrayList<>();
trail.add(foundPoints.get(foundPoints.size() - 1));
@@ -236,7 +238,7 @@ public class Problem18 extends Problem{
Location toAdd = null;
while(!found){
if(loc < 0){
results.append("Error: Location < 0\n");
results.add("Error: Location < 0\n");
System.exit(1);
}
Iterator<Location> it = foundPoints.iterator();
@@ -272,10 +274,7 @@ public class Problem18 extends Problem{
}
for(Location loc : trail){
results.append(list.get(loc.yLocation).get(loc.xLocation));
if(loc.yLocation < (list.size() - 1)){
results.append("->");
}
results.add(list.get(loc.yLocation).get(loc.xLocation).toString());
}
return results.toString();