diff --git a/src/Configuration.java b/src/Configuration.java index 7086b8d..9f3d58e 100644 --- a/src/Configuration.java +++ b/src/Configuration.java @@ -45,7 +45,7 @@ public boolean setValues(Set classes, int val) { } return true; } - + public boolean setValues(V item, int val) { int curr = config.get(item); if (!(curr == -1 || curr == val)) { @@ -63,5 +63,5 @@ public String toString() { } return s; } - + } diff --git a/src/HEXGraphTest.java b/src/HEXGraphTest.java deleted file mode 100644 index 1fb3073..0000000 --- a/src/HEXGraphTest.java +++ /dev/null @@ -1,55 +0,0 @@ - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.Set; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * @author dgorrie - * - * Testing class for our HEXGraphImplementation - */ -public class HEXGraphTest { - private static HEXGraphMethods mHexGraphMethods; - - - @BeforeClass - public static void setup() throws IOException, IllegalStateException { - HEXGraphFactory factory = new HEXGraphFactory(); - String directory = "/Users/dgorrie/Documents/workspace/hexgraph/src/"; - String sample = directory + "sample.hxg"; - String unconnected = directory + "no_connections.hxg"; - factory.buildHEXGraph(sample); - factory.buildHEXGraph(unconnected); - mHexGraphMethods = new HEXGraphMethods(factory, unconnected); - } - - @Test - public void testCreation() { - HEXGraph newGraph = new HEXGraph(); - newGraph.addNode("Person"); - newGraph.addNode("Dog"); - newGraph.addNode("Actor"); - newGraph.addNode("Politician"); - newGraph.addExclusion("Person", "Dog"); - newGraph.addHierarchy("Person", "Actor"); - newGraph.addHierarchy("Person", "Politician"); - assertEquals(4, newGraph.size()); - } - - @Test - public void testListStateSpace() { - Set> configs = mHexGraphMethods.ListStateSpace(); - assertEquals(1024, configs.size()); - } - - - - - - - -} diff --git a/test/HEXGraphTest.java b/test/HEXGraphTest.java new file mode 100644 index 0000000..e4a0b7e --- /dev/null +++ b/test/HEXGraphTest.java @@ -0,0 +1,161 @@ + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.Set; + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * @author dgorrie + *

