Browse Source

Test Observable.partition;

bjorn 10 years ago
parent
commit
24863ec461
2 changed files with 21 additions and 0 deletions
  1. 1 0
      tests/observable.lua
  2. 20 0
      tests/partition.lua

+ 1 - 0
tests/observable.lua

@@ -165,6 +165,7 @@ describe('Observable', function()
   dofile('tests/min.lua')
   dofile('tests/min.lua')
   dofile('tests/merge.lua')
   dofile('tests/merge.lua')
   dofile('tests/pack.lua')
   dofile('tests/pack.lua')
+  dofile('tests/partition.lua')
   dofile('tests/pluck.lua')
   dofile('tests/pluck.lua')
   dofile('tests/reduce.lua')
   dofile('tests/reduce.lua')
   dofile('tests/reject.lua')
   dofile('tests/reject.lua')

+ 20 - 0
tests/partition.lua

@@ -0,0 +1,20 @@
+describe('partition', function()
+  it('errors when its parent errors', function()
+    local observable = Rx.Observable.fromValue(''):map(function(x) return x() end)
+    expect(observable.subscribe).to.fail()
+    expect(observable:partition().subscribe).to.fail()
+  end)
+
+  it('uses the identity function as the predicate if none is specified', function()
+    local pass, fail = Rx.Observable.fromTable({true, false, true}):partition()
+    expect(pass).to.produce(true, true)
+    expect(fail).to.produce(false)
+  end)
+
+  it('partitions the elements into two observables based on the predicate', function()
+    local function isEven(x) return x % 2 == 0 end
+    local pass, fail = Rx.Observable.fromRange(5):partition(isEven)
+    expect(pass).to.produce(2, 4)
+    expect(fail).to.produce(1, 3, 5)
+  end)
+end)