# Path: dreamer/tools/nested.py
# def zip_(*structures, **kwargs):
# def map_(function, *structures, **kwargs):
#   def impl(function, *structures):
# def flatten_(structure):
# def filter_(predicate, *structures, **kwargs):
#   def impl(predicate, *structures):


import collections
import pathlib
import sys
import tensorflow as tf
from dreamer.tools import nested

  def test_convert_type(self):
    self.assertEqual((1, 2, 3), nested.flatten([1, 2, 3]))

  def test_mixed_structure(self):
    self.assertEqual((1, 2, 3, 4), nested.flatten([(1, 2), 3, {'foo': [4]}]))

  def test_value_ordering(self):
    self.assertEqual((1, 2, 3), nested.flatten({'a': 1, 'b': 2, 'c': 3}))


class FilterTest(tf.test.TestCase):

  def test_empty(self):
    self.assertEqual({}, nested.filter(lambda x: True, {}))
    self.assertEqual({}, nested.filter(lambda x: False, {}))

  def test_base_case(self):
    self.assertEqual((), nested.filter(lambda x: False, 1))

  def test_single_dict(self):
    predicate = lambda x: x % 2 == 0
    data = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
    self.assertEqual({'b': 2, 'd': 4}, nested.filter(predicate, data))

  def test_multiple_lists(self):
    a = [1, 2, 3]
    b = [4, 5, 6]
    c = [7, 8, 9]
    predicate = lambda *args: any(x % 4 == 0 for x in args)

# Path: dreamer/tools/nested.py
# def zip_(*structures, **kwargs):
# def map_(function, *structures, **kwargs):
#   def impl(function, *structures):
# def flatten_(structure):
# def filter_(predicate, *structures, **kwargs):
#   def impl(predicate, *structures):


# Path: tests/test_nested.py
import collections
import pathlib
import sys
import tensorflow as tf
from dreamer.tools import nested


  def test_convert_type(self):
    self.assertEqual((1, 2, 3), nested.flatten([1, 2, 3]))

  def test_mixed_structure(self):
    self.assertEqual((1, 2, 3, 4), nested.flatten([(1, 2), 3, {'foo': [4]}]))

  def test_value_ordering(self):
    self.assertEqual((1, 2, 3), nested.flatten({'a': 1, 'b': 2, 'c': 3}))


class FilterTest(tf.test.TestCase):

  def test_empty(self):
    self.assertEqual({}, nested.filter(lambda x: True, {}))
    self.assertEqual({}, nested.filter(lambda x: False, {}))

  def test_base_case(self):
    self.assertEqual((), nested.filter(lambda x: False, 1))

  def test_single_dict(self):
    predicate = lambda x: x % 2 == 0
    data = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
    self.assertEqual({'b': 2, 'd': 4}, nested.filter(predicate, data))

  def test_multiple_lists(self):
    a = [1, 2, 3]
    b = [4, 5, 6]
    c = [7, 8, 9]
    predicate = lambda *args: any(x % 4 == 0 for x in args)

    result = nested.filter(predicate, a, b, c)