From: jjenista Date: Thu, 24 Jun 2010 16:57:05 +0000 (+0000) Subject: just an interesting test case I never got around to checking in or exploring too... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=cb86b4aeba07725f9660d88a3b05c52b07795d64;p=IRC.git just an interesting test case I never got around to checking in or exploring too much --- diff --git a/Robust/src/Tests/disjoint/treeTraversal/makefile b/Robust/src/Tests/disjoint/treeTraversal/makefile new file mode 100644 index 00000000..3afb07d6 --- /dev/null +++ b/Robust/src/Tests/disjoint/treeTraversal/makefile @@ -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 index 00000000..fc19be9c --- /dev/null +++ b/Robust/src/Tests/disjoint/treeTraversal/test.java @@ -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() ); + } +}