curry.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. if (!dojo._hasResource["dojox.lang.tests.curry"]) { // _hasResource checks added
  2. // by build. Do not use
  3. // _hasResource directly in
  4. // your code.
  5. dojo._hasResource["dojox.lang.tests.curry"] = true;
  6. dojo.provide("dojox.lang.tests.curry");
  7. dojo.require("dojox.lang.functional");
  8. (function() {
  9. var df = dojox.lang.functional, add5 = df.curry("+")(5), sub3 = df
  10. .curry("_-3"), fun = df.lambda("100*a + 10*b + c");
  11. tests.register("dojox.lang.tests.curry", [function testCurry1(t) {
  12. t.assertEqual(df.curry("+")(1, 2), 3);
  13. }, function testCurry2(t) {
  14. t.assertEqual(df.curry("+")(1)(2), 3);
  15. }, function testCurry3(t) {
  16. t.assertEqual(df.curry("+")(1, 2, 3), 3);
  17. }, function testCurry4(t) {
  18. t.assertEqual(add5(1), 6);
  19. }, function testCurry5(t) {
  20. t.assertEqual(add5(3), 8);
  21. }, function testCurry6(t) {
  22. t.assertEqual(add5(5), 10);
  23. }, function testCurry7(t) {
  24. t.assertEqual(sub3(1), -2);
  25. }, function testCurry8(t) {
  26. t.assertEqual(sub3(3), 0);
  27. }, function testCurry9(t) {
  28. t.assertEqual(sub3(5), 2);
  29. },
  30. function testPartial1(t) {
  31. t.assertEqual(df.partial(fun, 1, 2, 3)(), 123);
  32. }, function testPartial2(t) {
  33. t
  34. .assertEqual(
  35. df.partial(fun, 1, 2, df.arg)(3),
  36. 123);
  37. }, function testPartial3(t) {
  38. t
  39. .assertEqual(
  40. df.partial(fun, 1, df.arg, 3)(2),
  41. 123);
  42. }, function testPartial4(t) {
  43. t.assertEqual(df.partial(fun, 1, df.arg, df.arg)(2,
  44. 3), 123);
  45. }, function testPartial5(t) {
  46. t
  47. .assertEqual(
  48. df.partial(fun, df.arg, 2, 3)(1),
  49. 123);
  50. }, function testPartial6(t) {
  51. t.assertEqual(df.partial(fun, df.arg, 2, df.arg)(1,
  52. 3), 123);
  53. }, function testPartial7(t) {
  54. t.assertEqual(df.partial(fun, df.arg, df.arg, 3)(1,
  55. 2), 123);
  56. }, function testPartial8(t) {
  57. t.assertEqual(df.partial(fun, df.arg, df.arg,
  58. df.arg)(1, 2, 3), 123);
  59. }]);
  60. })();
  61. }