# Path: telluride_decoding/result_store.py
# class NumpyStore(object):
# class WindowedDataStore(NumpyStore):
# class TwoResultStore(object):
#   def __init__(self, init_frame_count=10000, name='Generic'):
#   def count(self):
#   def all_data(self):
#   def create_storage(self, data):
#   def _grow_storage(self, data):
#   def add_data(self, data):
#   def next_window(self, window_size):
#   def __init__(self, window_step=100, window_width=None, pre_context=0,
#                initial_frame_count=100):
#   def create_storage(self, data):
#   def next_window(self):
#   def __init__(self, window_width=100, window_step=100, pre_context=0,
#                initial_frame_count=100):
#   def all_data(self):
#   def add_data(self, s1, s2):
#   def next_window(self):


from absl.testing import absltest
from telluride_decoding import result_store
import numpy as np




class NumpyStoreTest(absltest.TestCase):

  def test_storage(self):
    """Makes sure our storage class doesn't lose data."""
    num_points = 10000
    num_dims = 5
    data = np.random.randn(num_points, num_dims)
    storage = result_store.NumpyStore(init_frame_count=100)
    frame_chunk_size = 33
    count = 0
    while count < num_points:
      e = min(num_points, count + frame_chunk_size)
      storage.add_data(data[count:e, :])
      count = e
    np.testing.assert_array_equal(storage.all_data, data)
    self.assertEqual(storage.count, num_points)

  def test_storage_errors(self):
    with self.assertRaisesRegex(ValueError,
                                'Initial frame count must be greater than 0'):
      storage = result_store.NumpyStore(init_frame_count=0)

    storage = result_store.NumpyStore()
    self.assertFalse(storage.all_data)

    with self.assertRaisesRegex(TypeError, 'data must be a 2D numpy array'):

# Path: telluride_decoding/result_store.py
# class NumpyStore(object):
# class WindowedDataStore(NumpyStore):
# class TwoResultStore(object):
#   def __init__(self, init_frame_count=10000, name='Generic'):
#   def count(self):
#   def all_data(self):
#   def create_storage(self, data):
#   def _grow_storage(self, data):
#   def add_data(self, data):
#   def next_window(self, window_size):
#   def __init__(self, window_step=100, window_width=None, pre_context=0,
#                initial_frame_count=100):
#   def create_storage(self, data):
#   def next_window(self):
#   def __init__(self, window_width=100, window_step=100, pre_context=0,
#                initial_frame_count=100):
#   def all_data(self):
#   def add_data(self, s1, s2):
#   def next_window(self):


# Path: test/result_store_test.py
from absl.testing import absltest
from telluride_decoding import result_store
import numpy as np





class NumpyStoreTest(absltest.TestCase):

  def test_storage(self):
    """Makes sure our storage class doesn't lose data."""
    num_points = 10000
    num_dims = 5
    data = np.random.randn(num_points, num_dims)
    storage = result_store.NumpyStore(init_frame_count=100)
    frame_chunk_size = 33
    count = 0
    while count < num_points:
      e = min(num_points, count + frame_chunk_size)
      storage.add_data(data[count:e, :])
      count = e
    np.testing.assert_array_equal(storage.all_data, data)
    self.assertEqual(storage.count, num_points)

  def test_storage_errors(self):
    with self.assertRaisesRegex(ValueError,
                                'Initial frame count must be greater than 0'):
      storage = result_store.NumpyStore(init_frame_count=0)

    storage = result_store.NumpyStore()
    self.assertFalse(storage.all_data)

    with self.assertRaisesRegex(TypeError, 'data must be a 2D numpy array'):

      storage = result_store.WindowedDataStore()