product.js 519 B

1234567891011121314151617181920212223242526
  1. var assert = require('assert');
  2. var Lazy = require('..');
  3. var expresso = expresso;
  4. function range(i, j) {
  5. var r = [];
  6. for (;i<j;i++) r.push(i);
  7. return r;
  8. }
  9. exports['product'] = function () {
  10. var lazy = new Lazy;
  11. var executed = 0;
  12. lazy.product(function (y) {
  13. executed++;
  14. assert.equal(y, 1*2*3*4*5*6*7*8*9);
  15. })
  16. range(1,10).forEach(function (x) {
  17. lazy.emit('data', x);
  18. });
  19. lazy.emit('end');
  20. assert.equal(executed, 1, 'product failed to execute');
  21. }