# Path: spriteworld/factor_distributions.py
# _MAX_TRIES = int(1e5)
# class AbstractDistribution(object):
# class Continuous(AbstractDistribution):
# class Discrete(AbstractDistribution):
# class Mixture(AbstractDistribution):
# class Intersection(AbstractDistribution):
# class Product(AbstractDistribution):
# class SetMinus(AbstractDistribution):
# class Selection(AbstractDistribution):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def __str__(self):
#   def _get_rng(self, rng=None):
#   def keys(self):
#   def __init__(self, key, minval, maxval, dtype='float32'):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, key, candidates, probs=None):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, components, probs=None):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, components, index_for_sampling=0):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, components):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, base, hold_out):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, base, filtering):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):


from absl.testing import absltest
from absl.testing import parameterized
from six.moves import range
from spriteworld import factor_distributions as distribs
    contained = [{'x': value} for value in contained]
    not_contained = [{'x': value} for value in not_contained]
    test_sampling_and_containment(self, d, contained, not_contained)

  def testRaisesError(self):
    c_0 = distribs.Discrete('x', [0])
    c_1 = distribs.Discrete('y', [1])
    with self.assertRaises(ValueError):
      distribs.Mixture((c_0, c_1))

  def testProbs(self):
    c_0 = distribs.Discrete('x', [0])
    c_1 = distribs.Discrete('x', [1])
    d_0 = distribs.Mixture([c_0, c_1], probs=(0.3, 0.7))
    d_1 = distribs.Mixture([c_0, c_1], probs=(0.0, 1.0))
    for _ in range(5):
      self.assertTrue(d_0.contains(d_0.sample()))
    for _ in range(5):
      self.assertEqual(d_1.sample(), {'x': 1})


class IntersectionTest(parameterized.TestCase):
  """Runs tests for Intersection of distributions."""

  @parameterized.named_parameters(
      ('ContinuousContinuous', distribs.Continuous(
          'x', 0, 2), distribs.Continuous('x', 1, 3), [1.5], [0.5, 2.5]),
      ('DiscreteDiscrete', distribs.Discrete(
          'x', [0, 1]), distribs.Discrete('x', [1, 2]), [1], [0, 2]),
      ('DiscreteContinuous', distribs.Discrete(

# Path: spriteworld/factor_distributions.py
# _MAX_TRIES = int(1e5)
# class AbstractDistribution(object):
# class Continuous(AbstractDistribution):
# class Discrete(AbstractDistribution):
# class Mixture(AbstractDistribution):
# class Intersection(AbstractDistribution):
# class Product(AbstractDistribution):
# class SetMinus(AbstractDistribution):
# class Selection(AbstractDistribution):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def __str__(self):
#   def _get_rng(self, rng=None):
#   def keys(self):
#   def __init__(self, key, minval, maxval, dtype='float32'):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, key, candidates, probs=None):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, components, probs=None):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, components, index_for_sampling=0):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, components):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, base, hold_out):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):
#   def __init__(self, base, filtering):
#   def sample(self, rng=None):
#   def contains(self, spec):
#   def to_str(self, indent):
#   def keys(self):


# Path: tests/factor_distributions_test.py
from absl.testing import absltest
from absl.testing import parameterized
from six.moves import range
from spriteworld import factor_distributions as distribs

    contained = [{'x': value} for value in contained]
    not_contained = [{'x': value} for value in not_contained]
    test_sampling_and_containment(self, d, contained, not_contained)

  def testRaisesError(self):
    c_0 = distribs.Discrete('x', [0])
    c_1 = distribs.Discrete('y', [1])
    with self.assertRaises(ValueError):
      distribs.Mixture((c_0, c_1))

  def testProbs(self):
    c_0 = distribs.Discrete('x', [0])
    c_1 = distribs.Discrete('x', [1])
    d_0 = distribs.Mixture([c_0, c_1], probs=(0.3, 0.7))
    d_1 = distribs.Mixture([c_0, c_1], probs=(0.0, 1.0))
    for _ in range(5):
      self.assertTrue(d_0.contains(d_0.sample()))
    for _ in range(5):
      self.assertEqual(d_1.sample(), {'x': 1})


class IntersectionTest(parameterized.TestCase):
  """Runs tests for Intersection of distributions."""

  @parameterized.named_parameters(
      ('ContinuousContinuous', distribs.Continuous(
          'x', 0, 2), distribs.Continuous('x', 1, 3), [1.5], [0.5, 2.5]),
      ('DiscreteDiscrete', distribs.Discrete(
          'x', [0, 1]), distribs.Discrete('x', [1, 2]), [1], [0, 2]),
      ('DiscreteContinuous', distribs.Discrete(

          'x', [1, 3]), distribs.Continuous('x', 0, 2), [1], [0.5, 1.5, 3]),