def test_raise_exception__contains__(self): """ Tests :func:`colour.continuous.multi_signals.MultiSignals.__contains__` method raised exception. """ self.assertRaises(RuntimeError, operator.contains, MultiSignals(), 0)
def test__repr__(self): """ Test :meth:`colour.continuous.multi_signals.MultiSignals.__repr__` method. """ self.assertEqual( re.sub( r"extrapolator_kwargs={.*}", "extrapolator_kwargs={...}", repr(self._multi_signals), ), textwrap.dedent(""" MultiSignals([[ 0., 10., 20., 30.], [ 1., 20., 30., 40.], [ 2., 30., 40., 50.], [ 3., 40., 50., 60.], [ 4., 50., 60., 70.], [ 5., 60., 70., 80.], [ 6., 70., 80., 90.], [ 7., 80., 90., 100.], [ 8., 90., 100., 110.], [ 9., 100., 110., 120.]], labels=['0', '1', '2'], interpolator=KernelInterpolator, interpolator_kwargs={}, extrapolator=Extrapolator, extrapolator_kwargs={...})""")[1:], ) self.assertIsInstance(repr(MultiSignals()), str)
def test__repr__(self): """ Tests :func:`colour.continuous.multi_signals.MultiSignals.__repr__` method. """ self.assertEqual( re.sub(r'extrapolator_args={.*}', 'extrapolator_args={...}', repr(self._multi_signals)), textwrap.dedent(""" MultiSignals([[ 0., 10., 20., 30.], [ 1., 20., 30., 40.], [ 2., 30., 40., 50.], [ 3., 40., 50., 60.], [ 4., 50., 60., 70.], [ 5., 60., 70., 80.], [ 6., 70., 80., 90.], [ 7., 80., 90., 100.], [ 8., 90., 100., 110.], [ 9., 100., 110., 120.]], labels=[0, 1, 2], interpolator=KernelInterpolator, interpolator_args={}, extrapolator=Extrapolator, extrapolator_args={...})""")[1:]) self.assertIsInstance(repr(MultiSignals()), string_types)
def test_raise_exception_function(self): """ Test :func:`colour.continuous.signal.multi_signals.MultiSignals.\ function` property raised exception. """ self.assertRaises((ValueError, TypeError), MultiSignals().function, 0)
def test_raise_exception_function(self): """ Tests :func:`colour.continuous.signal.multi_signals.MultiSignals` property raised exception. """ self.assertRaises(RuntimeError, MultiSignals().function, 0)
def test_signal_type(self): """ Tests :func:`colour.continuous.multi_signals.MultiSignals.signal_type` property. """ multi_signals = MultiSignals(signal_type=Signal) self.assertEqual(multi_signals.signal_type, Signal)
def setUp(self): """Initialise the common tests attributes.""" self._range_1 = np.linspace(10, 100, 10) self._range_2 = tstack([self._range_1] * 3) + np.array([0, 10, 20]) self._domain_1 = np.arange(0, 10, 1) self._domain_2 = np.arange(100, 1100, 100) self._multi_signals = MultiSignals(self._range_2)
def test__init__(self): """ Tests :func:`colour.continuous.multi_signals.MultiSignals.__init__` method. """ multi_signals = MultiSignals(self._range_1) np.testing.assert_array_equal(multi_signals.domain, self._domain_1) np.testing.assert_array_equal(multi_signals.range, self._range_1[:, np.newaxis]) multi_signals = MultiSignals(self._range_1, self._domain_2) np.testing.assert_array_equal(multi_signals.domain, self._domain_2) np.testing.assert_array_equal(multi_signals.range, self._range_1[:, np.newaxis]) multi_signals = MultiSignals(self._range_2, self._domain_2) np.testing.assert_array_equal(multi_signals.domain, self._domain_2) np.testing.assert_array_equal(multi_signals.range, self._range_2) multi_signals = MultiSignals(dict(zip(self._domain_2, self._range_2))) np.testing.assert_array_equal(multi_signals.domain, self._domain_2) np.testing.assert_array_equal(multi_signals.range, self._range_2) multi_signals = MultiSignals(multi_signals) np.testing.assert_array_equal(multi_signals.domain, self._domain_2) np.testing.assert_array_equal(multi_signals.range, self._range_2) class NotSignal(Signal): """ Not :class:`Signal` class. """ pass multi_signals = MultiSignals(self._range_1, signal_type=NotSignal) self.assertIsInstance(multi_signals.signals[0], NotSignal) np.testing.assert_array_equal(multi_signals.domain, self._domain_1) np.testing.assert_array_equal(multi_signals.range, self._range_1[:, np.newaxis]) if is_pandas_installed(): from pandas import DataFrame, Series multi_signals = MultiSignals( Series(dict(zip(self._domain_2, self._range_1)))) np.testing.assert_array_equal(multi_signals.domain, self._domain_2) np.testing.assert_array_equal(multi_signals.range, self._range_1[:, np.newaxis]) data = dict(zip(['a', 'b', 'c'], tsplit(self._range_2))) multi_signals = MultiSignals(DataFrame(data, self._domain_2)) np.testing.assert_array_equal(multi_signals.domain, self._domain_2) np.testing.assert_array_equal(multi_signals.range, self._range_2)
def test_to_dataframe(self): """ Tests :func:`colour.continuous.multi_signals.MultiSignals.to_dataframe` method. """ if is_pandas_installed(): from pandas import DataFrame data = dict(zip(['a', 'b', 'c'], tsplit(self._range_2))) assert MultiSignals(self._range_2, self._domain_2, labels=['a', 'b', 'c']).to_dataframe().equals( DataFrame(data, self._domain_2))
def test_to_dataframe(self): """ Test :meth:`colour.continuous.multi_signals.MultiSignals.to_dataframe` method. """ if is_pandas_installed(): from pandas import DataFrame data = dict(zip(["a", "b", "c"], tsplit(self._range_2))) attest( MultiSignals(self._range_2, self._domain_2, labels=["a", "b", "c"]).to_dataframe().equals( DataFrame(data, self._domain_2)))
def test__str__(self): """ Tests :func:`colour.continuous.multi_signals.MultiSignals.__str__` method. """ self.assertEqual( str(self._multi_signals), textwrap.dedent(""" [[ 0. 10. 20. 30.] [ 1. 20. 30. 40.] [ 2. 30. 40. 50.] [ 3. 40. 50. 60.] [ 4. 50. 60. 70.] [ 5. 60. 70. 80.] [ 6. 70. 80. 90.] [ 7. 80. 90. 100.] [ 8. 90. 100. 110.] [ 9. 100. 110. 120.]]""")[1:]) self.assertIsInstance(str(MultiSignals()), string_types)