import unittest
import numpy as np
from numpy.testing import assert_allclose
import theano

from keras.layers import core


class TestLayerBase(unittest.TestCase):
    def test_input_output(self):
        nb_samples = 10
        input_dim = 5
        layer = core.Layer()

        # As long as there is no input, an error should be raised.
        for train in [True, False]:
            self.assertRaises(AttributeError, layer.get_input, train)
            self.assertRaises(AttributeError, layer.get_output, train)

        # Once an input is provided, it should be reachable through the
        # appropriate getters
        input = np.ones((nb_samples, input_dim))
        layer.input = theano.shared(value=input)
        for train in [True, False]:
            assert_allclose(layer.get_input(train).eval(), input)
            assert_allclose(layer.get_output(train).eval(), input)

    def test_connections(self):
        nb_samples = 10
        input_dim = 5
        layer1 = core.Layer()
        layer2 = core.Layer()

        input = np.ones((nb_samples, input_dim))
        layer1.input = theano.shared(value=input)

        # As long as there is no previous layer, an error should be raised.
        for train in [True, False]:
            self.assertRaises(AttributeError, layer2.get_input, train)

        # After connecting, input of layer1 should be passed through
        layer2.set_previous(layer1)
        for train in [True, False]:
            assert_allclose(layer2.get_input(train).eval(), input)
            assert_allclose(layer2.get_output(train).eval(), input)




if __name__ == '__main__':
    unittest.main()

@@ -1582,16 +1582,1802 @@
 nput)%0A%0A%0A
+class TestConfigParams(unittest.TestCase):%0A    %22%22%22%0A    Test the constructor, config and params functions of all layers in core.%0A    %22%22%22%0A%0A    def _runner(self, layer):%0A        conf = layer.get_config()%0A        assert (type(conf) == dict)%0A%0A        param = layer.get_params()%0A        # Typically a list or a tuple, but may be any iterable%0A        assert hasattr(param, '__iter__')%0A%0A    def test_base(self):%0A        layer = core.Layer()%0A        self._runner(layer)%0A%0A    def test_masked(self):%0A        layer = core.MaskedLayer()%0A        self._runner(layer)%0A%0A    def test_merge(self):%0A        layer_1 = core.Layer()%0A        layer_2 = core.Layer()%0A        layer = core.Merge(%5Blayer_1, layer_2%5D)%0A        self._runner(layer)%0A%0A    def test_dropout(self):%0A        layer = core.Dropout(0.5)%0A        self._runner(layer)%0A%0A    def test_activation(self):%0A        layer = core.Activation('linear')%0A        self._runner(layer)%0A%0A    def test_reshape(self):%0A        layer = core.Reshape(10, 10)%0A        self._runner(layer)%0A%0A    def test_flatten(self):%0A        layer = core.Flatten()%0A        self._runner(layer)%0A%0A    def test_repeat_vector(self):%0A        layer = core.RepeatVector(10)%0A        self._runner(layer)%0A%0A    def test_dense(self):%0A        layer = core.Dense(10, 10)%0A        self._runner(layer)%0A%0A    def test_act_reg(self):%0A        layer = core.ActivityRegularization(0.5, 0.5)%0A        self._runner(layer)%0A%0A    def test_time_dist_dense(self):%0A        layer = core.TimeDistributedDense(10, 10)%0A        self._runner(layer)%0A%0A    def test_autoencoder(self):%0A        layer_1 = core.Layer()%0A        layer_2 = core.Layer()%0A%0A        layer = core.AutoEncoder(layer_1, layer_2)%0A        self._runner(layer)%0A%0A    def test_maxout_dense(self):%0A        layer = core.MaxoutDense(10, 10)%0A        self._runner(layer)%0A
 %0A%0Aif __n

Test the constructor, config and params functions of all core layers.