- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / dromaeo / tests / sunspider-access-binary-trees.html
1 <html>
2 <head>
3 <script src="../htmlrunner.js"></script>
4 <script>
5 /* The Great Computer Language Shootout
6    http://shootout.alioth.debian.org/
7    contributed by Isaac Gouy */
8
9 function TreeNode(left,right,item){
10    this.left = left;
11    this.right = right;
12    this.item = item;
13 }
14
15 TreeNode.prototype.itemCheck = function(){
16    if (this.left==null) return this.item;
17    else return this.item + this.left.itemCheck() - this.right.itemCheck();
18 }
19
20 function bottomUpTree(item,depth){
21    if (depth>0){
22       return new TreeNode(
23           bottomUpTree(2*item-1, depth-1)
24          ,bottomUpTree(2*item, depth-1)
25          ,item
26       );
27    }
28    else {
29       return new TreeNode(null,null,item);
30    }
31 }
32
33 window.onload = function(){ startTest("sunspider-access-binary-trees", 'c1dfeea3');
34
35 var ret;
36
37 test( "Binary Trees", function(){
38         for ( var n = 4; n <= 5; n += 1 ) {
39         var minDepth = 4;
40         var maxDepth = Math.max(minDepth + 2, n);
41         var stretchDepth = maxDepth + 1;
42         
43         var check = bottomUpTree(0,stretchDepth).itemCheck();
44         
45         var longLivedTree = bottomUpTree(0,maxDepth);
46         for (var depth=minDepth; depth<=maxDepth; depth+=2){
47            var iterations = 1 << (maxDepth - depth + minDepth);
48         
49            check = 0;
50            for (var i=1; i<=iterations; i++){
51                   check += bottomUpTree(i,depth).itemCheck();
52                   check += bottomUpTree(-i,depth).itemCheck();
53            }
54         }
55         
56         ret = longLivedTree.itemCheck();
57         }
58 });
59
60 endTest(); };
61 </script>
62 </head>
63 <body></body>
64 </html>