Kaynağa Gözat

Finishes initial refactorization and moves tests to use JUnit.

Caleb Fangmeier 6 yıl önce
ebeveyn
işleme
79017ba331

+ 2 - 2
src/com/pact/Main.java

@@ -15,12 +15,12 @@ public class Main {
         while((line = inB.readLine()) != null){
             if(templates == null) {
                 // Load first line into template
-                templates = new HashSet();
+                templates = new HashSet<>();
                 templates.add(new Node(null, line));
                 continue;
             }
 
-            HashSet<Node> allCombined = new HashSet();
+            HashSet<Node> allCombined = new HashSet<>();
 
             Node input = new Node(null, line);
             for (Node template : templates) {

+ 119 - 143
src/com/pact/Node.java

@@ -1,6 +1,5 @@
 package com.pact;
 
-import java.io.PrintStream;
 import java.util.HashSet;
 import java.util.Iterator;
 
@@ -14,11 +13,11 @@ public class Node
 
     public Node(Node p, String s) {
         this.linkNode = null;
-        this.linkNodes = new HashSet<Node>();
+        this.linkNodes = new HashSet();
         this.venn = s;
         this.parent = p;
 
-        this.children = new HashSet<Node>();
+        this.children = new HashSet();
         if (s.length() > 1)
             setChildren(s);
     }
@@ -79,7 +78,7 @@ public class Node
 
     public HashSet<Node> getSiblings() {
         if (this.parent != null) {
-            HashSet sibs = (HashSet)this.parent.children.clone();
+            HashSet<Node> sibs = (HashSet)this.parent.children.clone();
             sibs.remove(this);
             return sibs;
         }
@@ -130,9 +129,22 @@ public class Node
 
     public boolean equals(Object o)
     {
-        Node n = (Node)o;
-        return equals(n);
-    }
+        return equals((Node)o);
+    }
+
+//    @Override
+//    public int hashCode() {
+//        if (children.isEmpty()) {
+//            return venn.hashCode();
+//        } else {
+//            int h = 0;
+//            for (Node child : children) {
+//                h += child.hashCode();
+//            }
+//            return Integer.hashCode(h);
+//        }
+//
+//    }
 
     private int getNumAreas() {
         int count = 0;
@@ -187,15 +199,15 @@ public class Node
         return result;
     }
 
-    private boolean oneAreaShared(Node node1, Node node2)
+    private static boolean oneAreaShared(Node node1, Node node2)
     {
-        HashSet result = new HashSet();
+        HashSet<Nodes> result = new HashSet<>();
         node2.deepSearch(node1, result);
-        HashSet largest = getLNodes(result);
+        HashSet<Nodes> largest = getLNodes(result);
         if (largest.isEmpty()) {
             return false;
         }
-        return (Nodes.setNodesSize(largest) == 1) && (largest.size() == 1);
+        return (Nodes.getNodesSize(largest) == 1) && (largest.size() == 1);
     }
 
     public HashSet<Node> combine(Node node) {
@@ -219,9 +231,9 @@ public class Node
             return result;
         }
 
-        HashSet largest = getLNodes(sResult);
+        HashSet<Nodes> largest = getLNodes(sResult);
 
-        HashSet unsharedNodes = new HashSet();
+        HashSet<Node> unsharedNodes = new HashSet<>();
         node2.collectUnshared(unsharedNodes);
         node1.collectUnshared(unsharedNodes);
 
@@ -230,7 +242,7 @@ public class Node
                 Node toAdd = new Node(null, node1.getVenn());
                 result.add(toAdd);
                 return result;
-            }if (node2.children.size() < node1.children.size()) {
+            } if (node2.children.size() < node1.children.size()) {
                 Node toAdd = new Node(null, node2.getVenn());
                 result.add(toAdd);
                 return result;
@@ -238,18 +250,17 @@ public class Node
 
         }
 
-        if (largest.size() > 0)
-        {
+        if (!largest.isEmpty()) {
             Iterator itLargest = largest.iterator();
 
             Nodes flargest = (Nodes)itLargest.next();
 
-            HashSet lg1sibs = flargest.node1.getSiblings();
-            HashSet lg2sibs = flargest.node2.getSiblings();
+            HashSet<Node> lg1sibs = flargest.node1.getSiblings();
+            HashSet<Node> lg2sibs = flargest.node2.getSiblings();
 
-            HashSet newSibs = new HashSet();
-            HashSet otherSibs1 = new HashSet();
-            HashSet otherSibs2 = new HashSet();
+            HashSet<Node> newSibs = new HashSet<>();
+            HashSet<Node> otherSibs1 = new HashSet<>();
+            HashSet<Node> otherSibs2 = new HashSet<>();
 
             Iterator lg1It = lg1sibs.iterator();
             Iterator lg2It = lg2sibs.iterator();
@@ -257,11 +268,10 @@ public class Node
             sortLargestSibs(lg1It, flargest.node2, newSibs, otherSibs1);
             sortLargestSibs(lg2It, flargest.node1, newSibs, otherSibs2);
 
-            Iterator nsIt = newSibs.iterator();
 
             if ((otherSibs1.isEmpty()) && (otherSibs2.isEmpty())) {
-                while (nsIt.hasNext()) {
-                    unsharedNodes.add((Node)nsIt.next());
+                for (Node newSib : newSibs) {
+                    unsharedNodes.add(newSib);
                 }
 
             }
@@ -287,7 +297,7 @@ public class Node
                         HashSet polyresults = polyOne.combine(polyTwo);
                         Iterator prsIt = polyresults.iterator();
                         while (prsIt.hasNext())
-                            result.add((Node)prsIt.next());
+                            result.add(prsIt.next());
                     }
                     else if (curr.node1.parent != null) {
                         String polyString1 = buildUp(curr.node1.parent, curr.node2.getVenn());
@@ -315,14 +325,14 @@ public class Node
                 Iterator nRit = newResults.iterator();
                 while (nRit.hasNext())
                 {
-                    result.add((Node)nRit.next());
+                    result.add(nRit.next());
                 }
             }
 
             return result;
         }
 
-        if (Nodes.setNodesSize(largest) == 1)
+        if (Nodes.getNodesSize(largest) == 1)
         {
             HashSet unique = getUniqueNodes(sResult);
             Iterator uIt = unique.iterator();
@@ -342,7 +352,7 @@ public class Node
                             Iterator nRit = newResults.iterator();
                             while (nRit.hasNext())
                             {
-                                result.add((Node)nRit.next());
+                                result.add(nRit.next());
                             }
                         }
                     }
@@ -354,14 +364,14 @@ public class Node
             return result;
         }
 
-        if (Nodes.setNodesSize(largest) > 1)
+        if (Nodes.getNodesSize(largest) > 1)
         {
             for (Object aLargest : largest) {
                 Nodes currL = (Nodes) aLargest;
                 HashSet largeResult = subTrees(currL);
                 Iterator lrIt = largeResult.iterator();
                 while (lrIt.hasNext()) {
-                    result.add((Node) lrIt.next());
+                    result.add(lrIt.next());
                 }
             }
             return result;
@@ -372,7 +382,7 @@ public class Node
 
     private void sortLargestSibs(Iterator<Node> lgsibs, Node lg, HashSet<Node> ns, HashSet<Node> os) {
         while (lgsibs.hasNext()) {
-            Node curr = (Node)lgsibs.next();
+            Node curr = lgsibs.next();
             Iterator linkIt = curr.linkNodes.iterator();
             boolean linkFlargest = false;
             if (linkIt.hasNext()) {
@@ -445,21 +455,20 @@ public class Node
         if (equals(node)) {
             this.linkNodes.add(node);
             node.linkNodes.add(this);
-
             h.add(new Nodes(this, node));
         } else {
-            Iterator it = this.children.iterator();
-            while (it.hasNext())
-                ((Node)(Node)it.next()).search(node, h);
+            for(Node child : children) {
+                child.search(node, h);
+            }
         }
     }
 
     private HashSet<Nodes> searchBothNodes(Node node)
     {
-        HashSet<Nodes> sResult = new HashSet();
+        HashSet<Nodes> sResult = new HashSet<>();
         search(node, sResult);
 
-        HashSet<Nodes> nsResult = new HashSet();
+        HashSet<Nodes> nsResult = new HashSet<>();
         node.search(this, nsResult);
 
         for (Nodes curr : nsResult) {
@@ -494,7 +503,7 @@ public class Node
     }
 
     private void resetSearch() {
-        this.linkNodes = new HashSet<Node>();
+        this.linkNodes = new HashSet<>();
         this.linkNode = null;
 
         for (Node child : this.children) {
@@ -502,24 +511,21 @@ public class Node
         }
     }
 
-    private HashSet<Nodes> getLNodes(HashSet<Nodes> h)
-    {
-        HashSet result = new HashSet();
-        int size = 0;
+    /**
+     *
+     * @param h A HashSet
+     * @return The largest Nodes in h, based on the length of n1's Venn diagram
+     */
+    private static HashSet<Nodes> getLNodes(HashSet<Nodes> h) {
+        HashSet<Nodes> result = new HashSet<>();
+        int size = -1;
 
-        Iterator it = h.iterator();
-        if (it.hasNext()) {
-            Nodes curr = (Nodes)it.next();
-            size = curr.nodesSize();
-            result.add(curr);
-        }
-        while (it.hasNext()) {
-            Nodes curr = (Nodes)it.next();
-            if (size < curr.nodesSize()) {
+        for(Nodes curr : h){
+            if (curr.nodesSize() > size) {
                 size = curr.nodesSize();
                 result.clear();
                 result.add(curr);
-            } else if (size == curr.nodesSize()) {
+            } else if (curr.nodesSize() == size) {
                 result.add(curr);
             }
         }
@@ -528,72 +534,64 @@ public class Node
 
     private Node combineAtRoot(Node node)
     {
-        HashSet uniqueNodes = new HashSet();
-        Iterator thisIt = this.children.iterator();
-        Iterator nodeIt = node.children.iterator();
+        HashSet<Node> uniqueNodes = new HashSet<>();
         boolean reduced = false;
-        while (thisIt.hasNext()) {
-            Node curr = (Node)thisIt.next();
+        for(Node curr : this.children) {
             if (!contains(curr, uniqueNodes))
                 uniqueNodes.add(curr);
             else {
                 reduced = true;
             }
         }
-        while (nodeIt.hasNext()) {
-            Node curr = (Node)nodeIt.next();
+        for(Node curr : node.children) {
             if (!contains(curr, uniqueNodes))
                 uniqueNodes.add(curr);
             else {
                 reduced = true;
             }
         }
-        Iterator unIt = uniqueNodes.iterator();
-        String result = "(";
-        while (unIt.hasNext()) {
-            result = result + unIt.next();
-        }
-        result = result + ")";
-
         if (!reduced) {
             return new Node(null, "(" + this.venn + node.getVenn() + ")");
+        } else {
+            String result_venn = "(";
+            for (Node unique : uniqueNodes) {
+                result_venn = result_venn + unique;
+            }
+            result_venn = result_venn + ")";
+            return new Node(null, result_venn);
         }
-        return new Node(null, result);
     }
 
-    private boolean unshared()
-    {
-        if (this.linkNodes.isEmpty())
-        {
-            Iterator it = this.children.iterator();
-            if (!it.hasNext()) {
+    private boolean unshared() {
+        if (this.linkNodes.isEmpty()) {
+            if(this.children.isEmpty()) {
                 return true;
-            }
-            while (it.hasNext()) {
-                if (!((Node)it.next()).unshared()) {
-                    return false;
+            } else {
+                for (Node node : this.children) {
+                    if (!node.unshared()) {
+                        return false;
+                    }
                 }
             }
             return true;
+        } else {
+            return false;
         }
-        return false;
     }
 
     private void collectUnshared(HashSet<Node> h) {
         if (unshared()) {
             h.add(this);
         }
-        Iterator it = this.children.iterator();
-        while (it.hasNext())
-            ((Node)it.next()).collectUnshared(h);
+        for (Node child : children) {
+            child.collectUnshared(h);
+        }
     }
 
     private HashSet<Nodes> getLinkedNodes(HashSet<Node> h)
     {
         HashSet result = new HashSet();
-        Iterator hit = h.iterator();
-        while (hit.hasNext()) {
-            Node curr = (Node)hit.next();
+        for (Node curr : h) {
             if (curr.hasLink() != null)
                 result.add(new Nodes(curr, curr.hasLink()));
         }
@@ -601,11 +599,8 @@ public class Node
     }
 
     private Node hasLink() {
-        HashSet sibs = getSiblings();
-        Iterator it = sibs.iterator();
-        while (it.hasNext()) {
-            Node curr = (Node)it.next();
-
+        HashSet<Node> sibs = getSiblings();
+        for (Node curr : sibs) {
             if (!curr.linkNodes.isEmpty()) {
                 return curr;
             }
@@ -626,10 +621,9 @@ public class Node
         }
         String result = "(" + s;
         if (n.parent != null) {
-            HashSet sibs = n.getSiblings();
-            Iterator it = sibs.iterator();
-            while (it.hasNext()) {
-                result = result + ((Node)it.next()).getVenn();
+            HashSet<Node> sibs = n.getSiblings();
+            for (Node sib : sibs) {
+                result = result + sib.getVenn();
             }
         }
         result = result + ")";
@@ -638,34 +632,26 @@ public class Node
 
     private HashSet<HashSet<Nodes>> reviewPolys(HashSet<Nodes> h)
     {
-        HashSet result = new HashSet();
-        Iterator it = h.iterator();
-        while (it.hasNext()) {
-            HashSet curresult = new HashSet();
-            Nodes curr = (Nodes)it.next();
-            Iterator currIt = h.iterator();
-            while (currIt.hasNext()) {
-                Nodes inCurr = (Nodes)currIt.next();
+        HashSet<HashSet<Nodes>> result = new HashSet<>();
+        for (Nodes curr : h) {
+            HashSet<Nodes> curresult = new HashSet<>();
+            for (Nodes inCurr : h) {
                 if (inCurr == curr) {
                     continue;
                 }
-                HashSet linkedNodes = inCurr.node2.linkNodes;
-                Iterator lnIt = linkedNodes.iterator();
+                HashSet<Node> linkedNodes = inCurr.node2.linkNodes;
                 boolean found = false;
-                while (lnIt.hasNext()) {
-                    Node currln = (Node)lnIt.next();
+                for (Node currln : linkedNodes) {
                     if (currln == curr.node2) {
                         found = true;
                         inCurr.node2.linkNode = currln;
                         break;
                     }
                 }
-
                 if (found) {
                     curresult.add(inCurr);
                 }
             }
-
             if (!curresult.isEmpty()) {
                 curresult.add(curr);
                 result.add(curresult);
@@ -675,42 +661,39 @@ public class Node
     }
 
     private HashSet<Nodes> addPolys(HashSet<Nodes> h) {
-        HashSet setresult = new HashSet();
-        Iterator it = h.iterator();
-        Nodes first = (Nodes)it.next();
-        String result = first.node2.getVenn();
-        result = result + first.node1.getVenn();
-        while (it.hasNext()) {
-            result = result + ((Nodes)it.next()).node1.getVenn();
+        HashSet<Nodes> setResult = new HashSet<>();
+        Nodes first = null;
+        String result = "";
+        for (Nodes nodes : h) {
+            if (first == null) {
+                first = nodes;
+                result = first.node2.getVenn();
+            }
+            result += nodes.node1.getVenn();
         }
-        Iterator itr = h.iterator();
-        while (itr.hasNext()) {
-            Nodes toAdd = new Nodes(((Nodes)itr.next()).node2, new Node(null, "(" + result + ")"));
-            setresult.add(toAdd);
+        for (Nodes nodes : h) {
+            Nodes toAdd = new Nodes((nodes).node2, new Node(null, "(" + result + ")"));
+            setResult.add(toAdd);
         }
-        return setresult;
+        return setResult;
     }
 
     private boolean isIn(Node node) {
         if (this == node) {
             return true;
         }
-        Iterator it = this.children.iterator();
-        while (it.hasNext()) {
-            if (((Node)it.next()).isIn(node)) {
+        for (Node child : this.children) {
+            if (child.isIn(node)) {
                 return true;
             }
         }
-
         return false;
     }
 
     private HashSet<Node> getUniqueNodes(HashSet<Nodes> h)
     {
-        HashSet result = new HashSet();
-        Iterator it = h.iterator();
-        while (it.hasNext()) {
-            Nodes curr = (Nodes)it.next();
+        HashSet<Node> result = new HashSet<>();
+        for (Nodes curr : h) {
             if (!result.contains(curr.node1)) {
                 result.add(curr.node1);
             }
@@ -722,10 +705,8 @@ public class Node
     }
 
     private HashSet<Node> getDuplicates(HashSet<Nodes> h) {
-        HashSet result = new HashSet();
-        Iterator it = h.iterator();
-        while (it.hasNext()) {
-            Nodes curr = (Nodes)it.next();
+        HashSet<Node> result = new HashSet<>();
+        for (Nodes curr : h) {
             if (curr.node1 == this)
                 result.add(curr.node2);
             else if (curr.node2 == this) {
@@ -737,16 +718,13 @@ public class Node
 
     protected Node reduce()
     {
-        HashSet c = this.children;
-        HashSet uniqueC = new HashSet();
-        HashSet dupC = new HashSet();
-        Iterator it = c.iterator();
-        while (it.hasNext()) {
-            Node curr = (Node)it.next();
-            if (contains(curr, uniqueC))
-                dupC.add(curr);
+        HashSet<Node> uniqueC = new HashSet<>();
+        HashSet<Node> dupC = new HashSet<>();
+        for (Node child : this.children) {
+            if (contains(child, uniqueC))
+                dupC.add(child);
             else {
-                uniqueC.add(curr);
+                uniqueC.add(child);
             }
         }
         if ((dupC.isEmpty()) || (this.venn.length() == 1)) {
@@ -769,9 +747,7 @@ public class Node
 
     private boolean contains(Node n, HashSet<Node> h)
     {
-        Iterator it = h.iterator();
-        while (it.hasNext()) {
-            Node curr = (Node)it.next();
+        for (Node curr : h) {
             if (curr.equals(n)) {
                 return true;
             }

+ 56 - 82
src/com/pact/Nodes.java

@@ -3,19 +3,16 @@ package com.pact;
 import java.util.HashSet;
 import java.util.Iterator;
 
-public class Nodes
-{
+public class Nodes {
     Node node1;
     Node node2;
 
-    public Nodes(Node n1, Node n2)
-    {
+    public Nodes(Node n1, Node n2) {
         this.node1 = n1;
         this.node2 = n2;
     }
 
-    public static int setNodesSize(HashSet<Nodes> h)
-    {
+    public static int getNodesSize(HashSet<Nodes> h) {
         Iterator it = h.iterator();
         return ((Nodes)it.next()).nodesSize();
     }
@@ -31,125 +28,102 @@ public class Nodes
 
     public boolean equals(Object o) {
         Nodes input = (Nodes)o;
-
         return ((input.node1 == this.node1) && (input.node2 == this.node2)) || (
                 (input.node1 == this.node2) && (input.node2 == this.node1));
     }
 
-    public HashSet<Node> combineSubTrees()
-    {
-        HashSet comsibs = new HashSet();
+    public HashSet<Node> combineSubTrees() {
+        System.out.println("combineSubTrees==========================");
+        System.out.println("node1: " + node1.getVenn());
+        System.out.println("node2: " + node2.getVenn());
+        HashSet<Node> commonSiblings = new HashSet<>();
 
-        HashSet n1sibs = this.node1.getSiblings();
-        Iterator it2 = n1sibs.iterator();
-        HashSet n2sibs = this.node2.getSiblings();
-        Iterator it1 = n2sibs.iterator();
+        HashSet<Node> node1Siblings = this.node1.getSiblings();
+        Iterator it1 = node1Siblings.iterator();
+        HashSet<Node> node2Siblings = this.node2.getSiblings();
+        Iterator it2 = node2Siblings.iterator();
 
-        String sibs1 = "";
+        String siblingsVenn = "";
 
-        if (it2.hasNext()) {
-            sibs1 = sibs1 + ((Node)it2.next()).getVenn();
-        }
-        else
-        {
+        if (!node1Siblings.isEmpty()) {
+            siblingsVenn = siblingsVenn + ((Node)it2.next()).getVenn();
+        } else {
             if (it1.hasNext()) {
-                sibs1 = sibs1 + ((Node)it1.next()).getVenn();
+                siblingsVenn = siblingsVenn + ((Node)it1.next()).getVenn();
                 if (it1.hasNext()) {
-                    String temp = sibs1;
-                    sibs1 = "(" + temp;
+                    String temp = siblingsVenn;
+                    siblingsVenn = "(" + temp;
                     while (it1.hasNext()) {
-                        sibs1 = sibs1 + ((Node)it1.next()).getVenn();
+                        siblingsVenn = siblingsVenn + ((Node)it1.next()).getVenn();
                     }
-                    sibs1 = sibs1 + ")";
+                    siblingsVenn = siblingsVenn + ")";
                 }
-                comsibs.add(new Node(null, sibs1));
-                return comsibs;
+                commonSiblings.add(new Node(null, siblingsVenn));
+                return commonSiblings;
             }
-
-            return comsibs;
+            return commonSiblings;
         }
 
-        if (it2.hasNext())
-        {
-            String temp = sibs1;
-            sibs1 = "(" + temp;
+        if (it2.hasNext()) {
+            String temp = siblingsVenn;
+            siblingsVenn = "(" + temp;
             while (it2.hasNext()) {
-                sibs1 = sibs1 + ((Node)it2.next()).getVenn();
+                siblingsVenn = siblingsVenn + ((Node)it2.next()).getVenn();
             }
-            sibs1 = sibs1 + ")";
+            siblingsVenn = siblingsVenn + ")";
         }
 
-        Node nodesibs1 = new Node(null, sibs1);
+        Node nodesibs1 = new Node(null, siblingsVenn);
         if (!it1.hasNext()) {
-            comsibs.add(nodesibs1);
-            return comsibs;
+            commonSiblings.add(nodesibs1);
+            return commonSiblings;
         }
-        String sibs2 = "";
+        String siblings2 = "";
         if (it1.hasNext()) {
-            sibs2 = sibs2 + ((Node)it1.next()).getVenn();
+            siblings2 = siblings2 + ((Node)it1.next()).getVenn();
             if (it1.hasNext()) {
-                String temp = sibs2;
-                sibs2 = "(" + temp;
+                String temp = siblings2;
+                siblings2 = "(" + temp;
                 while (it1.hasNext()) {
-                    sibs2 = sibs2 + ((Node)it1.next()).getVenn();
+                    siblings2 = siblings2 + ((Node)it1.next()).getVenn();
                 }
-                sibs2 = sibs2 + ")";
+                siblings2 = siblings2 + ")";
             }
         }
 
-        Node nodesibs2 = new Node(null, sibs2);
-        return nodesibs1.combine(nodesibs2);
-    }
-
-    private boolean inSet(Node n, Iterator<Node> it)
-    {
-        boolean inSet = false;
-        while (it.hasNext()) {
-            if (n.equals((Node)it.next())) {
-                inSet = true;
-                break;
-            }
+        Node nodeSibs2 = new Node(null, siblings2);
+        HashSet<Node> result =  nodesibs1.combine(nodeSibs2);
+        System.out.println("result: ");
+        for(Node n : result){
+            System.out.println("\t " + n.getVenn());
         }
-        return inSet;
+        return result;
     }
 
     protected HashSet<Nodes> combineNew()
     {
-        HashSet setResult = new HashSet();
-        Node rnode1 = new Node(null, this.node2.root().getVenn());
+        HashSet<Nodes> setResult = new HashSet<>();
+        Node resultNode1 = new Node(null, this.node2.root().getVenn());
         String added = "(" + this.node2.getVenn() + this.node1.getVenn() + ")";
 
-        HashSet ln = this.node2.linkNodes;
-
-        Iterator lnIt = ln.iterator();
-        while (lnIt.hasNext()) {
-            String result = buildUp((Node)lnIt.next(), added);
-            Node rnode2 = new Node(null, result);
-            setResult.add(new Nodes(rnode1, rnode2));
+        for (Node linkNode : node2.linkNodes) {
+            String result = buildUp(linkNode, added);
+            Node resultNode2 = new Node(null, result);
+            setResult.add(new Nodes(resultNode1, resultNode2));
         }
-
         return setResult;
     }
 
-    private String buildUp(Node n, String s)
-    {
+    private String buildUp(Node n, String s) {
         if (n.parent == null) {
             return s;
         }
-        String result = s;
-        if (n.parent != null) {
-            HashSet sibs = n.getSiblings();
-            Iterator it = sibs.iterator();
-            if (it.hasNext()) {
-                String temp = "(" + result;
-                result = temp;
-
-                while (it.hasNext()) {
-                    result = result + ((Node)it.next()).getVenn();
-                }
-                result = result + ")";
+        else {
+            String result = s;
+            for(Node sibling : n.getSiblings()){
+                result +=  sibling.getVenn();
             }
+            return buildUp(n.parent, "(" + result + ")");
         }
-        return buildUp(n.parent, result);
     }
 }

+ 181 - 0
src/com/pact/com/pact/test/NodeTest.java

@@ -0,0 +1,181 @@
+package com.pact.com.pact.test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import com.pact.Node;
+import com.pact.Nodes;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashSet;
+
+class NodeTest {
+
+    @Test
+    public void equalsTest1(){
+        Node node1 = new Node(null, "(ABC)");
+        Node node2 = new Node(null, "(AB)");
+        assertFalse(node1.equals(node2));
+    }
+
+    @Test
+    public void equalsTest2(){
+        Node node1 = new Node(null, "(ABC)");
+        Node node2 = new Node(null, "(AB)");
+        assertFalse(node2.equals(node1));
+    }
+
+    @Test
+    public void equalsTest3(){
+        Node node1 = new Node(null, "((BC)A)");
+        Node node2 = new Node(null, "(A(CB))");
+        assertTrue(node1.equals(node2));
+    }
+
+    @Test
+    public void equalsTest4(){
+        Node node1 = new Node(null, "(A(BC))");
+        Node node2 = new Node(null, "(A(BCD))");
+        assertFalse(node1.equals(node2));
+    }
+
+    @Test
+    public void searchTest1() {
+        Node node1 = new Node(null, "(A(B(C(DA))))");
+        Node node2 = new Node(null, "(A(B(CD)))");
+        HashSet<Nodes> result = new HashSet<>();
+        node2.deepSearch(node1, result);
+        System.out.println(result);
+    }
+
+    void reducedCombineTest(String s1, String s2, String sResult){
+        Node node1 = new Node(null, s1);
+        Node node2 = new Node(null, s2);
+        HashSet<Node> results = node1.reducedCombine(node2);
+        for(Node result : results)
+            System.out.println("" + node1 + " + " + node2 + " => " + result);
+        assertTrue(results.size() == 1);
+        Node result = results.iterator().next();
+        assertEquals(new Node(null, sResult), result);
+    }
+
+    void reducedCombineTest(String s1, String s2, String[] sResults){
+        Node node1 = new Node(null, s1);
+        Node node2 = new Node(null, s2);
+        HashSet<Node> results = node1.reducedCombine(node2);
+        for(Node result : results)
+            System.out.println("" + node1 + " + " + node2 + " => " + result);
+        assertTrue(results.size() == sResults.length);
+        for (String sResult : sResults) {
+            Node testNode = new Node(null, sResult);
+            boolean found = false;
+            for(Node node : results) {
+                if(testNode.equals(node)) {
+                    found = true;
+                    break;
+                }
+            }
+            assertTrue(found);
+        }
+    }
+
+    @Test
+    public void reducedCombineTest1() {
+        reducedCombineTest("(DB)", "(AC)","((DB)(AC))");
+    }
+
+    @Test
+    public void reducedCombineTest2() {
+        reducedCombineTest("(A(BDC))", "((CDB)A)", "(A(BDC))");
+    }
+
+
+    @Test
+    public void reducedCombineTest3() {
+        reducedCombineTest("(A(CD))", "(A(B(CD)))", "(A(B(CD)))");
+    }
+
+    @Test
+    public void reducedCombineTest4() {
+        reducedCombineTest("(A((BE)(CD)))", "(A(B(CD)))", "(A((BE)(CD)))");
+    }
+
+    @Test
+    public void reducedCombineTest5() {
+        reducedCombineTest("(A(A(B(CD))))", "(A((BE)(C(DA))))", "((((BE)(C(DA)))A)A)");
+    }
+
+    @Test
+    public void reducedCombineTest6() {
+        reducedCombineTest("(A(B(CD)))", "((A(B(CD)))(A(B(CD))))", "(A(B(CD)))");
+    }
+
+    @Test
+    public void reducedCombineTest7() {
+        reducedCombineTest("(A(CD))", "(A(B(C(DA))))", "(A(B(C(DA))))");
+    }
+
+    @Test
+    public void reducedCombineTest8() {
+        reducedCombineTest("(A(B(CD)))", "(A(B(C(DA))))", "(A(B(C(DA))))");
+    }
+
+    @Test
+    public void reducedCombineTest9() {
+        reducedCombineTest("A", "B", "(AB)");
+    }
+
+    @Test
+    public void reducedCombineTest10() {
+        reducedCombineTest("(A(B(D((CE)(CD)))))", "(F(C(DB)((D(BE))(CD))))", "(((((CD)((ECB)D))C(DB))BF)A)");
+    }
+
+    @Test
+    public void reducedCombineTest10b() {
+        reducedCombineTest("(A(B(D((CE)(CD)))))", "(F(C(DB)((D(BE))(CD))))", "(((((CD)((ECB)D))C(DB))BF)A)");
+    }
+
+    @Test
+    public void reducedCombineTest11() {
+        reducedCombineTest("((AB)(CD))", "(E(F(GA)))", "(((AB)(CD))(E(F(GA))))");
+    }
+
+    @Test
+    public void reducedCombineTest12() {
+        reducedCombineTest("(A(B(CD)))", "(D(C(BA)))", "((A(B(CD)))(D(C(BA))))");
+    }
+
+    @Test
+    public void reducedCombineTest13() {
+        reducedCombineTest("(A(CD))", "(A(BE))", "(A(CD)(BE))");
+    }
+
+    @Test
+    public void reducedCombineTest14() {
+        reducedCombineTest("(A(CD)(BE))", "(A((CD)(BE)))", "(A((CD)(BE)))");
+    }
+
+    @Test
+    public void reducedCombineTest15() {
+        String results[] = {"((AC)(AB))", "(((AC)B)A)"};
+        reducedCombineTest("((AC)B)", "(A(AB))", results);
+    }
+
+    @Test
+    public void reducedCombineTest16() {
+        String results[] = {"(((BA)C)A)", "(((CA)B)A)"};
+        reducedCombineTest("((AC)BA)", "(A(CB))", results);
+    }
+
+    @Test
+    public void reducedCombineTest17() {
+        reducedCombineTest("(A(BC))", "(DB)", "((A(BC))(DB))");
+    }
+
+    @Test
+    public void reducedCombineTest18() {
+        reducedCombineTest("(((TH)(IS))(R(E(AL))))", "(((TH)(IS))(T(RE)))",
+                           "(((TH)(IS))(((E(AL))R)T))");
+    }
+
+
+}