private static void doAssertWorldEvolvesLike( String initialState, String[] laterStates, boolean reverseOrder) { World world = createWorld(split(initialState, "\n")); if (reverseOrder) { Collections.reverse(world.rabbits); } for (IdxObj<String> state : enumerate(laterStates)) { world.step(); assertThat( renderWorld(world, true, false), equalToState(split(state.object, "\n"), state.index + 2)); } }
/** * @brief Note that this method steps the world, changing the input argument that is referenced. */ public static void assertWorldEvolvesLike(World world, int nSteps, String[] finalWorld) { for (int i = 0; i < nSteps; i++) { world.step(); } String[] steppedWorld = renderCompleteWorld(world, false); try { assertThat(finalWorld.length, equalTo(steppedWorld.length)); assertThat(finalWorld, equalTo(steppedWorld)); } catch (AssertionError e) { // Output the stepped world in case it's helpful for building an // assertion. for (String s : steppedWorld) { System.out.println("\"" + s + "\","); } throw e; } }