# Path: compiler_opt/rl/constant_value_network.py
# class ConstantValueNetwork(network.Network):
#   def __init__(self, input_tensor_spec, constant_output_val=0, name=None):
#   def call(self, observation, step_type=None, network_state=(), training=False):


import tensorflow as tf
from tf_agents.specs import tensor_spec
from compiler_opt.rl import constant_value_network
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for compiler_opt.rl.constant_value_network."""





class ConstantValueNetworkTest(tf.test.TestCase):

  def testBuilds(self):
    observation_spec = tensor_spec.BoundedTensorSpec((8, 8, 3), tf.float32, 0,
                                                     1)
    observation = tensor_spec.sample_spec_nest(
        observation_spec, outer_dims=(1,))

    net = constant_value_network.ConstantValueNetwork(
        input_tensor_spec=observation_spec, constant_output_val=0)

    value, _ = net(observation)
    self.assertAllEqual([0.], value)

  def testHandlesExtraOuterDims(self):
    observation_spec = tensor_spec.BoundedTensorSpec((8, 8, 3), tf.float32, 0,
                                                     1)
    observation = tensor_spec.sample_spec_nest(
        observation_spec, outer_dims=(2, 2))


# Path: compiler_opt/rl/constant_value_network.py
# class ConstantValueNetwork(network.Network):
#   def __init__(self, input_tensor_spec, constant_output_val=0, name=None):
#   def call(self, observation, step_type=None, network_state=(), training=False):


# Path: compiler_opt/rl/constant_value_network_test.py
import tensorflow as tf
from tf_agents.specs import tensor_spec
from compiler_opt.rl import constant_value_network

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for compiler_opt.rl.constant_value_network."""





class ConstantValueNetworkTest(tf.test.TestCase):

  def testBuilds(self):
    observation_spec = tensor_spec.BoundedTensorSpec((8, 8, 3), tf.float32, 0,
                                                     1)
    observation = tensor_spec.sample_spec_nest(
        observation_spec, outer_dims=(1,))

    net = constant_value_network.ConstantValueNetwork(
        input_tensor_spec=observation_spec, constant_output_val=0)

    value, _ = net(observation)
    self.assertAllEqual([0.], value)

  def testHandlesExtraOuterDims(self):
    observation_spec = tensor_spec.BoundedTensorSpec((8, 8, 3), tf.float32, 0,
                                                     1)
    observation = tensor_spec.sample_spec_nest(
        observation_spec, outer_dims=(2, 2))


    net = constant_value_network.ConstantValueNetwork(