Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2149 → Rev 2150

/trunk/api/js/dojo1.0/dojox/lang/tests/runTests.html
New file
0,0 → 1,9
<html>
<head>
<title>DojoX Functional Unit Test Runner</title>
<meta http-equiv="REFRESH" content="0;url=../../../util/doh/runner.html?testModule=dojox.lang.tests.main" />
</head>
<body>
<p>Redirecting to D.O.H runner.</p>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/lang/tests/lambda.js
New file
0,0 → 1,22
if(!dojo._hasResource["dojox.lang.tests.lambda"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.lambda"] = true;
dojo.provide("dojox.lang.tests.lambda");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional;
tests.register("dojox.lang.tests.lambda", [
function testLambda1(t){ t.assertEqual(df.repeat(3, "3*", 1), [1, 3, 9]); },
function testLambda2(t){ t.assertEqual(df.repeat(3, "*3", 1), [1, 3, 9]); },
function testLambda3(t){ t.assertEqual(df.repeat(3, "_*3", 1), [1, 3, 9]); },
function testLambda4(t){ t.assertEqual(df.repeat(3, "3*_", 1), [1, 3, 9]); },
function testLambda5(t){ t.assertEqual(df.repeat(3, "n->n*3", 1), [1, 3, 9]); },
function testLambda6(t){ t.assertEqual(df.repeat(3, "n*3", 1), [1, 3, 9]); },
function testLambda7(t){ t.assertEqual(df.repeat(3, "3*m", 1), [1, 3, 9]); },
function testLambda8(t){ t.assertEqual(df.repeat(3, "->1", 1), [1, 1, 1]); },
function testLambda9(t){ t.assertEqual(df.repeat(3, function(n){ return n * 3; }, 1), [1, 3, 9]); },
function testLambda10(t){ t.assertEqual(df.repeat(3, ["_-1", ["*3"]], 1), [1, 2, 5]); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/curry.js
New file
0,0 → 1,30
if(!dojo._hasResource["dojox.lang.tests.curry"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.curry"] = true;
dojo.provide("dojox.lang.tests.curry");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional, add5 = df.curry("+")(5), sub3 = df.curry("_-3"), fun = df.lambda("100*a + 10*b + c");
tests.register("dojox.lang.tests.curry", [
function testCurry1(t){ t.assertEqual(df.curry("+")(1, 2), 3); },
function testCurry2(t){ t.assertEqual(df.curry("+")(1)(2), 3); },
function testCurry3(t){ t.assertEqual(df.curry("+")(1, 2, 3), 3); },
function testCurry4(t){ t.assertEqual(add5(1), 6); },
function testCurry5(t){ t.assertEqual(add5(3), 8); },
function testCurry6(t){ t.assertEqual(add5(5), 10); },
function testCurry7(t){ t.assertEqual(sub3(1), -2); },
function testCurry8(t){ t.assertEqual(sub3(3), 0); },
function testCurry9(t){ t.assertEqual(sub3(5), 2); },
function testPartial1(t){ t.assertEqual(df.partial(fun, 1, 2, 3)(), 123); },
function testPartial2(t){ t.assertEqual(df.partial(fun, 1, 2, df.arg)(3), 123); },
function testPartial3(t){ t.assertEqual(df.partial(fun, 1, df.arg, 3)(2), 123); },
function testPartial4(t){ t.assertEqual(df.partial(fun, 1, df.arg, df.arg)(2, 3), 123); },
function testPartial5(t){ t.assertEqual(df.partial(fun, df.arg, 2, 3)(1), 123); },
function testPartial6(t){ t.assertEqual(df.partial(fun, df.arg, 2, df.arg)(1, 3), 123); },
function testPartial7(t){ t.assertEqual(df.partial(fun, df.arg, df.arg, 3)(1, 2), 123); },
function testPartial8(t){ t.assertEqual(df.partial(fun, df.arg, df.arg, df.arg)(1, 2, 3), 123); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/fold.js
New file
0,0 → 1,33
if(!dojo._hasResource["dojox.lang.tests.fold"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.fold"] = true;
dojo.provide("dojox.lang.tests.fold");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional, a = df.arg;
tests.register("dojox.lang.tests.fold", [
function testFoldl1(t){ t.assertEqual(df.foldl([1, 2, 3], "+", 0), 6); },
function testFoldl2(t){ t.assertEqual(df.foldl1([1, 2, 3], "*"), 6); },
function testFoldl3(t){ t.assertEqual(df.foldl1([1, 2, 3], "/"), 1/6); },
function testFoldl4(t){ t.assertEqual(df.foldl1([1, 2, 3], df.partial(Math.max, a, a)), 3); },
function testFoldl5(t){ t.assertEqual(df.foldl1([1, 2, 3], df.partial(Math.min, a, a)), 1); },
function testFoldr1(t){ t.assertEqual(df.foldr([1, 2, 3], "+", 0), 6); },
function testFoldr2(t){ t.assertEqual(df.foldr1([1, 2, 3], "*"), 6); },
function testFoldr3(t){ t.assertEqual(df.foldr1([1, 2, 3], "/"), 3/2); },
function testFoldr4(t){ t.assertEqual(df.foldr1([1, 2, 3], df.partial(Math.max, a, a)), 3); },
function testFoldr5(t){ t.assertEqual(df.foldr1([1, 2, 3], df.partial(Math.min, a, a)), 1); },
function testScanl1(t){ t.assertEqual(df.scanl([1, 2, 3], "+", 0), [0, 1, 3, 6]); },
function testScanl2(t){ t.assertEqual(df.scanl1([1, 2, 3], "*"), [1, 2, 6]); },
function testScanl3(t){ t.assertEqual(df.scanl1([1, 2, 3], df.partial(Math.max, a, a)), [1, 2, 3]); },
function testScanl4(t){ t.assertEqual(df.scanl1([1, 2, 3], df.partial(Math.min, a, a)), [1, 1, 1]); },
function testScanr1(t){ t.assertEqual(df.scanr([1, 2, 3], "+", 0), [6, 5, 3, 0]); },
function testScanr2(t){ t.assertEqual(df.scanr1([1, 2, 3], "*"), [6, 6, 3]); },
function testScanr3(t){ t.assertEqual(df.scanr1([1, 2, 3], df.partial(Math.max, a, a)), [3, 3, 3]); },
function testScanr4(t){ t.assertEqual(df.scanr1([1, 2, 3], df.partial(Math.min, a, a)), [1, 2, 3]); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/main.js
New file
0,0 → 1,16
if(!dojo._hasResource["dojox.lang.tests.test_fun"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.test_fun"] = true;
dojo.provide("dojox.lang.tests.test_fun");
 
try{
dojo.require("dojox.lang.tests.listcomp");
dojo.require("dojox.lang.tests.lambda");
dojo.require("dojox.lang.tests.fold");
dojo.require("dojox.lang.tests.curry");
dojo.require("dojox.lang.tests.misc");
dojo.require("dojox.lang.tests.std");
}catch(e){
doh.debug(e);
}
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/listcomp.js
New file
0,0 → 1,26
if(!dojo._hasResource["dojox.lang.tests.listcomp"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.listcomp"] = true;
dojo.provide("dojox.lang.tests.listcomp");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional;
tests.register("dojox.lang.tests.listcomp", [
function testIterator1(t){ t.assertEqual(df.repeat(3, function(n){ return n + 1; }, 0), [0, 1, 2]); },
function testIterator2(t){ t.assertEqual(df.repeat(3, function(n){ return n * 3; }, 1), [1, 3, 9]); },
function testIterator3(t){ t.assertEqual(df.until(function(n){ return n > 10; }, function(n){ return n * 3; }, 1), [1, 3, 9]); },
function testListcomp1(t){ t.assertEqual(df.listcomp("i for(var i=0; i<3; ++i)"), [0, 1, 2]); },
function testListcomp2(t){ t.assertEqual(df.listcomp("i*j for(var i=0; i<3; ++i) for(var j=0; j<3; ++j)"), [0, 0, 0, 0, 1, 2, 0, 2, 4]); },
function testListcomp3(t){ t.assertEqual(df.listcomp("i*j for(var i=0; i<3; ++i) if(i%2==1) for(var j=0; j<3; ++j)"), [0, 1, 2]); },
function testListcomp4(t){ t.assertEqual(df.listcomp("i+j for(var i=0; i<3; ++i) for(var j=0; j<3; ++j)"), [0, 1, 2, 1, 2, 3, 2, 3, 4]); },
function testListcomp5(t){ t.assertEqual(df.listcomp("i+j for(var i=0; i<3; ++i) if(i%2==1) for(var j=0; j<3; ++j)"), [1, 2, 3]); },
function testListcomp6(t){ t.assertEqual(df.listcomp("i for(i=0; i<3; ++i)"), [0, 1, 2]); },
function testListcomp7(t){ t.assertEqual(df.listcomp("i*j for(i=0; i<3; ++i) for(j=0; j<3; ++j)"), [0, 0, 0, 0, 1, 2, 0, 2, 4]); },
function testListcomp8(t){ t.assertEqual(df.listcomp("i*j for(i=0; i<3; ++i) if(i%2==1) for(j=0; j<3; ++j)"), [0, 1, 2]); },
function testListcomp9(t){ t.assertEqual(df.listcomp("i+j for(i=0; i<3; ++i) for(j=0; j<3; ++j)"), [0, 1, 2, 1, 2, 3, 2, 3, 4]); },
function testListcomp10(t){ t.assertEqual(df.listcomp("i+j for(i=0; i<3; ++i) if(i%2==1) for(j=0; j<3; ++j)"), [1, 2, 3]); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/std.js
New file
0,0 → 1,31
if(!dojo._hasResource["dojox.lang.tests.std"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.std"] = true;
dojo.provide("dojox.lang.tests.std");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional, v, isOdd = "%2";
tests.register("dojox.lang.tests.std", [
function testFilter1(t){ t.assertEqual(df.filter([1, 2, 3], isOdd), [1, 3]); },
function testFilter2(t){ t.assertEqual(df.filter([1, 2, 3], "%2==0"), [2]); },
function testForEach(t){ t.assertEqual(
(v = [], df.forEach([1, 2, 3], function(x){ v.push(x); }), v), [1, 2, 3]); },
function testMap(t){ t.assertEqual(df.map([1, 2, 3], "+3"), [4, 5, 6]); },
function testEvery1(t){ t.assertFalse(df.every([1, 2, 3], isOdd)); },
function testEvery2(t){ t.assertTrue(df.every([1, 3, 5], isOdd)); },
 
function testSome1(t){ t.assertFalse(df.some([2, 4, 6], isOdd)); },
function testSome2(t){ t.assertTrue(df.some([1, 2, 3], isOdd)); },
 
function testReduce1(t){ t.assertEqual(df.reduce([4, 2, 1], "x-y"), 1); },
function testReduce2(t){ t.assertEqual(df.reduce([4, 2, 1], "x-y", 8), 1); },
function testReduceRight1(t){ t.assertEqual(df.reduceRight([4, 2, 1], "x-y"), -5); },
function testReduceRight2(t){ t.assertEqual(df.reduceRight([4, 2, 1], "x-y", 8), 1); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/misc.js
New file
0,0 → 1,36
if(!dojo._hasResource["dojox.lang.tests.misc"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.misc"] = true;
dojo.provide("dojox.lang.tests.misc");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional, fun = df.lambda("100*a + 10*b + c"), result = [];
df.forIn({a: 1, b: 2}, function(v, i){ result.push("[" + i + "] = " + v); });
tests.register("dojox.lang.tests.misc", [
function testZip1(t){ t.assertEqual(df.zip([1, 2, 3], [4, 5, 6]), [[1, 4], [2, 5], [3, 6]]); },
function testZip2(t){ t.assertEqual(df.zip([1, 2], [3, 4], [5, 6]), [[1, 3, 5], [2, 4, 6]]); },
function testUnzip1(t){ t.assertEqual(df.unzip([[1, 4], [2, 5], [3, 6]]), [[1, 2, 3], [4, 5, 6]]); },
function testUnzip2(t){ t.assertEqual(df.unzip([[1, 3, 5], [2, 4, 6]]), [[1, 2], [3, 4], [5, 6]]); },
function testConst1(t){ t.assertEqual(df.constFun(5)(), 5); },
function testConst2(t){ t.assertEqual(df.constFun(8)(), 8); },
function testInvoke1(t){ t.assertEqual(df.invoke("max")(Math, 1, 2), 2); },
function testInvoke2(t){ t.assertEqual(df.invoke("min")(Math, 1, 2), 1); },
function testPluck1(t){ t.assertEqual(df.pluck("PI")(Math), Math.PI); },
function testPluck2(t){ t.assertEqual(df.pluck("E")(Math), Math.E); },
function testMixer(t){ t.assertEqual(df.mixer(fun, [1, 2, 0])(3, 1, 2), 123); },
function testFlip(t){ t.assertEqual(df.flip(fun)(3, 2, 1), 123); },
function testCompose1(t){ t.assertEqual(df.lambda(["+5", "*3"])(8), 8 * 3 + 5); },
function testCompose2(t){ t.assertEqual(df.lambda(["+5", "*3"].reverse())(8), (8 + 5) * 3); },
function testForIn(t){ t.assertEqual(result.sort().join(", "), "[a] = 1, [b] = 2"); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/fun_perf.html
New file
0,0 → 1,61
<html>
<head>
<title>clocking fun</title>
<style type="text/css">
@import "../resources/dojo.css";
</style>
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:true"></script>
<script type="text/javascript" src="../functional.js"></script>
<script type="text/javascript">
dojo.addOnLoad(function(){
var LEN = 1000, ITER = 100, SUM = (LEN - 1) * LEN / 2;
var foldl_1 = function(/*Array*/ a, /*Function*/ f, /*Object*/ z){
for(var i = 0; i < a.length; z = f.call(dojo.global, z, a[i++]));
return z;
};
var foldl_2 = function(/*Array*/ a, /*Function*/ f, /*Object*/ z){
dojo.forEach(a, function(x){ z = f.call(dojo.global, z, x); });
return z;
};
var foldl_3 = function(/*Array*/ a, /*Function*/ f, /*Object*/ z){
a.forEach(function(x){ z = f.call(dojo.global, z, x); });
return z;
};
var sample = dojox.lang.functional.repeat(LEN, function(x){ return x + 1; }, 0);
console.profile("dojox.lang.functional.foldl");
for(var i = 0; i < ITER; ++i){
var t = dojox.lang.functional.foldl(sample, function(a, b){ return a + b; }, 0);
console.assert(t == SUM);
}
console.profileEnd("dojox.lang.functional.foldl");
console.profile("dojox.lang.functional.reduce");
for(var i = 0; i < ITER; ++i){
var t = dojox.lang.functional.reduce(sample, function(a, b){ return a + b; });
console.assert(t == SUM);
}
console.profileEnd("dojox.lang.functional.reduce");
console.profile("raw loop");
for(var i = 0; i < ITER; ++i){
var t = foldl_1(sample, function(a, b){ return a + b; }, 0);
console.assert(t == SUM);
}
console.profileEnd("raw loop");
console.profile("dojo.forEach");
for(var i = 0; i < ITER; ++i){
var t = foldl_2(sample, function(a, b){ return a + b; }, 0);
console.assert(t == SUM);
}
console.profileEnd("dojo.forEach");
console.profile("Array.forEach");
for(var i = 0; i < ITER; ++i){
var t = foldl_3(sample, function(a, b){ return a + b; }, 0);
console.assert(t == SUM);
}
console.profileEnd("Array.forEach");
});
</script>
</head>
<body>
<p>This test is meant to run on Firefox with Firebug installed.</p>
</body>
</html>