def test_sequence_equal_not_equal_left(self): scheduler = TestScheduler() msgs1 = [ on_next(110, 1), on_next(190, 2), on_next(240, 3), on_next(290, 4), on_next(310, 0), on_next(340, 6), on_next(450, 7), on_completed(510), ] msgs2 = [ on_next(90, 1), on_next(270, 3), on_next(280, 4), on_next(300, 5), on_next(330, 6), on_next(340, 7), on_completed(720), ] xs = scheduler.create_hot_observable(msgs1) ys = scheduler.create_hot_observable(msgs2) results = scheduler.start(lambda: xs.pipe(ops.sequence_equal(ys))) assert results.messages == [on_next(310, False), on_completed(310)] assert xs.subscriptions == [subscribe(200, 310)] assert ys.subscriptions == [subscribe(200, 310)]
def create(): def comparer(x, y): return x % 2 == y % 2 return xs.pipe( ops.sequence_equal([3 - 2, 4, 5 + 9, 6 + 42, 7 - 6], comparer) )
def test_sequence_equal_not_equal_4_sym(self): scheduler = TestScheduler() msgs1 = [on_next(250, 1), on_completed(300)] msgs2 = [on_next(290, 1), on_next(310, 2), on_completed(350)] xs = scheduler.create_hot_observable(msgs1) ys = scheduler.create_hot_observable(msgs2) results = scheduler.start(create=lambda: ys.pipe(ops.sequence_equal(xs))) assert results.messages == [on_next(310, False), on_completed(310)] assert xs.subscriptions == [subscribe(200, 300)] assert ys.subscriptions == [subscribe(200, 310)]
def open(self): print("WebSocket opened") # A Subject is both an observable and observer, so we can both subscribe # to it and also feed (on_next) it with new values self.subject: Subject[Dict[str, int]] = Subject() # Now we take on our magic glasses and project the stream of bytes into # a ... query = self.subject.pipe( # 1. stream of keycodes ops.map(lambda obj: obj["keycode"]), # 2. stream of windows (10 ints long) ops.window_with_count(10, 1), # 3. stream of booleans, True or False ops.flat_map(lambda win: win.pipe(ops.sequence_equal(codes))), # 4. stream of Trues ops.filter(lambda equal: equal), ) # 4. we then subscribe to the Trues, and signal Konami! if we see any query.subscribe(on_next=lambda x: self.write_message("Konami!"))
def test_sequence_equal_not_equal_2_sym(self): scheduler = TestScheduler() msgs1 = [ on_next(110, 1), on_next(190, 2), on_next(240, 3), on_next(290, 4), on_next(310, 5), on_next(340, 6), on_next(450, 7), on_next(490, 8), on_next(520, 9), on_next(580, 10), on_next(600, 11), ] msgs2 = [ on_next(90, 1), on_next(270, 3), on_next(280, 4), on_next(300, 5), on_next(330, 6), on_next(340, 7), on_next(350, 9), on_next(400, 9), on_next(410, 10), on_next(490, 11), on_next(550, 12), on_next(560, 13), ] xs = scheduler.create_hot_observable(msgs1) ys = scheduler.create_hot_observable(msgs2) results = scheduler.start(create=lambda: ys.pipe(ops.sequence_equal(xs))) assert results.messages == [on_next(490, False), on_completed(490)] assert xs.subscriptions == [subscribe(200, 490)] assert ys.subscriptions == [subscribe(200, 490)]
def create(): return xs.pipe(ops.sequence_equal([3, 4]))
def create(): return xs.pipe(ops.sequence_equal([3, 4, 5, 6, 7, 8]))
def create(): return xs.pipe( ops.sequence_equal([3, 4, 5, 6, 7], on_error_comparer(5, ex)) )
def create(): def comparer(a, b): raise Exception(ex) return ys.pipe(ops.sequence_equal(xs, comparer))