+ * Testing class for our HEXGraphImplementation + */ +public class HEXGraphTest { + private static HEXGraph graph; + private static final String[] testNames = {"PERSON", "MOUNTAIN", "ANIMAL"}; + private static final String[] exclusions = {"CAT, DOG", "ANIMAL, LAKE", "LAKE, MOUNTAIN"}; + private static final String[] subsets = {"ARTIST, POLITICIAN", "", "PUPPY, PERSON, KITTEN, ARTIST, CAT, POLITICIAN, DOG"}; + private static final String[] supersets = {"ANIMAL", "", ""}; + private static HEXGraphMethods mHexGraphMethods; + + @BeforeClass + public static void setup() throws IOException, IllegalStateException { + HEXGraphFactory factory = new HEXGraphFactory(); + String directory = "src/"; + String sample = directory + "sample.hxg"; + String unconnected = directory + "no_connections.hxg"; + factory.buildHEXGraph(sample); + factory.buildHEXGraph(unconnected); + mHexGraphMethods = new HEXGraphMethods(factory, unconnected); + } + + @Test + public void testExclusions() { + for (int i = 0; i < testNames.length; i++) { + // System.out.println(graph.getExcluded(testNames[i]).toString()); + assertEquals(graph.getExcluded(testNames[i]).toString(), "[" + exclusions[i] + "]"); + } + } + + @Test + public void testHierarchySubset() { + for (int i = 0; i < testNames.length; i++) { + // System.out.println(graph.getHierarchySubset(testNames[i]).toString()); + assertEquals(graph.getDescendants(testNames[i]).toString(), "[" + subsets[i] + "]"); + } + } + + @Test + public void testHierarchySuperset() { + for (int i = 0; i < testNames.length; i++) { + // System.out.println(graph.getHierarchySuperset(testNames[i]).toString()); + assertEquals(graph.getDescendants(testNames[i]).toString(), "[" + supersets[i] + "]"); + } + } + + @Test + public void testListStateSpace() { + Set> configs = mHexGraphMethods.ListStateSpace(); + assertEquals(1024, configs.size()); + } + + private HEXGraph createSimpleGraph() { + HEXGraph graph = new HEXGraph(); + graph.addNode("Person"); + graph.addNode("Dog"); + graph.addNode("Actor"); + graph.addNode("Politician"); + graph.addExclusion("Person", "Dog"); + graph.addHierarchy("Person", "Actor"); + graph.addHierarchy("Person", "Politician"); + return graph; + } + + @Test + public void testCreation() { + HEXGraph graph = createSimpleGraph(); + assertEquals(4, graph.size()); + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Dog", "Person")); + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Person", "Dog")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUPER, graph.getRelationship("Actor", "Person")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUPER, graph.getRelationship("Politician", "Person")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUB, graph.getRelationship("Person", "Actor")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUB, graph.getRelationship("Person", "Politician")); + assertEquals(HEXGraph.Relationship.OVERLAPPING, graph.getRelationship("Actor", "Politician")); + assertEquals(HEXGraph.Relationship.OVERLAPPING, graph.getRelationship("Politician", "Actor")); + } + + + @Test + public void testDensify() { + HEXGraph graph = createSimpleGraph(); + graph.densify(); + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Dog", "Actor")); + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Dog", "Person")); + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Dog", "Politician")); + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Actor", "Dog")); + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Person", "Dog")); + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Politician", "Dog")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUPER, graph.getRelationship("Actor", "Person")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUPER, graph.getRelationship("Politician", "Person")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUB, graph.getRelationship("Person", "Actor")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUB, graph.getRelationship("Person", "Politician")); + assertEquals(HEXGraph.Relationship.OVERLAPPING, graph.getRelationship("Actor", "Politician")); + assertEquals(HEXGraph.Relationship.OVERLAPPING, graph.getRelationship("Politician", "Actor")); + } + + @Test + public void testSparisfy() { + HEXGraph graph = createSimpleGraph(); + graph.sparsify(); + // graph stays the same + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Dog", "Person")); + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Person", "Dog")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUPER, graph.getRelationship("Actor", "Person")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUPER, graph.getRelationship("Politician", "Person")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUB, graph.getRelationship("Person", "Actor")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUB, graph.getRelationship("Person", "Politician")); + assertEquals(HEXGraph.Relationship.OVERLAPPING, graph.getRelationship("Actor", "Politician")); + assertEquals(HEXGraph.Relationship.OVERLAPPING, graph.getRelationship("Politician", "Actor")); + } + + @Test + public void testSparisfyAfterDensify() { + HEXGraph graph = createSimpleGraph(); + graph.densify(); + graph.sparsify(); + // graph stays the same + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Dog", "Person")); + assertEquals(HEXGraph.Relationship.EXCLUSION, graph.getRelationship("Person", "Dog")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUPER, graph.getRelationship("Actor", "Person")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUPER, graph.getRelationship("Politician", "Person")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUB, graph.getRelationship("Person", "Actor")); + assertEquals(HEXGraph.Relationship.HIERARCHY_SUB, graph.getRelationship("Person", "Politician")); + assertEquals(HEXGraph.Relationship.OVERLAPPING, graph.getRelationship("Actor", "Politician")); + assertEquals(HEXGraph.Relationship.OVERLAPPING, graph.getRelationship("Politician", "Actor")); + } + + @Test + public void testListStateSpace2() { + System.out.println("testing list state space"); + HEXGraph graph = createSimpleGraph(); + HEXGraphMethods method = new HEXGraphMethods(graph); + Set> confs = method.ListStateSpace(); + System.out.println("printing"); + for (Configuration conf : confs) { + System.out.println(conf.toString()); + } + // 6 configurations + // Politician, Actor, Dog, Person + // 0 0 0 0 + // 0 0 1 0 + // 0 0 0 1 + // 0 1 0 1 + // 1 0 0 1 + // 1 1 0 1 + assertEquals(6, confs.size()); + } + +}