<s> try : <EOL> import unittest2 as unittest <EOL> except : <EOL> import unittest <EOL> import numpy as np <EOL> from pyrr import matrix33 , quaternion , vector3 <EOL> class test_matrix33 ( unittest . TestCase ) : <EOL> def test_import ( self ) : <EOL> import pyrr <EOL> pyrr . matrix33 <EOL> from pyrr import matrix33 <EOL> def test_create_from_quaternion_unit ( self ) : <EOL> result = matrix33 . create_from_quaternion ( [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] ) <EOL> np . testing . assert_almost_equal ( result , np . eye ( <NUM_LIT:3> ) , decimal = <NUM_LIT:5> ) <EOL> self . assertTrue ( result . dtype == np . float ) <EOL> def test_create_from_quaternion_x ( self ) : <EOL> result = matrix33 . create_from_quaternion ( [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] ) <EOL> expected = [ <EOL> [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , - <NUM_LIT:1.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT:0.> , - <NUM_LIT:1.> ] , <EOL> ] <EOL> np . testing . assert_almost_equal ( result , expected , decimal = <NUM_LIT:5> ) <EOL> self . assertTrue ( result . dtype == np . float ) <EOL> def test_create_from_quaternion_y ( self ) : <EOL> result = matrix33 . create_from_quaternion ( [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] ) <EOL> expected = [ <EOL> [ - <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT:0.> , - <NUM_LIT:1.> ] , <EOL> ] <EOL> np . testing . assert_almost_equal ( result , expected , decimal = <NUM_LIT:5> ) <EOL> self . assertTrue ( result . dtype == np . float ) <EOL> def test_create_from_quaternion_z ( self ) : <EOL> result = matrix33 . create_from_quaternion ( [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ] ) <EOL> expected = [ <EOL> [ - <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , - <NUM_LIT:1.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] , <EOL> ] <EOL> np . testing . assert_almost_equal ( result , expected , decimal = <NUM_LIT:5> ) <EOL> self . assertTrue ( result . dtype == np . float ) <EOL> def test_create_from_quaternion_rotation ( self ) : <EOL> result = matrix33 . create_from_quaternion ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.> ] ) <EOL> expected = [ <EOL> [ - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ] , <EOL> ] <EOL> np . testing . assert_almost_equal ( result , expected , decimal = <NUM_LIT:5> ) <EOL> self . assertTrue ( result . dtype == np . float ) <EOL> def test_create_from_quaternion_equivalent ( self ) : <EOL> result = matrix33 . create_from_quaternion ( quaternion . create_from_x_rotation ( <NUM_LIT:0.5> ) ) <EOL> expected = matrix33 . create_from_x_rotation ( <NUM_LIT:0.5> ) <EOL> np . testing . assert_almost_equal ( result , expected , decimal = <NUM_LIT:5> ) <EOL> self . assertTrue ( result . dtype == np . float ) <EOL> def test_inverse_equivalence ( self ) : <EOL> q = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> result = matrix33 . create_from_quaternion ( quaternion . inverse ( q ) ) <EOL> expected = matrix33 . inverse ( matrix33 . create_from_quaternion ( q ) ) <EOL> np . testing . assert_almost_equal ( result , expected , decimal = <NUM_LIT:5> ) <EOL> q = quaternion . create_from_x_rotation ( <NUM_LIT:0.5> ) <EOL> result = matrix33 . create_from_inverse_of_quaternion ( q ) <EOL> expected = matrix33 . inverse ( matrix33 . create_from_quaternion ( q ) ) <EOL> np . testing . assert_almost_equal ( result , expected , decimal = <NUM_LIT:5> ) <EOL> def test_create_from_inverse_of_quaternion ( self ) : <EOL> q = quaternion . create_from_x_rotation ( np . pi / <NUM_LIT> ) <EOL> result = matrix33 . create_from_inverse_of_quaternion ( q ) <EOL> self . assertTrue ( np . allclose ( result , matrix33 . create_from_x_rotation ( - np . pi / <NUM_LIT> ) ) ) <EOL> def test_create_identity ( self ) : <EOL> result = matrix33 . create_identity ( ) <EOL> np . testing . assert_almost_equal ( result , np . eye ( <NUM_LIT:3> ) , decimal = <NUM_LIT:5> ) <EOL> self . assertTrue ( result . dtype == np . float ) <EOL> def create_from_matrix44 ( self ) : <EOL> m44 = np . arange ( ( <NUM_LIT:4> , <NUM_LIT:4> ) ) <EOL> result = matrix33 . create_from_matrix44 ( m44 ) <EOL> self . assertTrue ( np . allclose ( result , m44 [ : <NUM_LIT:3> ] [ : <NUM_LIT:3> ] ) ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_create_from_eulers ( self ) : <EOL> matrix33 . create_from_eulers ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> def test_create_from_axis_rotation ( self ) : <EOL> result = matrix33 . create_from_axis_rotation ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , np . pi ) <EOL> np . testing . assert_almost_equal ( result , matrix33 . create_from_quaternion ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) , decimal = <NUM_LIT:3> ) <EOL> self . assertTrue ( result . dtype == np . float ) <EOL> def test_create_from_axis_rotation_non_normalised ( self ) : <EOL> result = matrix33 . create_from_axis_rotation ( [ <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:1.> ] , np . pi ) <EOL> np . testing . assert_almost_equal ( result , matrix33 . create_from_quaternion ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) , decimal = <NUM_LIT:3> ) <EOL> self . assertTrue ( result . dtype == np . float ) <EOL> def test_create_from_x_rotation ( self ) : <EOL> mat = matrix33 . create_from_x_rotation ( np . pi / <NUM_LIT> ) <EOL> self . assertTrue ( np . allclose ( np . dot ( [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , mat ) , [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] ) ) <EOL> self . assertTrue ( np . allclose ( np . dot ( [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ] , mat ) , [ <NUM_LIT:0.> , <NUM_LIT:0.> , - <NUM_LIT:1.> ] ) ) <EOL> self . assertTrue ( np . allclose ( np . dot ( [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] , mat ) , [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ] ) ) <EOL> def test_create_from_y_rotation ( self ) : <EOL> mat = matrix33 . create_from_y_rotation ( np . pi / <NUM_LIT> ) <EOL> self . assertTrue ( np . allclose ( np . dot ( [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , mat ) , [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] ) ) <EOL> self . assertTrue ( np . allclose ( np . dot ( [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ] , mat ) , [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ] ) ) <EOL> self . assertTrue ( np . allclose ( np . dot ( [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] , mat ) , [ - <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] ) ) <EOL> def test_create_from_z_rotation ( self ) : <EOL> mat = matrix33 . create_from_z_rotation ( np . pi / <NUM_LIT> ) <EOL> self . assertTrue ( np . allclose ( np . dot ( [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , mat ) , [ <NUM_LIT:0.> , - <NUM_LIT:1.> , <NUM_LIT:0.> ] ) ) <EOL> self . assertTrue ( np . allclose ( np . dot ( [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ] , mat ) , [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] ) ) <EOL> self . assertTrue ( np . allclose ( np . dot ( [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] , mat ) , [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] ) ) <EOL> def test_create_from_scale ( self ) : <EOL> scale = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> mat = matrix33 . create_from_scale ( scale ) <EOL> result = mat . diagonal ( ) <EOL> expected = scale <EOL> self . assertTrue ( np . array_equal ( result , expected ) ) <EOL> def test_create_from_quaternion_identity ( self ) : <EOL> quat = quaternion . create ( ) <EOL> result = matrix33 . create_from_quaternion ( quat ) <EOL> expected = np . eye ( <NUM_LIT:3> ) <EOL> self . assertTrue ( np . array_equal ( result , expected ) ) <EOL> def test_create_from_quaternion_rotated_x ( self ) : <EOL> quat = quaternion . create_from_x_rotation ( np . pi ) <EOL> result = matrix33 . create_from_quaternion ( quat ) <EOL> expected = matrix33 . create_from_x_rotation ( np . pi ) <EOL> self . assertTrue ( np . allclose ( result , expected ) ) <EOL> def test_create_from_quaternion_rotated_y ( self ) : <EOL> quat = quaternion . create_from_y_rotation ( np . pi ) <EOL> result = matrix33 . create_from_quaternion ( quat ) <EOL> expected = matrix33 . create_from_y_rotation ( np . pi ) <EOL> self . assertTrue ( np . allclose ( result , expected ) ) <EOL> def test_create_from_quaternion_rotated_z ( self ) : <EOL> quat = quaternion . create_from_z_rotation ( np . pi ) <EOL> result = matrix33 . create_from_quaternion ( quat ) <EOL> expected = matrix33 . create_from_z_rotation ( np . pi ) <EOL> self . assertTrue ( np . allclose ( result , expected ) ) <EOL> def test_apply_to_vector_identity ( self ) : <EOL> mat = matrix33 . create_identity ( ) <EOL> vec = vector3 . unit . x <EOL> result = matrix33 . apply_to_vector ( mat , vec ) <EOL> expected = vec <EOL> self . assertTrue ( np . array_equal ( result , expected ) ) <EOL> def test_apply_to_vector_rotated_x ( self ) : <EOL> mat = matrix33 . create_from_x_rotation ( np . pi ) <EOL> vec = vector3 . unit . y <EOL> result = matrix33 . apply_to_vector ( mat , vec ) <EOL> expected = - vec <EOL> self . assertTrue ( np . allclose ( result , expected ) ) <EOL> def test_apply_to_vector_rotated_y ( self ) : <EOL> mat = matrix33 . create_from_y_rotation ( np . pi ) <EOL> vec = vector3 . unit . x <EOL> result = matrix33 . apply_to_vector ( mat , vec ) <EOL> expected = - vec <EOL> self . assertTrue ( np . allclose ( result , expected ) ) <EOL> def test_apply_to_vector_rotated_z ( self ) : <EOL> mat = matrix33 . create_from_z_rotation ( np . pi ) <EOL> vec = vector3 . unit . x <EOL> result = matrix33 . apply_to_vector ( mat , vec ) <EOL> expected = - vec <EOL> self . assertTrue ( np . allclose ( result , expected ) ) <EOL> def test_multiply_identity ( self ) : <EOL> m1 = matrix33 . create_identity ( ) <EOL> m2 = matrix33 . create_identity ( ) <EOL> result = matrix33 . multiply ( m1 , m2 ) <EOL> self . assertTrue ( np . allclose ( result , np . dot ( m1 , m2 ) ) ) <EOL> def test_multiply_rotation ( self ) : <EOL> m1 = matrix33 . create_from_x_rotation ( np . pi ) <EOL> m2 = matrix33 . create_from_y_rotation ( np . pi / <NUM_LIT> ) <EOL> result = matrix33 . multiply ( m1 , m2 ) <EOL> self . assertTrue ( np . allclose ( result , np . dot ( m1 , m2 ) ) ) <EOL> def test_inverse ( self ) : <EOL> m = matrix33 . create_from_y_rotation ( np . pi ) <EOL> result = matrix33 . inverse ( m ) <EOL> self . assertTrue ( np . allclose ( result , matrix33 . create_from_y_rotation ( - np . pi ) ) ) <EOL> def test_create_direction_scale ( self ) : <EOL> m = matrix33 . create_direction_scale ( [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ] , <NUM_LIT:0.5> ) <EOL> v = np . array ( [ <EOL> [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:1.> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> ] ) <EOL> result = np . array ( [ <EOL> matrix33 . apply_to_vector ( m , v [ <NUM_LIT:0> ] ) , <EOL> matrix33 . apply_to_vector ( m , v [ <NUM_LIT:1> ] ) , <EOL> matrix33 . apply_to_vector ( m , v [ <NUM_LIT:2> ] ) , <EOL> ] ) <EOL> expected = np . array ( [ <EOL> [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT:1.> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> ] ) <EOL> self . assertTrue ( np . allclose ( result , expected ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
