summaryrefslogtreecommitdiffstatshomepage
path: root/includes/js/dojox/lang/tests/fold.js
diff options
context:
space:
mode:
authorGravatar mensonge2008-11-13 09:49:11 +0000
committerGravatar mensonge2008-11-13 09:49:11 +0000
commite44a7e37b6c7b5961adaffc62b9042b8d442938e (patch)
tree95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojox/lang/tests/fold.js
parenta62b9742ee5e28bcec6872d88f50f25b820914f6 (diff)
downloadscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz
scuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.zip
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
Diffstat (limited to 'includes/js/dojox/lang/tests/fold.js')
-rw-r--r--includes/js/dojox/lang/tests/fold.js64
1 files changed, 64 insertions, 0 deletions
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]); }
+ ]);
+})();
+
+}