# Path: tensorflow_constrained_optimization/python/rates/helpers.py
# class RateObject(object):
# class UniqueList(RateObject):
# def convert_to_1d_tensor(tensor, name=None):
# def get_num_columns_of_2d_tensor(tensor, name="tensor"):
# def get_num_elements_of_tensor(tensor, name="tensor"):
#   def __init__(self, collection=None, element_type=None):
#   def list(self):
#   def append(self, element):
#   def __eq__(self, other):
#   def __ne__(self, other):
#   def __len__(self):
#   def __iter__(self):
#   def __add__(self, other):
#   def __radd__(self, other):
#   def __getitem__(self, slice_spec):


import tensorflow as tf
from tensorflow_constrained_optimization.python.rates import helpers
    # Trying to get the number of elements of a tensor with partially-unknown
    # shape should fail.
    tensor = tf.compat.v1.placeholder(tf.float32, shape=(1, None, 1))
    with self.assertRaises(ValueError):
      _ = helpers.get_num_elements_of_tensor(tensor)

    # Make sure that we successfully get the number of elements.
    tensor = tf.convert_to_tensor([[1, 2, 3], [4, 5, 6]])
    self.assertEqual(6, helpers.get_num_elements_of_tensor(tensor))


class UniqueListTest(tf.test.TestCase):
  """Tests for `UniqueList` classes."""

  def test_construct(self):
    """Tests the `UniqueList` constructor."""
    element1 = 1
    element2 = 2
    element3 = element1
    element4 = 4
    element5 = element4
    element6 = 6

    unique_list = helpers.UniqueList(
        [element1, element2, element3, element4, element5, element6])
    self.assertEqual(4, len(unique_list))
    self.assertEqual([element1, element2, element4, element6], unique_list.list)

  def test_append_raises(self):
    """Tests that "append" raises when given the wrong type."""

# Path: tensorflow_constrained_optimization/python/rates/helpers.py
# class RateObject(object):
# class UniqueList(RateObject):
# def convert_to_1d_tensor(tensor, name=None):
# def get_num_columns_of_2d_tensor(tensor, name="tensor"):
# def get_num_elements_of_tensor(tensor, name="tensor"):
#   def __init__(self, collection=None, element_type=None):
#   def list(self):
#   def append(self, element):
#   def __eq__(self, other):
#   def __ne__(self, other):
#   def __len__(self):
#   def __iter__(self):
#   def __add__(self, other):
#   def __radd__(self, other):
#   def __getitem__(self, slice_spec):


# Path: tensorflow_constrained_optimization/python/rates/helpers_test.py
import tensorflow as tf
from tensorflow_constrained_optimization.python.rates import helpers

    # Trying to get the number of elements of a tensor with partially-unknown
    # shape should fail.
    tensor = tf.compat.v1.placeholder(tf.float32, shape=(1, None, 1))
    with self.assertRaises(ValueError):
      _ = helpers.get_num_elements_of_tensor(tensor)

    # Make sure that we successfully get the number of elements.
    tensor = tf.convert_to_tensor([[1, 2, 3], [4, 5, 6]])
    self.assertEqual(6, helpers.get_num_elements_of_tensor(tensor))


class UniqueListTest(tf.test.TestCase):
  """Tests for `UniqueList` classes."""

  def test_construct(self):
    """Tests the `UniqueList` constructor."""
    element1 = 1
    element2 = 2
    element3 = element1
    element4 = 4
    element5 = element4
    element6 = 6

    unique_list = helpers.UniqueList(
        [element1, element2, element3, element4, element5, element6])
    self.assertEqual(4, len(unique_list))
    self.assertEqual([element1, element2, element4, element6], unique_list.list)

  def test_append_raises(self):
    """Tests that "append" raises when given the wrong type."""

    unique_list = helpers.UniqueList(element_type=list)