# Path: utils/replay_buffer.py
# class ReplayBuffer:
# class PrioritizedReplayBuffer:
#     def __init__(self, templates, capacity):
#     def _create_buffers(self, templates):
#     def reset(self):
#     def size(self):
#     def append(self, tensors):
#     def sample(self, nb_samples):
#     def get_all_buffers(self):
#     def __init__(self, templates, capactiy):
#     def size(self):
#     def append(self, priority, tensors):
#     def sample(self, amount, temperature=1):


import os, sys, unittest
import numpy as np
import tensorflow as tf
from utils import replay_buffer

dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(dir + '/../..')


class TestReplayBuffer(unittest.TestCase):

    def test_replay_buffer_init(self):
        templates = [('test1', tf.int32, ()), ('test2', tf.int32, (1,)), ('test3', tf.int32, (2, 2))]
        capacity = 2
        rep_buf = replay_buffer.ReplayBuffer(templates, capacity)

        sess = tf.InteractiveSession()
        sess.run(tf.global_variables_initializer())
        buffers = sess.run(rep_buf.buffers)

        self.assertEqual(np.array_equal(buffers['test1'], [0, 0]), True)
        self.assertEqual(np.array_equal(buffers['test2'], [ [0], [0] ]), True)
        self.assertEqual(np.array_equal(buffers['test3'], [ [[0, 0],[0, 0]], [[0, 0],[0, 0]] ]), True)

    def test_replay_buffer_append(self):
        templates = [('test1', tf.int32, ()), ('test2', tf.int32, (1,)), ('test3', tf.int32, (2, 2))]
        capacity = 2

# Path: utils/replay_buffer.py
# class ReplayBuffer:
# class PrioritizedReplayBuffer:
#     def __init__(self, templates, capacity):
#     def _create_buffers(self, templates):
#     def reset(self):
#     def size(self):
#     def append(self, tensors):
#     def sample(self, nb_samples):
#     def get_all_buffers(self):
#     def __init__(self, templates, capactiy):
#     def size(self):
#     def append(self, priority, tensors):
#     def sample(self, amount, temperature=1):


# Path: tests/utils/test_replay_buffer.py
import os, sys, unittest
import numpy as np
import tensorflow as tf
from utils import replay_buffer


dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(dir + '/../..')


class TestReplayBuffer(unittest.TestCase):

    def test_replay_buffer_init(self):
        templates = [('test1', tf.int32, ()), ('test2', tf.int32, (1,)), ('test3', tf.int32, (2, 2))]
        capacity = 2
        rep_buf = replay_buffer.ReplayBuffer(templates, capacity)

        sess = tf.InteractiveSession()
        sess.run(tf.global_variables_initializer())
        buffers = sess.run(rep_buf.buffers)

        self.assertEqual(np.array_equal(buffers['test1'], [0, 0]), True)
        self.assertEqual(np.array_equal(buffers['test2'], [ [0], [0] ]), True)
        self.assertEqual(np.array_equal(buffers['test3'], [ [[0, 0],[0, 0]], [[0, 0],[0, 0]] ]), True)

    def test_replay_buffer_append(self):
        templates = [('test1', tf.int32, ()), ('test2', tf.int32, (1,)), ('test3', tf.int32, (2, 2))]
        capacity = 2

        rep_buf = replay_buffer.ReplayBuffer(templates, capacity)