|
1 | 1 | package bwapi; |
2 | 2 |
|
| 3 | +import bwem.Area; |
3 | 4 | import bwem.BWEM; |
4 | 5 | import bwem.BWMap; |
5 | | -import bwta.BWTA; |
6 | | -import bwta.Chokepoint; |
7 | | -import bwta.Region; |
| 6 | +import bwem.ChokePoint; |
8 | 7 | import org.junit.Test; |
9 | 8 |
|
10 | 9 | import java.io.IOException; |
11 | 10 | import java.util.Collections; |
12 | 11 | import java.util.HashMap; |
13 | 12 | import java.util.HashSet; |
14 | | -import java.util.List; |
15 | 13 | import java.util.Map; |
16 | 14 |
|
17 | | -import static org.junit.Assert.*; |
| 15 | +import static org.junit.Assert.assertEquals; |
| 16 | +import static org.junit.Assert.assertTrue; |
18 | 17 |
|
19 | 18 | public class BWEMTest { |
20 | 19 | static class BWEMMap{ |
@@ -72,36 +71,42 @@ public int hashCode() { |
72 | 71 | mapData.put("(4)Roadrunner.scx", new BWEMMap(26, 12, 35)); |
73 | 72 | } |
74 | 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 | + |
75 | 84 | @Test |
76 | 85 | public void chokePointsFromDifferentMapsAreDistinct() throws IOException { |
77 | | - BWEM first = new BWEM(GameBuilder.createGame()); |
| 86 | + BWEM first = new BWEM(GameBuilder.createGame("(2)Benzene.scx")); |
78 | 87 | first.initialize(); |
79 | | - BWEM second = new BWEM(GameBuilder.createGame()); |
| 88 | + BWEM second = new BWEM(GameBuilder.createGame("(2)Destination.scx")); |
80 | 89 | second.initialize(); |
81 | 90 | assertTrue(Collections.disjoint(first.getMap().getChokePoints(), second.getMap().getChokePoints())); |
82 | 91 | } |
83 | 92 |
|
84 | 93 | @Test |
85 | 94 | public void checkSSCAITMaps() throws IOException { |
86 | 95 | for (String mapName : mapData.keySet()) { |
87 | | - BWTA.readMap(GameBuilder.createGame(mapName)); |
88 | | - BWTA.analyze(); |
89 | | - BWMap map = BWTA.getBWEM().getMap(); |
| 96 | + Game game = GameBuilder.createGame(mapName); |
| 97 | + BWEM bwem = new BWEM(game); |
| 98 | + bwem.initialize(); |
| 99 | + BWMap map = bwem.getMap(); |
90 | 100 | assertEquals(new BWEMMap(map), mapData.get(mapName)); |
91 | 101 | assertEquals(mapName, map.getChokePoints().size(), new HashSet<>(map.getChokePoints()).size()); |
92 | 102 |
|
93 | | - List<Chokepoint> chokes = BWTA.getChokepoints(); |
94 | | - assertEquals(mapName, map.getChokePoints().size(), chokes.size()); |
95 | | - for (Chokepoint choke : chokes) { |
96 | | - assertTrue(choke.getRegions().getLeft().getChokepoints().contains(choke)); |
97 | | - assertTrue(choke.getRegions().getRight().getChokepoints().contains(choke)); |
98 | | - } |
99 | | - for (Region region : BWTA.getRegions()) { |
100 | | - for (Chokepoint choke : region.getChokepoints()) { |
101 | | - assertNotNull(mapName, choke); |
102 | | - assertTrue(mapName, chokes.contains(choke)); |
103 | | - assertTrue(choke.getRegions().getLeft().equals(region) |
104 | | - || choke.getRegions().getRight().equals(region)); |
| 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 | + } |
105 | 110 | } |
106 | 111 | } |
107 | 112 | } |
|
0 commit comments