# 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
from __future__ import print_function



def test_sampling_and_containment(test_object, d, contained, not_contained):
  for _ in range(5):
    test_object.assertTrue(d.contains(d.sample()))
  for contained_spec in contained:
    try:
      contained = d.contains(contained_spec)
    except KeyError:
      # Having the wrong keys also indicate it is not contained.
      contained = False
    test_object.assertTrue(contained)
  for not_contained_spec in not_contained:
    try:
      contained = d.contains(not_contained_spec)
    except KeyError:
      contained = False
    test_object.assertFalse(contained)


class ContinuousTest(parameterized.TestCase):
  """Runs tests for Continuous distribution."""

  @parameterized.parameters(
      (0.0, 1.0, (-0.5, 2.0)),
      (-1.0, -0.1, (-1.4, 0.5)),
  )
  def testSamplingContainmentContinuous(self, minval, maxval, not_contained):

# 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

from __future__ import print_function



def test_sampling_and_containment(test_object, d, contained, not_contained):
  for _ in range(5):
    test_object.assertTrue(d.contains(d.sample()))
  for contained_spec in contained:
    try:
      contained = d.contains(contained_spec)
    except KeyError:
      # Having the wrong keys also indicate it is not contained.
      contained = False
    test_object.assertTrue(contained)
  for not_contained_spec in not_contained:
    try:
      contained = d.contains(not_contained_spec)
    except KeyError:
      contained = False
    test_object.assertFalse(contained)


class ContinuousTest(parameterized.TestCase):
  """Runs tests for Continuous distribution."""

  @parameterized.parameters(
      (0.0, 1.0, (-0.5, 2.0)),
      (-1.0, -0.1, (-1.4, 0.5)),
  )
  def testSamplingContainmentContinuous(self, minval, maxval, not_contained):

    d = distribs.Continuous('x', minval, maxval)