just an interesting test case I never got around to checking in or exploring too...
authorjjenista <jjenista>
Thu, 24 Jun 2010 16:57:05 +0000 (16:57 +0000)
committerjjenista <jjenista>
Thu, 24 Jun 2010 16:57:05 +0000 (16:57 +0000)
Robust/src/Tests/disjoint/treeTraversal/makefile [new file with mode: 0644]
Robust/src/Tests/disjoint/treeTraversal/test.java [new file with mode: 0644]

diff --git a/Robust/src/Tests/disjoint/treeTraversal/makefile b/Robust/src/Tests/disjoint/treeTraversal/makefile
new file mode 100644 (file)
index 0000000..3afb07d
--- /dev/null
@@ -0,0 +1,18 @@
+PROGRAM=test
+
+SOURCE_FILES=$(PROGRAM).java
+
+BUILDSCRIPT=~/research/Robust/src/buildscript
+
+BSFLAGS= -mainclass Test -mlp 8 2
+OWNERSHIP= -ownership -ownallocdepth 1 -methodeffects 
+
+all: $(PROGRAM).bin
+
+$(PROGRAM).bin: $(SOURCE_FILES)
+       $(BUILDSCRIPT) $(BSFLAGS) $(OWNERSHIP) $(DEBUGFLAGS) -o $(PROGRAM) $(SOURCE_FILES)
+
+clean:
+       rm -f  $(PROGRAM).bin
+       rm -fr tmpbuilddirectory
+       rm -f  *~
diff --git a/Robust/src/Tests/disjoint/treeTraversal/test.java b/Robust/src/Tests/disjoint/treeTraversal/test.java
new file mode 100644 (file)
index 0000000..fc19be9
--- /dev/null
@@ -0,0 +1,59 @@
+public class Node {
+
+  public Node( int v, Node l, Node r ) {
+    left   = l;
+    right  = r;
+    this.v = v;
+  }
+
+  public Node left;
+  public Node right;
+
+  public int v;
+  public int t;
+
+  public int computeTotal() {
+    t = v;
+    if( left != null ) {
+      sese left {
+        t += left.computeTotal();
+      }
+    }
+    if( right != null ) {
+      sese right {
+        t += right.computeTotal();
+      }
+    }
+    return t;
+  }
+}
+
+public class Test {
+
+  static public void main( String[] args ) {
+
+    // total = 1+2+4+2+6+3+7+1+3+1+2 = 32
+    Node root = 
+      new Node( 1,
+                new Node( 2,
+                          new Node( 4,
+                                    new Node( 2,
+                                              new Node( 6, null, null ),
+                                              null
+                                              ),
+                                    new Node( 3, null, null )
+                                    ),
+                          new Node( 7, 
+                                    null,
+                                    new Node( 1, null, null )
+                                    )
+                          ),
+                new Node( 3,
+                          new Node( 1, null, null ),
+                          new Node( 2, null, null )
+                          )
+                );
+
+    System.out.println( "total="+root.computeTotal() );    
+  }
+}