reduce.js 883 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import assert from 'assert';
  2. describe('reduce', () => {
  3. it('reduces without a seed', async () => {
  4. await Observable.from([1, 2, 3, 4, 5, 6]).reduce((a, b) => {
  5. return a + b;
  6. }).forEach(x => {
  7. assert.equal(x, 21);
  8. });
  9. });
  10. it('errors if empty and no seed', async () => {
  11. try {
  12. await Observable.from([]).reduce((a, b) => {
  13. return a + b;
  14. }).forEach(() => null);
  15. assert.ok(false);
  16. } catch (err) {
  17. assert.ok(true);
  18. }
  19. });
  20. it('reduces with a seed', async () => {
  21. Observable.from([1, 2, 3, 4, 5, 6]).reduce((a, b) => {
  22. return a + b;
  23. }, 100).forEach(x => {
  24. assert.equal(x, 121);
  25. });
  26. });
  27. it('reduces an empty list with a seed', async () => {
  28. await Observable.from([]).reduce((a, b) => {
  29. return a + b;
  30. }, 100).forEach(x => {
  31. assert.equal(x, 100);
  32. });
  33. });
  34. });