misc.js 2.0 KB

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