Repository navigation
BWEM Bugfix: Different chokes receive equal hashcodes #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,19 @@ | |
|
|
||
| import bwem.BWEM; | ||
| import bwem.BWMap; | ||
| import bwta.BWTA; | ||
| import bwta.Chokepoint; | ||
| import bwta.Region; | ||
| import org.junit.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.*; | ||
|
|
||
| public class BWEMTest { | ||
| static class BWEMMap{ | ||
|
|
@@ -66,13 +72,38 @@ public int hashCode() { | |
| mapData.put("(4)Roadrunner.scx", new BWEMMap(26, 12, 35)); | ||
| } | ||
|
|
||
| @Test | ||
| public void chokePointsFromDifferentMapsAreDistinct() throws IOException { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test seems unintuitive, if anything I would expect the opposite. These maps here (first and second) are the same map. |
||
| BWEM first = new BWEM(GameBuilder.createGame()); | ||
| first.initialize(); | ||
| BWEM second = new BWEM(GameBuilder.createGame()); | ||
| second.initialize(); | ||
| assertTrue(Collections.disjoint(first.getMap().getChokePoints(), second.getMap().getChokePoints())); | ||
| } | ||
|
|
||
| @Test | ||
| public void checkSSCAITMaps() throws IOException { | ||
| for (String mapName : mapData.keySet()) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer testing through the BWEM API, PTAL if somehting like the following could work:
diff --git a/src/test/java/bwapi/BWEMTest.java b/src/test/java/bwapi/BWEMTest.java
index 65558961..c73d8e14 100644
--- a/src/test/java/bwapi/BWEMTest.java
+++ b/src/test/java/bwapi/BWEMTest.java
@@ -1,16 +1,21 @@
package bwapi;
+import bwem.Area;
import bwem.BWEM;
import bwem.BWMap;
+import bwem.ChokePoint;
import org.junit.Test;
import java.io.IOException;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
public class BWEMTest {
static class BWEMMap{
@@ -66,12 +71,42 @@ public class BWEMTest {
mapData.put("(4)Roadrunner.scx", new BWEMMap(26, 12, 35));
}
+ @Test
+ public void chokePointsFromSameMapAreEqual() throws IOException {
+ BWEM first = new BWEM(GameBuilder.createGame("(2)Destination.scx"));
+ first.initialize();
+ BWEM second = new BWEM(GameBuilder.createGame("(2)Destination.scx"));
+ second.initialize();
+ assertEquals(first.getMap().getChokePoints(), second.getMap().getChokePoints());
+ assertEquals(new HashSet<>(first.getMap().getChokePoints()), new HashSet<>(second.getMap().getChokePoints()));
+ }
+
+ @Test
+ public void chokePointsFromDifferentMapsAreDistinct() throws IOException {
+ BWEM first = new BWEM(GameBuilder.createGame("(2)Benzene.scx"));
+ first.initialize();
+ BWEM second = new BWEM(GameBuilder.createGame("(2)Destination.scx"));
+ second.initialize();
+ assertTrue(Collections.disjoint(first.getMap().getChokePoints(), second.getMap().getChokePoints()));
+ }
+
@Test
public void checkSSCAITMaps() throws IOException {
for (String mapName : mapData.keySet()) {
Game game = GameBuilder.createGame(mapName);
BWEM bwem = new BWEM(game);
bwem.initialize();
- assertEquals(new BWEMMap(bwem.getMap()), mapData.get(mapName));
+ BWMap map = bwem.getMap();
+ assertEquals(new BWEMMap(map), mapData.get(mapName));
+ assertEquals(mapName, map.getChokePoints().size(), new HashSet<>(map.getChokePoints()).size());
+
+ for (Area area : map.getAreas()) {
+ for (ChokePoint cp1 : area.getChokePoints()) {
+ for (ChokePoint cp2 : area.getChokePoints()) {
+ if (!cp1.isBlocked() && !cp2.isBlocked()) {
+ assertTrue(mapName, cp1.accessibleFrom(cp2));
+ }
+ }
+ }
+ }
}
}
} |
||
| Game game = GameBuilder.createGame(mapName); | ||
| BWEM bwem = new BWEM(game); | ||
| bwem.initialize(); | ||
| assertEquals(new BWEMMap(bwem.getMap()), mapData.get(mapName)); | ||
| BWTA.readMap(GameBuilder.createGame(mapName)); | ||
| BWTA.analyze(); | ||
| BWMap map = BWTA.getBWEM().getMap(); | ||
| assertEquals(new BWEMMap(map), mapData.get(mapName)); | ||
| assertEquals(mapName, map.getChokePoints().size(), new HashSet<>(map.getChokePoints()).size()); | ||
|
|
||
| List<Chokepoint> chokes = BWTA.getChokepoints(); | ||
| assertEquals(mapName, map.getChokePoints().size(), chokes.size()); | ||
| for (Chokepoint choke : chokes) { | ||
| assertTrue(choke.getRegions().getLeft().getChokepoints().contains(choke)); | ||
| assertTrue(choke.getRegions().getRight().getChokepoints().contains(choke)); | ||
| } | ||
| for (Region region : BWTA.getRegions()) { | ||
| for (Chokepoint choke : region.getChokepoints()) { | ||
| assertNotNull(mapName, choke); | ||
| assertTrue(mapName, chokes.contains(choke)); | ||
| assertTrue(choke.getRegions().getLeft().equals(region) | ||
| || choke.getRegions().getRight().equals(region)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pointer equality for graph is wrong here i think, two the same maps in different runs "should" return an equals true, I propose the following diff: