# Path: compiler_opt/rl/data_collector.py
# DEADLINE_IN_SECONDS = 30
# WAIT_TERMINATION = ((0.9, 0), (0.8, 0.5), (0, 1))
# REWARD_QUANTILE_MONITOR = (0.1, 0.5, 1, 2, 3, 4, 5, 6, 8, 10, 20, 30, 40, 50,
#                            60, 70, 80, 90, 95, 99, 99.5, 99.9)
# def build_distribution_monitor(data: Sequence[float]) -> Dict[str, float]:
#   def collect_data(
#       self, policy_path: str
#   ) -> Tuple[Iterator[trajectory.Trajectory], Dict[str, float]]:
#   def on_dataset_consumed(self,
#                           dataset_iterator: Iterator[trajectory.Trajectory]):
#   def __init__(self,  # pylint: disable=dangerous-default-value
#                num_modules: int,
#                deadline: float = DEADLINE_IN_SECONDS,
#                thresholds: Tuple[Tuple[float, float], ...] = WAIT_TERMINATION):
#   def _should_exit(self, collected: int):
#   def wait(self, get_num_finished_work):
#   def waited_time(self):
# class DataCollector(metaclass=abc.ABCMeta):
# class EarlyExitChecker:


from unittest import mock
from absl.testing import absltest
from compiler_opt.rl import data_collector
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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 data_collector."""





class DataCollectorTest(absltest.TestCase):

  def test_build_distribution_monitor(self):
    data = [3, 2, 1]
    monitor_dict = data_collector.build_distribution_monitor(data)
    self.assertDictContainsSubset({'mean': 2, 'p_0.1': 1}, monitor_dict)

  @mock.patch('time.time')
  def test_early_exit(self, mock_time):
    mock_time.return_value = 0

# Path: compiler_opt/rl/data_collector.py
# DEADLINE_IN_SECONDS = 30
# WAIT_TERMINATION = ((0.9, 0), (0.8, 0.5), (0, 1))
# REWARD_QUANTILE_MONITOR = (0.1, 0.5, 1, 2, 3, 4, 5, 6, 8, 10, 20, 30, 40, 50,
#                            60, 70, 80, 90, 95, 99, 99.5, 99.9)
# def build_distribution_monitor(data: Sequence[float]) -> Dict[str, float]:
#   def collect_data(
#       self, policy_path: str
#   ) -> Tuple[Iterator[trajectory.Trajectory], Dict[str, float]]:
#   def on_dataset_consumed(self,
#                           dataset_iterator: Iterator[trajectory.Trajectory]):
#   def __init__(self,  # pylint: disable=dangerous-default-value
#                num_modules: int,
#                deadline: float = DEADLINE_IN_SECONDS,
#                thresholds: Tuple[Tuple[float, float], ...] = WAIT_TERMINATION):
#   def _should_exit(self, collected: int):
#   def wait(self, get_num_finished_work):
#   def waited_time(self):
# class DataCollector(metaclass=abc.ABCMeta):
# class EarlyExitChecker:


# Path: compiler_opt/rl/data_collector_test.py
from unittest import mock
from absl.testing import absltest
from compiler_opt.rl import data_collector

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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 data_collector."""





class DataCollectorTest(absltest.TestCase):

  def test_build_distribution_monitor(self):
    data = [3, 2, 1]
    monitor_dict = data_collector.build_distribution_monitor(data)
    self.assertDictContainsSubset({'mean': 2, 'p_0.1': 1}, monitor_dict)

  @mock.patch('time.time')
  def test_early_exit(self, mock_time):
    mock_time.return_value = 0

    early_exit = data_collector.EarlyExitChecker(