2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.lang.tests.misc"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.lang.tests.misc"] = true;
|
|
|
3 |
dojo.provide("dojox.lang.tests.misc");
|
|
|
4 |
dojo.require("dojox.lang.functional");
|
|
|
5 |
|
|
|
6 |
(function(){
|
|
|
7 |
var df = dojox.lang.functional, fun = df.lambda("100*a + 10*b + c"), result = [];
|
|
|
8 |
df.forIn({a: 1, b: 2}, function(v, i){ result.push("[" + i + "] = " + v); });
|
|
|
9 |
|
|
|
10 |
tests.register("dojox.lang.tests.misc", [
|
|
|
11 |
function testZip1(t){ t.assertEqual(df.zip([1, 2, 3], [4, 5, 6]), [[1, 4], [2, 5], [3, 6]]); },
|
|
|
12 |
function testZip2(t){ t.assertEqual(df.zip([1, 2], [3, 4], [5, 6]), [[1, 3, 5], [2, 4, 6]]); },
|
|
|
13 |
|
|
|
14 |
function testUnzip1(t){ t.assertEqual(df.unzip([[1, 4], [2, 5], [3, 6]]), [[1, 2, 3], [4, 5, 6]]); },
|
|
|
15 |
function testUnzip2(t){ t.assertEqual(df.unzip([[1, 3, 5], [2, 4, 6]]), [[1, 2], [3, 4], [5, 6]]); },
|
|
|
16 |
|
|
|
17 |
function testConst1(t){ t.assertEqual(df.constFun(5)(), 5); },
|
|
|
18 |
function testConst2(t){ t.assertEqual(df.constFun(8)(), 8); },
|
|
|
19 |
|
|
|
20 |
function testInvoke1(t){ t.assertEqual(df.invoke("max")(Math, 1, 2), 2); },
|
|
|
21 |
function testInvoke2(t){ t.assertEqual(df.invoke("min")(Math, 1, 2), 1); },
|
|
|
22 |
|
|
|
23 |
function testPluck1(t){ t.assertEqual(df.pluck("PI")(Math), Math.PI); },
|
|
|
24 |
function testPluck2(t){ t.assertEqual(df.pluck("E")(Math), Math.E); },
|
|
|
25 |
|
|
|
26 |
function testMixer(t){ t.assertEqual(df.mixer(fun, [1, 2, 0])(3, 1, 2), 123); },
|
|
|
27 |
function testFlip(t){ t.assertEqual(df.flip(fun)(3, 2, 1), 123); },
|
|
|
28 |
|
|
|
29 |
function testCompose1(t){ t.assertEqual(df.lambda(["+5", "*3"])(8), 8 * 3 + 5); },
|
|
|
30 |
function testCompose2(t){ t.assertEqual(df.lambda(["+5", "*3"].reverse())(8), (8 + 5) * 3); },
|
|
|
31 |
|
|
|
32 |
function testForIn(t){ t.assertEqual(result.sort().join(", "), "[a] = 1, [b] = 2"); }
|
|
|
33 |
]);
|
|
|
34 |
})();
|
|
|
35 |
|
|
|
36 |
}
|