import java.util.ArrayList; public class LandscapeTester { private static final String SUCCESS = "PA" + "SS"; private static void later() { System.out.println("Later tasks have not been checked yet."); System.out.println("Complete the current task first, then run the tester again."); } private static boolean states(Landscape s, boolean[][] expected) { if (s.getRows() != expected.length || s.getCols() != expected[0].length) return false; for (int r = 0; r < expected.length; r++) for (int c = 0; c < expected[0].length; c++) if (s.getCell(r,c) == null || s.getCell(r,c).getAlive() != expected[r][c]) return false; return true; } public static void main(String[] args) { System.out.println("========================================"); System.out.println("Landscape Tester"); System.out.println("========================================\n"); boolean[][] pattern = {{true,false,true},{false,true,false}}; Landscape s; try { s = new Landscape(pattern); } catch (Exception e) { System.out.println("Keep working on Task 2."); System.out.println("Hint: The boolean-grid constructor must create a Cell at every location."); later(); return; } if (states(s, pattern) && "X X\n X \n".equals(s.toString())) { Landscape none = new Landscape(2,3,0.0); none.reset(); Landscape all = new Landscape(2,3,1.0); all.reset(); boolean resetOK = true; for (int r=0;r<2;r++) for(int c=0;c<3;c++) resetOK &= none.getCell(r,c)!=null && !none.getCell(r,c).getAlive() && all.getCell(r,c)!=null && all.getCell(r,c).getAlive(); if (!resetOK) { System.out.println("Keep working on Task 2."); System.out.println("Hint: reset() must create a Cell at every location using initialChance."); later(); return; } System.out.println(SUCCESS + " - Task 2: Landscape basics"); } else { System.out.println("Keep working on Task 2."); System.out.println("Hint: Check constructors, accessors, and the X/blank text representation."); later(); return; } Landscape n = new Landscape(new boolean[][]{{false,false,false},{false,false,false},{false,false,false}}); ArrayList corner=n.getNeighbors(0,0), edge=n.getNeighbors(0,1), center=n.getNeighbors(1,1); if (corner.size()==3 && edge.size()==5 && center.size()==8) { System.out.println(SUCCESS + " - Task 3: Neighbors"); } else { System.out.println("Keep working on Task 3."); System.out.println("Hint: A 3x3 corner has 3 neighbors, an edge has 5, and the center has 8."); later(); return; } boolean[][] blinker = {{false,false,false},{true,true,true},{false,false,false}}; Landscape b = new Landscape(blinker); b.advance(); boolean[][] vertical = {{false,true,false},{false,true,false},{false,true,false}}; if (!states(b, vertical)) { System.out.println("Keep working on Task 5."); System.out.println("Hint: Build the new generation while reading neighbors only from the original Landscape."); later(); return; } b.advance(); if (states(b, blinker)) { System.out.println(SUCCESS + " - Task 5: Advance one generation"); System.out.println("\nLandscape work complete."); } else { System.out.println("Keep working on Task 5."); System.out.println("Hint: A blinker should return to its original state after two generations."); } } }