From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojox/lang/tests/array.js | 84 ++++++++++++++ includes/js/dojox/lang/tests/curry.js | 31 +++++ includes/js/dojox/lang/tests/fold.js | 64 +++++++++++ includes/js/dojox/lang/tests/fun_perf.html | 176 +++++++++++++++++++++++++++++ includes/js/dojox/lang/tests/lambda.js | 24 ++++ includes/js/dojox/lang/tests/listcomp.js | 28 +++++ includes/js/dojox/lang/tests/main.js | 17 +++ includes/js/dojox/lang/tests/misc.js | 31 +++++ includes/js/dojox/lang/tests/runTests.html | 9 ++ 9 files changed, 464 insertions(+) create mode 100644 includes/js/dojox/lang/tests/array.js create mode 100644 includes/js/dojox/lang/tests/curry.js create mode 100644 includes/js/dojox/lang/tests/fold.js create mode 100644 includes/js/dojox/lang/tests/fun_perf.html create mode 100644 includes/js/dojox/lang/tests/lambda.js create mode 100644 includes/js/dojox/lang/tests/listcomp.js create mode 100644 includes/js/dojox/lang/tests/main.js create mode 100644 includes/js/dojox/lang/tests/misc.js create mode 100644 includes/js/dojox/lang/tests/runTests.html (limited to 'includes/js/dojox/lang/tests') diff --git a/includes/js/dojox/lang/tests/array.js b/includes/js/dojox/lang/tests/array.js new file mode 100644 index 0000000..292210c --- /dev/null +++ b/includes/js/dojox/lang/tests/array.js @@ -0,0 +1,84 @@ +if(!dojo._hasResource["dojox.lang.tests.array"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.lang.tests.array"] = true; +dojo.provide("dojox.lang.tests.array"); + +dojo.require("dojox.lang.functional"); +dojo.require("dojox.lang.functional.fold"); +dojo.require("dojox.lang.functional.reversed"); + +(function(){ + var df = dojox.lang.functional, v, isOdd = "%2"; + + var revArrayIter = function(array){ + this.array = array; + this.position = array.length - 1; + }; + dojo.extend(revArrayIter, { + hasNext: df.lambda("this.position >= 0"), + next: df.lambda("this.array[this.position--]") + }); + + tests.register("dojox.lang.tests.array", [ + 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 testFilterIter(t){ + var iter = new revArrayIter([1, 2, 3]); + t.assertEqual(df.filter(iter, isOdd), [3, 1]); + }, + function testFilterRev(t){ + var iter = new revArrayIter([1, 2, 3]); + t.assertEqual(df.filter(iter, isOdd), df.filterRev([1, 2, 3], isOdd)); + }, + + function testForEach(t){ + t.assertEqual((v = [], df.forEach([1, 2, 3], function(x){ v.push(x); }), v), [1, 2, 3]); + }, + function testForEachIter(t){ + var iter = new revArrayIter([1, 2, 3]); + t.assertEqual((v = [], df.forEach(iter, function(x){ v.push(x); }), v), [3, 2, 1]); + }, + function testForEachRev(t){ + t.assertEqual((v = [], df.forEachRev([1, 2, 3], function(x){ v.push(x); }), v), [3, 2, 1]); + }, + + function testMap(t){ t.assertEqual(df.map([1, 2, 3], "+3"), [4, 5, 6]); }, + function testMapIter(t){ + var iter = new revArrayIter([1, 2, 3]); + t.assertEqual(df.map(iter, "+3"), [6, 5, 4]); + }, + function testMapRev(t){ + var iter = new revArrayIter([1, 2, 3]); + t.assertEqual(df.map(iter, "+3"), df.mapRev([1, 2, 3], "+3")); + }, + + function testEvery1(t){ t.assertFalse(df.every([1, 2, 3], isOdd)); }, + function testEvery2(t){ t.assertTrue(df.every([1, 3, 5], isOdd)); }, + function testEveryIter(t){ + var iter = new revArrayIter([1, 3, 5]); + t.assertTrue(df.every(iter, isOdd)); + }, + function testEveryRev1(t){ t.assertFalse(df.everyRev([1, 2, 3], isOdd)); }, + function testEveryRev2(t){ t.assertTrue(df.everyRev([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 testSomeIter(t){ + var iter = new revArrayIter([1, 2, 3]); + t.assertTrue(df.some(iter, isOdd)); + }, + function testSomeRev1(t){ t.assertFalse(df.someRev([2, 4, 6], isOdd)); }, + function testSomeRev2(t){ t.assertTrue(df.someRev([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 testReduceIter(t){ + var iter = new revArrayIter([1, 2, 4]); + t.assertEqual(df.reduce(iter, "x-y"), 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); } + ]); +})(); + +} diff --git a/includes/js/dojox/lang/tests/curry.js b/includes/js/dojox/lang/tests/curry.js new file mode 100644 index 0000000..cb6fa6a --- /dev/null +++ b/includes/js/dojox/lang/tests/curry.js @@ -0,0 +1,31 @@ +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.curry"); + +(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); } + ]); +})(); + +} diff --git a/includes/js/dojox/lang/tests/fold.js b/includes/js/dojox/lang/tests/fold.js new file mode 100644 index 0000000..e766c62 --- /dev/null +++ b/includes/js/dojox/lang/tests/fold.js @@ -0,0 +1,64 @@ +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.fold"); +dojo.require("dojox.lang.functional.scan"); +dojo.require("dojox.lang.functional.curry"); + +(function(){ + var df = dojox.lang.functional, a = df.arg; + + var revArrayIter = function(array){ + this.array = array; + this.position = array.length - 1; + }; + dojo.extend(revArrayIter, { + hasNext: df.lambda("this.position >= 0"), + next: df.lambda("this.array[this.position--]") + }); + + 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 testFoldlIter(t){ + var iter = new revArrayIter([1, 2, 3]); + t.assertEqual(df.foldl(iter, "+", 0), 6); + }, + function testFoldl1Iter(t){ + var iter = new revArrayIter([1, 2, 3]); + t.assertEqual(df.foldl1(iter, "/"), 3/2); + }, + + 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 testScanlIter(t){ + var iter = new revArrayIter([1, 2, 3]); + t.assertEqual(df.scanl(iter, "+", 0), [0, 3, 5, 6]); + }, + function testScanl1Iter(t){ + var iter = new revArrayIter([1, 2, 3]); + t.assertEqual(df.scanl1(iter, "*"), [3, 6, 6]); + }, + + 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]); } + ]); +})(); + +} diff --git a/includes/js/dojox/lang/tests/fun_perf.html b/includes/js/dojox/lang/tests/fun_perf.html new file mode 100644 index 0000000..9d19a60 --- /dev/null +++ b/includes/js/dojox/lang/tests/fun_perf.html @@ -0,0 +1,176 @@ + + + clocking fun + + + + + + + + +

