|
1 | 1 | package bwapi; |
2 | 2 |
|
| 3 | +import bwem.Area; |
3 | 4 | import bwem.BWEM; |
4 | 5 | import bwem.BWMap; |
| 6 | +import bwem.ChokePoint; |
5 | 7 | import org.junit.Test; |
6 | 8 |
|
7 | 9 | import java.io.IOException; |
| 10 | +import java.util.Collections; |
8 | 11 | import java.util.HashMap; |
| 12 | +import java.util.HashSet; |
9 | 13 | import java.util.Map; |
10 | 14 |
|
11 | 15 | import static org.junit.Assert.assertEquals; |
| 16 | +import static org.junit.Assert.assertTrue; |
12 | 17 |
|
13 | 18 | public class BWEMTest { |
14 | 19 | static class BWEMMap{ |
@@ -66,13 +71,44 @@ public int hashCode() { |
66 | 71 | mapData.put("(4)Roadrunner.scx", new BWEMMap(26, 12, 35)); |
67 | 72 | } |
68 | 73 |
|
| 74 | + @Test |
| 75 | + public void chokePointsFromSameMapAreEqual() throws IOException { |
| 76 | + BWEM first = new BWEM(GameBuilder.createGame("(2)Destination.scx")); |
| 77 | + first.initialize(); |
| 78 | + BWEM second = new BWEM(GameBuilder.createGame("(2)Destination.scx")); |
| 79 | + second.initialize(); |
| 80 | + assertEquals(first.getMap().getChokePoints(), second.getMap().getChokePoints()); |
| 81 | + assertEquals(new HashSet<>(first.getMap().getChokePoints()), new HashSet<>(second.getMap().getChokePoints())); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void chokePointsFromDifferentMapsAreDistinct() throws IOException { |
| 86 | + BWEM first = new BWEM(GameBuilder.createGame("(2)Benzene.scx")); |
| 87 | + first.initialize(); |
| 88 | + BWEM second = new BWEM(GameBuilder.createGame("(2)Destination.scx")); |
| 89 | + second.initialize(); |
| 90 | + assertTrue(Collections.disjoint(first.getMap().getChokePoints(), second.getMap().getChokePoints())); |
| 91 | + } |
| 92 | + |
69 | 93 | @Test |
70 | 94 | public void checkSSCAITMaps() throws IOException { |
71 | 95 | for (String mapName : mapData.keySet()) { |
72 | 96 | Game game = GameBuilder.createGame(mapName); |
73 | 97 | BWEM bwem = new BWEM(game); |
74 | 98 | bwem.initialize(); |
75 | | - assertEquals(new BWEMMap(bwem.getMap()), mapData.get(mapName)); |
| 99 | + BWMap map = bwem.getMap(); |
| 100 | + assertEquals(new BWEMMap(map), mapData.get(mapName)); |
| 101 | + assertEquals(mapName, map.getChokePoints().size(), new HashSet<>(map.getChokePoints()).size()); |
| 102 | + |
| 103 | + for (Area area : map.getAreas()) { |
| 104 | + for (ChokePoint firstChokePoint : area.getChokePoints()) { |
| 105 | + for (ChokePoint secondChokePoint : area.getChokePoints()) { |
| 106 | + if (!firstChokePoint.isBlocked() && !secondChokePoint.isBlocked()) { |
| 107 | + assertTrue(mapName, firstChokePoint.accessibleFrom(secondChokePoint)); |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + } |
76 | 112 | } |
77 | 113 | } |
78 | 114 | } |
0 commit comments