From 8d4d20aeaea5e02be0861765790716a1dcd1919d Mon Sep 17 00:00:00 2001 From: Nicolas Delsaux Date: Thu, 8 Dec 2016 13:10:21 +0100 Subject: [PATCH] =?UTF-8?q?S=C3=A9paration=20des=20tests=20r=C3=A9cup?= =?UTF-8?q?=C3=A9r=C3=A9s=20du=20jeu=20et=20des=20tests=20de=20performance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ndx/codingame/hypersonic/Playfield.java | 127 +++---- .../ndx/codingame/hypersonic/InGameTest.java | 31 +- .../codingame/hypersonic/PerformanceTest.java | 319 ++++++++++++++++++ 3 files changed, 397 insertions(+), 80 deletions(-) create mode 100644 multiplayer/hypersonic/src/test/java/org/ndx/codingame/hypersonic/PerformanceTest.java diff --git a/multiplayer/hypersonic/src/main/java/org/ndx/codingame/hypersonic/Playfield.java b/multiplayer/hypersonic/src/main/java/org/ndx/codingame/hypersonic/Playfield.java index 29b5300..79e351b 100644 --- a/multiplayer/hypersonic/src/main/java/org/ndx/codingame/hypersonic/Playfield.java +++ b/multiplayer/hypersonic/src/main/java/org/ndx/codingame/hypersonic/Playfield.java @@ -3,8 +3,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -import java.util.Map; -import java.util.TreeMap; import org.ndx.codingame.hypersonic.content.Bomb; import org.ndx.codingame.hypersonic.content.Box; @@ -18,32 +16,31 @@ import org.ndx.codingame.hypersonic.content.Wall; import org.ndx.codingame.lib2d.discrete.DiscretePoint; import org.ndx.codingame.lib2d.discrete.Playground; -import org.ndx.codingame.lib2d.discrete.ScoredDirection; public class Playfield extends Playground { public static final class ToCompleteString implements ContentVisitor { - @Override public String visitBomb(Bomb bomb) { return "|B("+bomb.delay+","+bomb.range+")"; } - @Override public String visitNothing(Nothing nothing) { return "| . "; } - @Override public String visitBox(Box box) { return "| 0 "; } - @Override public String visitWall(Wall wall) { return "| X "; } - @Override public String visitGamer(Gamer gamer) { return "|G("+gamer.bombs+","+gamer.range+")"; } - @Override public String visitItem(Item item) { return "| I("+item.type+") "; } - @Override public String visitFire(Fire fire) { return "| F "; } - @Override public String visitFireThenItem(FireThenItem fire) { return "| F->I "; } + @Override public String visitBomb(final Bomb bomb) { return "|B("+bomb.delay+","+bomb.range+")"; } + @Override public String visitNothing(final Nothing nothing) { return "| . "; } + @Override public String visitBox(final Box box) { return "| 0 "; } + @Override public String visitWall(final Wall wall) { return "| X "; } + @Override public String visitGamer(final Gamer gamer) { return "|G("+gamer.bombs+","+gamer.range+")"; } + @Override public String visitItem(final Item item) { return "| I("+item.type+") "; } + @Override public String visitFire(final Fire fire) { return "| F "; } + @Override public String visitFireThenItem(final FireThenItem fire) { return "| F->I "; } } public static final class ToPhysicalString extends ContentAdapter { private ToPhysicalString() { super("."); } - @Override public String visitBox(Box box) { return "0"; } - @Override public String visitWall(Wall box) { return "X"; } + @Override public String visitBox(final Box box) { return "0"; } + @Override public String visitWall(final Wall box) { return "X"; } } private static PlaygroundDeriver playgroundDeriver = new PlaygroundDeriver(); private Playfield next; private Playground opportunities; - public Playfield(int width, int height) { + public Playfield(final int width, final int height) { super(width, height); } @@ -51,28 +48,28 @@ public Playfield(int width, int height) { * Cloning constructor * @param playground */ - public Playfield(Playfield playground) { + public Playfield(final Playfield playground) { super(playground); } - public boolean allow(DiscretePoint position) { + public boolean allow(final DiscretePoint position) { return allow(position.x, position.y); } - public boolean allow(int p_x, int p_y) { + public boolean allow(final int p_x, final int p_y) { if(contains(p_x, p_y)) { return get(p_x, p_y).canBeWalkedOn(); } return false; } - public void readRow(String row, int rowIndex) { - char[] characters = row.toCharArray(); + public void readRow(final String row, final int rowIndex) { + final char[] characters = row.toCharArray(); for (int x = 0; x < characters.length; x++) { set(x, rowIndex, findContentFor(characters[x])); } } - private Content findContentFor(char c) { + private Content findContentFor(final char c) { switch(c) { case '.': return Nothing.instance; @@ -93,7 +90,7 @@ private Content findContentFor(char c) { return null; } - public Type accept(PlaygroundVisitor visitor) { + public Type accept(final PlaygroundVisitor visitor) { visitor.startVisit(this); for (int y = 0; y < height; y++) { visitor.startVisitRow(y); @@ -109,28 +106,29 @@ public Collection toStringCollection(final ContentVisitor visito return accept(new PlaygroundAdapter>() { private StringBuilder row; @Override - public void startVisit(Playfield playground) { + public void startVisit(final Playfield playground) { returned = new ArrayList<>(playground.height); } @Override - public void startVisitRow(int y) { + public void startVisitRow(final int y) { row = new StringBuilder(); } @Override - public void visit(int x, int y, Content content) { - if(content==null) + public void visit(final int x, final int y, final Content content) { + if(content==null) { row.append(Nothing.instance.accept(visitor)); - else + } else { row.append(content.accept(visitor)); + } } @Override - public void endVisitRow(int y) { + public void endVisitRow(final int y) { returned.add(row.toString()); } }); } - public String toString(ContentVisitor visitor) { + public String toString(final ContentVisitor visitor) { return toStringCollection(visitor).stream().reduce((r1, r2) -> r1+"\n"+r2).get(); } @@ -140,68 +138,74 @@ public String toPhysicialString() { public static class ExportGameEntities extends PlaygroundAdapter> implements ContentVisitor { public ExportGameEntities() {} @Override - public void startVisit(Playfield playground) { + public void startVisit(final Playfield playground) { returned = new ArrayList<>(); } @Override - public void visit(int x, int y, Content content) { - String text = content.accept(this); + public void visit(final int x, final int y, final Content content) { + final String text = content.accept(this); if(text!=null) { returned.add(text); } } - @Override public String visitNothing(Nothing nothing) { return null; } - @Override public String visitBox(Box box) { return null; } - @Override public String visitWall(Wall wall) { return null; } - @Override public String visitGamer(Gamer gamer) { + @Override public String visitNothing(final Nothing nothing) { return null; } + @Override public String visitBox(final Box box) { return null; } + @Override public String visitWall(final Wall wall) { return null; } + @Override public String visitGamer(final Gamer gamer) { return String.format("new Gamer(%d, %d, %d, %d, %d)", gamer.id, gamer.x, gamer.y, gamer.bombs, gamer.range); } - @Override public String visitBomb(Bomb bomb) { + @Override public String visitBomb(final Bomb bomb) { return String.format("new Bomb(%d, %d, %d, %d, %d)", bomb.owner, bomb.x, bomb.y, bomb.delay, bomb.range); } - @Override public String visitItem(Item item) { + @Override public String visitItem(final Item item) { return String.format("new Item(%d, %d, %d, %d, %d)", 0, item.x, item.y, item.type, 0); } - @Override public String visitFire(Fire fire) { return null; } - @Override public String visitFireThenItem(FireThenItem fireThenItem) { return null; } + @Override public String visitFire(final Fire fire) { return null; } + @Override public String visitFireThenItem(final FireThenItem fireThenItem) { return null; } } - public String toUnitTestString(Gamer me) { + public String toUnitTestString(final Gamer me) { + final String METHOD_PREFIX = "\t\t\t"; + final String CONTENT_PREFIX = METHOD_PREFIX+"\t"; final StringBuilder returned = new StringBuilder(); - returned.append("\t\t\t@Test public void can_find_move_") + + returned.append(METHOD_PREFIX+"// @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE)\n"); + returned.append(METHOD_PREFIX+"@Test public void can_find_move_") .append(System.currentTimeMillis()).append("() {\n"); - returned.append("\t\t\t\tPlayfield tested = read(Arrays.asList(\n"); - Collection physical = toStringCollection(new ToPhysicalString()); - Iterator physicalIter = physical.iterator(); + returned.append(CONTENT_PREFIX+"Playfield tested = read(Arrays.asList(\n"); + final Collection physical = toStringCollection(new ToPhysicalString()); + final Iterator physicalIter = physical.iterator(); while (physicalIter.hasNext()) { - String row = (String) physicalIter.next(); - returned.append("\t\t\t\t\t\"").append(row).append("\""); + final String row = physicalIter.next(); + returned.append(CONTENT_PREFIX+"\t\"").append(row).append("\""); if(physicalIter.hasNext()) { returned.append(","); } returned.append("\n"); } - returned.append("\t\t\t\t\t));\n"); - returned.append(String.format("\t\t\t\tGamer me = new Gamer(%d, %d, %d, %d, %d);\n", me.id, me.x, me.y, me.bombs, me.range)); - returned.append("\t\t\t\ttested.readGameEntities(\n"); - Collection entities = accept(new ExportGameEntities()); - Iterator entitiesIter = entities.iterator(); + returned.append(CONTENT_PREFIX+"\t));\n"); + returned.append(String.format(CONTENT_PREFIX+"Gamer me = new Gamer(%d, %d, %d, %d, %d);\n", me.id, me.x, me.y, me.bombs, me.range)); + returned.append(CONTENT_PREFIX+"tested.readGameEntities(\n"); + final Collection entities = accept(new ExportGameEntities()); + final Iterator entitiesIter = entities.iterator(); while (entitiesIter.hasNext()) { - String string = entitiesIter.next(); - returned.append("\t\t\t\t\t").append(string); - if(entitiesIter.hasNext()) + final String string = entitiesIter.next(); + returned.append(CONTENT_PREFIX+"\t").append(string); + if(entitiesIter.hasNext()) { returned.append(","); + } returned.append("\n"); } - returned.append("\t\t\t\t\t);\n"); - returned.append("\t\t\t\tassertThat(me.compute(tested)).isNotNull();\n"); - returned.append("\t\t\t}\n\n"); + returned.append(CONTENT_PREFIX+"\t);\n"); + returned.append(CONTENT_PREFIX+"assertThat(me.compute(tested)).isNotNull();\n"); + returned.append(METHOD_PREFIX+"}\n\n"); return returned.toString(); } + @Override public String toString() { return toString(new ToCompleteString()); } - public void readGameEntities(Entity...entities) { - for (Entity entity : entities) { + public void readGameEntities(final Entity...entities) { + for (final Entity entity : entities) { set(entity.x, entity.y, entity); } } @@ -215,6 +219,7 @@ public Playfield next() { } return next; } + @Override public void clear() { next = null; } @@ -232,14 +237,14 @@ public int findDelayBeforeBombFor(int id) { return accept(new BombDelayFinder(id)); } */ - public Playground getOpportunitiesAt(int range) { + public Playground getOpportunitiesAt(final int range) { if(opportunities==null) { opportunities = createOpportunitiesAt(range); } return opportunities; } - public Playground createOpportunitiesAt(int range) { + public Playground createOpportunitiesAt(final int range) { return descendant(EvolvableConstants.BOMB_DELAY).accept(new OpportunitiesFinder(range)); } diff --git a/multiplayer/hypersonic/src/test/java/org/ndx/codingame/hypersonic/InGameTest.java b/multiplayer/hypersonic/src/test/java/org/ndx/codingame/hypersonic/InGameTest.java index 499bd27..fe44df9 100644 --- a/multiplayer/hypersonic/src/test/java/org/ndx/codingame/hypersonic/InGameTest.java +++ b/multiplayer/hypersonic/src/test/java/org/ndx/codingame/hypersonic/InGameTest.java @@ -5,22 +5,14 @@ import java.util.Arrays; -import org.databene.contiperf.PerfTest; -import org.databene.contiperf.Required; -import org.databene.contiperf.junit.ContiPerfRule; import org.junit.Ignore; -import org.junit.Rule; import org.junit.Test; import org.ndx.codingame.hypersonic.content.Bomb; import org.ndx.codingame.hypersonic.content.Item; public class InGameTest { - private static final int PERCENTILE = 100; - private static final int THREAD_COUNT = 1; - private static final int INVOCATION_COUNT = 10; - @Rule public ContiPerfRule performance = new ContiPerfRule(); - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void can_find_move_1479318135242() { final Playfield tested = read(Arrays.asList( ".........0...", @@ -52,7 +44,7 @@ public class InGameTest { ); assertThat(me.compute(tested)).isNotEqualTo("MOVE 3 6"); } - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void can_find_move_1479328110167() { final Playfield tested = read(Arrays.asList( "..00.000.00..", @@ -75,7 +67,7 @@ public class InGameTest { assertThat(me.compute(tested)).isEqualTo("MOVE 1 0"); } - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void can_find_move_1479329573531() { final Playfield tested = read(Arrays.asList( "..0.0.0.0.0..", @@ -97,7 +89,7 @@ public class InGameTest { assertThat(me.compute(tested)).isNotIn("MOVE 12 10"); } - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void can_find_move_1479372001821() { final Playfield tested = read(Arrays.asList( "..00.0.0.00..", @@ -120,7 +112,7 @@ public class InGameTest { assertThat(me.compute(tested)).isNotEqualTo("MOVE 9 10"); } - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void can_find_move_1479376321186() { final Playfield tested = read(Arrays.asList( "....00000.0..", @@ -142,7 +134,7 @@ public class InGameTest { ); assertThat(me.compute(tested)).isNotNull(); } - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void should_not_drop_bomb_on_empty_ground() { final Playfield tested = read(Arrays.asList( "...00...0....", @@ -171,7 +163,7 @@ public class InGameTest { ); assertThat(me.compute(tested)).doesNotStartWith("BOMB"); } - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void bomb_that_spot() { final Playfield tested = read(Arrays.asList( ".............", @@ -200,7 +192,7 @@ public class InGameTest { assertThat(me.compute(tested)).startsWith("BOMB"); } - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void should_grab_item_beside() { final Playfield tested = read(Arrays.asList( "..........0..", @@ -228,7 +220,8 @@ public class InGameTest { ); assertThat(me.compute(tested)).isNotNull(); } - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) @Test public void i_should_drop_a_bomb() { + + @Test public void i_should_drop_a_bomb() { final Playfield tested = read(Arrays.asList( ".............", ".X.X.X.X.X.X.", @@ -253,7 +246,7 @@ public class InGameTest { assertThat(me.compute(tested)).isNotNull(); } - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) @Test public void do_not_go_in_bomb_alley() { + @Test public void do_not_go_in_bomb_alley() { final Playfield tested = read(Arrays.asList( ".............", ".X.X.X.X.X.X.", @@ -282,7 +275,7 @@ public class InGameTest { assertThat(me.compute(tested)).isNotEqualTo("BOMB 6 3"); } - @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) @Test @Ignore public void run_for_your_life_moron() { + @Test @Ignore public void run_for_your_life_moron() { final Playfield tested = read(Arrays.asList( ".............", ".X.X.X.X.X.X.", diff --git a/multiplayer/hypersonic/src/test/java/org/ndx/codingame/hypersonic/PerformanceTest.java b/multiplayer/hypersonic/src/test/java/org/ndx/codingame/hypersonic/PerformanceTest.java new file mode 100644 index 0000000..a14be4d --- /dev/null +++ b/multiplayer/hypersonic/src/test/java/org/ndx/codingame/hypersonic/PerformanceTest.java @@ -0,0 +1,319 @@ +package org.ndx.codingame.hypersonic; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.ndx.codingame.hypersonic.PlayerTest.read; + +import java.util.Arrays; + +import org.databene.contiperf.PerfTest; +import org.databene.contiperf.Required; +import org.databene.contiperf.junit.ContiPerfRule; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.ndx.codingame.hypersonic.content.Bomb; +import org.ndx.codingame.hypersonic.content.Item; + +public class PerformanceTest { + private static final int PERCENTILE = 100; + private static final int THREAD_COUNT = 1; + private static final int INVOCATION_COUNT = 10; + @Rule public ContiPerfRule performance = new ContiPerfRule(); + + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void can_find_move_1479318135242() { + final Playfield tested = read(Arrays.asList( + ".........0...", + ".............", + ".............", + ".............", + "0............", + ".............", + "0............", + ".............", + ".0...........", + ".............", + "...0.0.0.0..." + )); + final Gamer me = new Gamer(0, 2, 6, 0, 6); + tested.readGameEntities( + new Item(0, 3, 0, 2, 0), + new Item(0, 1, 2, 1, 0), + new Item(0, 3, 2, 2, 0), + new Item(0, 9, 2, 2, 0), + new Item(0, 11, 2, 1, 0), + new Bomb(0, 1, 4, 4, 5), + new Bomb(0, 4, 4, 2, 5), + new Bomb(0, 1, 6, 8, 6), + new Item(0, 3, 8, 2, 0), + new Gamer(1, 4, 9, 0, 6), + new Bomb(1, 5, 9, 7, 6), + new Bomb(1, 7, 9, 3, 6) + ); + assertThat(me.compute(tested)).isNotEqualTo("MOVE 3 6"); + } + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void can_find_move_1479328110167() { + final Playfield tested = read(Arrays.asList( + "..00.000.00..", + ".X0X0X0X0X0X.", + ".0...000...0.", + ".X.X0X0X0X.X.", + "000.0.0.0.000", + "0X.X.X.X.X.X0", + "000.0.0.0.000", + ".X.X0X0X0X.X.", + ".0...000...0.", + ".X0X0X0X0X0X.", + "..00.000.00.." + )); + final Gamer me = new Gamer(0, 1, 0, 0, 3); + tested.readGameEntities( + new Bomb(0, 0, 2, 2, 3), + new Bomb(1, 12, 7, 4, 3) + ); + assertThat(me.compute(tested)).isEqualTo("MOVE 1 0"); + } + + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void can_find_move_1479329573531() { + final Playfield tested = read(Arrays.asList( + "..0.0.0.0.0..", + ".X0X.X0X.X0X.", + "00.00...00.00", + "0X.X.X.X.X.X0", + "..00.....00..", + ".X.X.X.X.X.X.", + "..00.....00..", + "0X.X.X.X.X.X0", + "00.00...00.00", + ".X0X.X0X.X0X.", + "..0.0.0.0.0.." + )); + final Gamer me = new Gamer(1, 12, 10, 1, 3); + tested.readGameEntities( + new Gamer(0, 0, 0, 1, 3) + ); + assertThat(me.compute(tested)).isNotIn("MOVE 12 10"); + } + + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void can_find_move_1479372001821() { + final Playfield tested = read(Arrays.asList( + "..00.0.0.00..", + ".X0X0X.X0X0X.", + "0000..0..0000", + ".X0X.X.X.X0X.", + "0.0.00000.0.0", + ".X.X.X.X.X.X.", + "0.0.00000.0.0", + ".X0X.X.X.X0X.", + "0000..0..0000", + ".X0X0X.X0X0X.", + "..00.0.0....." + )); + final Gamer me = new Gamer(1, 8, 10, 1, 3); + tested.readGameEntities( + new Gamer(0, 1, 0, 1, 3), + new Bomb(1, 11, 10, 2, 3) + ); + assertThat(me.compute(tested)).isNotEqualTo("MOVE 9 10"); + } + + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void can_find_move_1479376321186() { + final Playfield tested = read(Arrays.asList( + "....00000.0..", + ".X0X.X.X.X0X.", + "00.0000000.00", + "0X.X0X0X0X.X0", + "00..0.0.0..00", + ".X0X.X.X.X0X.", + "00..0.0.0..00", + "0X.X0X0X0X.X0", + "00.0000000.00", + ".X0X.X.X.X0X.", + "..0.00000...." + )); + final Gamer me = new Gamer(0, 3, 0, 1, 3); + tested.readGameEntities( + new Bomb(0, 1, 0, 1, 3), + new Bomb(1, 9, 10, 4, 3) + ); + assertThat(me.compute(tested)).isNotNull(); + } + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void should_not_drop_bomb_on_empty_ground() { + final Playfield tested = read(Arrays.asList( + "...00...0....", + ".X0X0X.X0X.X.", + "....0...0...0", + ".X0X.X.X.X0X.", + "00..0...0..00", + ".X.X.X0X.X.X.", + "00..0...0..00", + ".X0X.X.X.X0X.", + "0...0...0...0", + ".X.X0X.X0X0X.", + "....0...0...." + )); + final Gamer me = new Gamer(1, 11, 10, 1, 3); + tested.readGameEntities( + new Gamer(0, 2, 0, 1, 3), + new Item(0, 9, 0, 1, 0), + new Item(0, 10, 1, 1, 0), + new Gamer(2, 12, 1, 1, 3), + new Item(0, 0, 2, 2, 0), + new Gamer(3, 0, 9, 1, 3), + new Item(0, 2, 9, 1, 0), + new Item(0, 3, 10, 1, 0), + new Item(0, 9, 10, 1, 0) + ); + assertThat(me.compute(tested)).doesNotStartWith("BOMB"); + } + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void bomb_that_spot() { + final Playfield tested = read(Arrays.asList( + ".............", + ".X.X.X.X.X0X.", + ".............", + ".X.X.X.X.X0X.", + ".............", + ".X.X0X.X.X.X.", + ".000.....0...", + ".X.X0X.X.X.X.", + "....0........", + ".X.X.X.X.X.X.", + "............." + )); + final Gamer me = new Gamer(2, 5, 8, 7, 9); + tested.readGameEntities( + new Item(0, 1, 2, 2, 0), + new Bomb(1, 3, 2, 3, 10), + new Bomb(1, 4, 2, 4, 10), + new Bomb(1, 2, 4, 8, 12), + new Gamer(1, 2, 5, 6, 12), + new Bomb(0, 2, 8, 1, 7), + new Item(0, 3, 8, 1, 0), + new Gamer(0, 4, 10, 4, 7) + ); + assertThat(me.compute(tested)).startsWith("BOMB"); + } + + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) + @Test public void should_grab_item_beside() { + final Playfield tested = read(Arrays.asList( + "..........0..", + ".X.X.X.X.X.X.", + ".......00...0", + "0X.X.X.X.X0X0", + "........0....", + "0X.X.X.X.X.X0", + "..0..........", + "0X0X.X.X.X.X0", + "0...000......", + ".X.X.X.X.X.X.", + "..0..00......" + )); + final Gamer me = new Gamer(1, 8, 8, 2, 5); + tested.readGameEntities( + new Gamer(0, 1, 0, 1, 6), + new Bomb(0, 2, 1, 2, 6), + new Bomb(0, 0, 2, 5, 6), + new Item(0, 6, 2, 1, 0), + new Item(0, 10, 4, 1, 0), + new Item(0, 4, 6, 1, 0), + new Item(0, 8, 6, 1, 0), + new Item(0, 7, 8, 2, 0) + ); + assertThat(me.compute(tested)).isNotNull(); + } + + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) @Test public void i_should_drop_a_bomb() { + final Playfield tested = read(Arrays.asList( + ".............", + ".X.X.X.X.X.X.", + ".............", + ".X.X.X.X.X.X.", + ".............", + ".X.X.X.X.X.X.", + ".............", + ".X.X.X.X.X.X.", + ".............", + ".X.X.X.X.X.X.", + ".....0......." + )); + final Gamer me = new Gamer(1, 3, 10, 7, 8); + tested.readGameEntities( + new Item(0, 0, 3, 2, 0), + new Item(0, 0, 5, 2, 0), + new Item(0, 0, 7, 2, 0), + new Item(0, 12, 7, 2, 0), + new Gamer(0, 4, 8, 5, 9) + ); + assertThat(me.compute(tested)).isNotNull(); + } + + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) @Test public void do_not_go_in_bomb_alley() { + final Playfield tested = read(Arrays.asList( + ".............", + ".X.X.X.X.X.X.", + "..0..........", + ".X.X.X.X.X.X.", + ".....0.0.00..", + ".X.X.X.X.X0X.", + ".000.0.0.0...", + ".X0X0X.X0X0X.", + ".0000....00..", + ".X.X.X.X.X.X.", + "..0..0......." + )); + final Gamer me = new Gamer(2, 6, 2, 6, 5); + tested.readGameEntities( + new Item(0, 2, 0, 1, 0), + new Item(0, 3, 2, 1, 0), + new Gamer(0, 4, 2, 5, 6), + new Bomb(2, 8, 3, 2, 5), + new Item(0, 11, 4, 1, 0), + new Item(0, 10, 6, 2, 0), + new Gamer(1, 6, 8, 2, 5), + new Bomb(1, 8, 8, 7, 5), + new Bomb(1, 7, 10, 4, 5) + ); + assertThat(me.compute(tested)).isNotEqualTo("BOMB 6 3"); + } + + @PerfTest(invocations = INVOCATION_COUNT, threads = THREAD_COUNT) @Required(percentile99=PERCENTILE) @Test @Ignore public void run_for_your_life_moron() { + final Playfield tested = read(Arrays.asList( + ".............", + ".X.X.X.X.X.X.", + ".............", + ".X.X.X.X.X.X.", + ".....0....0..", + ".X.X.X.X.X0X.", + ".000.0.......", + ".X0X.X.X.X0X.", + ".000......0..", + ".X.X.X.X.X.X.", + "............." + )); + final Gamer me = new Gamer(2, 10, 6, 3, 6); + tested.readGameEntities( + new Gamer(0, 3, 4, 5, 8), + new Bomb(2, 6, 4, 3, 5), + new Bomb(2, 7, 4, 4, 5), + new Bomb(2, 8, 4, 5, 5), + new Item(0, 9, 4, 1, 0), + new Item(0, 11, 4, 1, 0), + new Bomb(0, 4, 6, 3, 8), + new Gamer(1, 7, 6, 5, 5), + new Bomb(2, 8, 6, 7, 5), + new Bomb(2, 9, 6, 8, 6), + new Item(0, 4, 7, 1, 0), + new Bomb(1, 6, 8, 3, 5), + new Item(0, 2, 10, 1, 0) + ); + assertThat(me.compute(tested)).doesNotEndWith("10 6"); + } + +} \ No newline at end of file