import unittest
import numpy as np
from bsym import ColourOperation
from unittest.mock import patch

class ColourOperationTestCase( unittest.TestCase ):
    """Tests for colour operation methods"""

    def test_symmetry_operation_is_initialised_from_a_matrix( self ):
        matrix = np.matrix( [ [ 1, 0 ], [ 0, 1 ] ] )
        mapping = [ { 1: 0, 0: 1 }, { 1: 1, 0: 0 } ]
        co = ColourOperation( matrix, colour_mapping=mapping )
        np.testing.assert_array_equal( co.matrix, matrix )
        self.assertEqual( co.colour_mapping, mapping )

    def test_from_vector( self ):
        vector = [ 2, 3, 1 ]
        mapping = [ { 1: 0, 0: 1 }, { 1: 1, 0: 0 } ]
        co = ColourOperation.from_vector( vector, mapping )
        np.testing.assert_array_equal( co.matrix, np.matrix( [ [ 0, 0, 1 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ] ) )
        self.assertEqual( co.colour_mapping, mapping )

    def test_from_vector_with_label( self ):
        vector = [ 2, 3, 1 ]
        mapping = [ { 1: 0, 0: 1 }, { 1: 1, 0: 0 } ]
        label = 'A'
        co = ColourOperation.from_vector( vector, mapping, label=label )
        np.testing.assert_array_equal( co.matrix, np.matrix( [ [ 0, 0, 1 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ] ) )
        self.assertEqual( co.label, label )
        self.assertEqual( co.colour_mapping, mapping )

    def test_symmetry_operation_is_initialised_with_label( self ):
        matrix = np.matrix( [ [ 1, 0 ], [ 0, 1 ] ] )
        label = 'E'
        mapping = [ { 1: 0, 0: 1 }, { 1: 1, 0: 0 } ]
        co = ColourOperation( matrix, mapping, label=label )
        self.assertEqual( co.label, label )
        self.assertEqual( co.colour_mapping, mapping )

    def test_from_vector_counting_from_zero( self ):
        vector = [ 1, 2, 0 ]
        mapping = [ { 1: 0, 0: 1 }, { 1: 1, 0: 0 } ]
        co = ColourOperation.from_vector( vector, mapping, count_from_zero=True )
        np.testing.assert_array_equal( co.matrix, np.matrix( [ [ 0, 0, 1 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ] ) )
        self.assertEqual( co.colour_mapping, mapping )

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

@@ -60,16 +60,31 @@
 peration
+, Configuration
 %0Afrom un
@@ -2061,16 +2061,1082 @@
 ping )%0A%0A
+    def test_operate_on( self ):%0A        matrix = np.matrix( %5B %5B 0, 1, 0 %5D, %5B 0, 0, 1 %5D, %5B 1, 0, 0 %5D %5D )%0A        colour_mapping = %5B %7B 1:1, 2:2, 3:3 %7D,%0A                           %7B 1:2, 2:3, 3:1 %7D,%0A                           %7B 1:3, 2:2, 3:1 %7D %5D%0A        co = ColourOperation( matrix, colour_mapping )%0A        configuration = Configuration( %5B 1, 2, 3 %5D )%0A        co.operate_on( configuration )%0A        np.testing.assert_array_equal( co.operate_on( configuration ).vector, np.array( %5B 2, 1, 3 %5D ) )%0A%0A    def test_mul( self ):%0A        matrix_a = np.array( %5B %5B 1, 1 %5D, %5B 0, 0 %5D %5D )%0A        colour_mapping_a = %5B %7B 0:1, 1:0 %7D, %7B 0:1, 1:0 %7D %5D%0A        matrix_b = np.array( %5B %5B 1, 0 %5D, %5B 1, 0 %5D %5D )%0A        colour_mapping_b = %5B %7B 0:1, 1:0 %7D, %7B 0:1, 1:0 %7D %5D%0A        co_a = ColourOperation( matrix_a, colour_mapping_a )%0A        co_b = ColourOperation( matrix_b, colour_mapping_b )%0A        co_c = co_a * co_b%0A        np.testing.assert_array_equal( co_c.matrix , np.array( %5B %5B 2, 0 %5D, %5B 0, 0 %5D %5D ) )%0A        self.assertEqual( co_c.colour_mapping, %5B %7B 0:0, 1:1 %7D, %7B 0:0, 1:1 %7D %5D )%0A%0A
 if __nam

Add unit tests