123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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]);
- }]);
- })();
- }
|