partition.lua 800 B

1234567891011121314151617181920
  1. describe('partition', function()
  2. it('errors when its parent errors', function()
  3. local observable = Rx.Observable.of(''):map(function(x) return x() end)
  4. expect(observable.subscribe).to.fail()
  5. expect(observable:partition().subscribe).to.fail()
  6. end)
  7. it('uses the identity function as the predicate if none is specified', function()
  8. local pass, fail = Rx.Observable.fromTable({true, false, true}):partition()
  9. expect(pass).to.produce(true, true)
  10. expect(fail).to.produce(false)
  11. end)
  12. it('partitions the elements into two observables based on the predicate', function()
  13. local function isEven(x) return x % 2 == 0 end
  14. local pass, fail = Rx.Observable.fromRange(5):partition(isEven)
  15. expect(pass).to.produce(2, 4)
  16. expect(fail).to.produce(1, 3, 5)
  17. end)
  18. end)