def test_totalAreaNormaliser_repr(self):

        with self.subTest(msg='Preserving magnitude'):

            tanorm = TotalAreaNormaliser(keepMagnitude=False)
            strform = str(tanorm)
            self.assertEqual(strform, 'Normalised to unit area.')

        with self.subTest(msg='Preserving magnitude'):

            tanorm = TotalAreaNormaliser(keepMagnitude=True)
            strform = str(tanorm)
            self.assertEqual(
                strform, 'Normalised to constant area, preserving magnitude.')
    def test_totalAreaNormaliser(self):
        """
		Check that the TotalAreaNormaliser works
		"""
        # Check if algorithm is being performed correctly
        tanorm = TotalAreaNormaliser(keepMagnitude=False)
        X = numpy.copy(self.X)
        x_normed = X / X.sum(axis=1)[:, None]

        numpy.testing.assert_array_almost_equal(
            x_normed,
            tanorm.normalise(X),
            err_msg="Total Area normaliser not working correctly")
        numpy.testing.assert_array_equal(X.sum(axis=1),
                                         tanorm.normalisation_coefficients)
    def test_totalAreaNormaliser_raises(self):

        tanorm = TotalAreaNormaliser(keepMagnitude=False)

        with self.subTest(msg='Not two dimensions'):

            X = numpy.random.randn(2, 2, 2)
            self.assertRaises(ValueError, tanorm.normalise, X)

            X = numpy.random.randn(2)
            self.assertRaises(ValueError, tanorm.normalise, X)
    def test_nullNormaliser_eq_(self):
        """
		Check that the NullNormaliser equality testing works
		"""
        with self.subTest():
            norm = NullNormaliser()
            norm2 = NullNormaliser()

            self.assertEqual(norm, norm2)

        pqn = ProbabilisticQuotientNormaliser()
        tanorm = TotalAreaNormaliser(keepMagnitude=False)
        tanorm2 = TotalAreaNormaliser(keepMagnitude=True)

        notEqualList = [
            1, True, 'str', 1.1,
            list(), dict(), tanorm, tanorm2, pqn
        ]
        norm = NullNormaliser()
        for comparison in notEqualList:
            with self.subTest(msg=comparison):
                self.assertNotEqual(norm, comparison)
    def test_totalAreaNormaliser_eq_(self):
        """
		Check that the TotalAreaNormaliser equality testing works
		"""
        with self.subTest(msg='Test keepMagnitude is respected'):
            tanorm = TotalAreaNormaliser(keepMagnitude=False)
            tanorm2 = TotalAreaNormaliser(keepMagnitude=False)
            tanorm3 = TotalAreaNormaliser(keepMagnitude=True)
            tanorm4 = TotalAreaNormaliser(keepMagnitude=True)

            self.assertEqual(tanorm, tanorm2)
            self.assertEqual(tanorm3, tanorm3)
            self.assertNotEqual(tanorm, tanorm3)

        pqn = ProbabilisticQuotientNormaliser()
        notEqualList = [
            1, True, 'str', 1.1,
            list(), dict(),
            NullNormaliser(), pqn
        ]
        tanorm = TotalAreaNormaliser()
        for comparison in notEqualList:
            with self.subTest(msg=comparison):
                self.assertNotEqual(tanorm, comparison)