def test_joined_dreams(): recs1 = [Record(12, 34), Record(11, 123), Record(8, 5)] recs2 = [Record(11, 2), Record(8, 1), Record(3, 43)] joined_count = dream.of(recs1)\ .join(recs2, lambda rec: rec.id)\ .map(lambda rec: rec[0].count + rec[1].count)\ .into(sum) assert joined_count == 123 + 2 + 5 + 1 partial_joined = dream.join(recs2, lambda rec: rec.id) \ .map(lambda rec: rec[0].count + rec[1].count) \ .into(sum) assert partial_joined(recs1) == 123 + 2 + 5 + 1
def test_of_basic(): assert len(dream.of(range(3)).dask.items()) == 4
def test_foldby(): assert dream.of(range(30)).foldby(lambda n: n % 2, add).into(dict) == {0: 210, 1: 225}
def test_fold(): assert dream.of(range(3)).fold(add).compute() == sum(range(3))
def test_filter_basic(): assert dream.of(range(4)).filter(lambda n: n % 2 == 0).into(sum) == 2
def test_map_basic(): assert dream.of(range(7)).map(lambda n: n + 1).into(sum) == sum(map(lambda n: n + 1, range(7))) assert dream.of(range(3)).into(sum) == sum(range(3))