This test is meant to run with Firebug.

+ + diff --git a/includes/js/dojox/lang/tests/lambda.js b/includes/js/dojox/lang/tests/lambda.js new file mode 100644 index 0000000..7e5e7ed --- /dev/null +++ b/includes/js/dojox/lang/tests/lambda.js @@ -0,0 +1,24 @@ +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"); +dojo.require("dojox.lang.functional.sequence"); + +(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]); } + ]); +})(); + +} diff --git a/includes/js/dojox/lang/tests/listcomp.js b/includes/js/dojox/lang/tests/listcomp.js new file mode 100644 index 0000000..45cd8ab --- /dev/null +++ b/includes/js/dojox/lang/tests/listcomp.js @@ -0,0 +1,28 @@ +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.listcomp"); +dojo.require("dojox.lang.functional.sequence"); + +(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]); } + ]); +})(); + +} diff --git a/includes/js/dojox/lang/tests/main.js b/includes/js/dojox/lang/tests/main.js new file mode 100644 index 0000000..1f0d7ab --- /dev/null +++ b/includes/js/dojox/lang/tests/main.js @@ -0,0 +1,17 @@ +if(!dojo._hasResource["dojox.lang.tests.main"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.lang.tests.main"] = true; +dojo.provide("dojox.lang.tests.main"); + +try{ + // functional block + 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.array"); +}catch(e){ + doh.debug(e); +} + +} diff --git a/includes/js/dojox/lang/tests/misc.js b/includes/js/dojox/lang/tests/misc.js new file mode 100644 index 0000000..f17ea8c --- /dev/null +++ b/includes/js/dojox/lang/tests/misc.js @@ -0,0 +1,31 @@ +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.object"); +dojo.require("dojox.lang.functional.zip"); + +(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 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"); }, + function testKeys(t){ t.assertEqual(df.keys({a: 1, b: 2, c: 3}), ["a", "b", "c"]); }, + function testValues(t){ t.assertEqual(df.values({a: 1, b: 2, c: 3}), [1, 2, 3]); } + ]); +})(); + +} diff --git a/includes/js/dojox/lang/tests/runTests.html b/includes/js/dojox/lang/tests/runTests.html new file mode 100644 index 0000000..32fdfdb --- /dev/null +++ b/includes/js/dojox/lang/tests/runTests.html @@ -0,0 +1,9 @@ + + + DojoX Functional Unit Test Runner + + + +

Redirecting to D.O.H runner.

+ + -- cgit v1.2.3-54-g00ecf