Example #1
0
    def test_numpyarray_fails(self):
        with pytest.raises(ValueError):
            equal_to(np.asarray(((1, 1), (1, 1))), 0)

        with pytest.raises(ValueError):
            equal_to(np.asarray(((1, 1), (1, 1))), np.asarray(
                ((0, 0), (0, 0))))
Example #2
0
def unit_vector(value: Union[Sequence[Num], Vector],
                name: Optional[AnyStr] = None):
    value = np_.asarray(value)

    try:
        dimensions(value, 1, name)
        equal_to(np_.linalg.norm(value), 1,
                 'norm({})'.format(name if name is not None else 'value'))
    except ValueError as ValueE:
        raise ValueError(
            'Expected `{}` to be a valid unit vector, but was not.'.format(
                name if name is not None else 'value', )) from ValueE
Example #3
0
def rotation_matrix(value: Union[Sequence[Sequence[Num]], Matrix],
                    name: Optional[AnyStr] = None):
    value = np_.asarray(value)

    try:
        dimensions(value, 2, name)
        shape(value, (3, 3), name)
        # greater_than_or_equal_to(value, -1, name)
        # less_than_or_equal_to(value, 1, name)
        equal_to(np_.abs(np_.linalg.det(value)), 1,
                 'det({})'.format(name if name is not None else 'value'))
    except ValueError as ValueE:
        raise ValueError(
            'Expected `{}` to be a valid rotation matrix, but was '
            'not.'.format(name if name is not None else 'value', )) from ValueE
Example #4
0
 def test_numpyarray_passes(self):
     equal_to(np.asarray(((1, 1), (1, 1))), 1)
     equal_to(np.asarray(((1, 1), (1, 1))), np.asarray(((1, 1), (1, 1))))
Example #5
0
 def test_list_of_list_fails(self):
     with pytest.raises(ValueError):
         equal_to(((1, 1), (1, 1)), 0)
     with pytest.raises(ValueError):
         equal_to(((1, 1), (1, 1)), ((0, 0), (0, 0)))
Example #6
0
 def test_list_of_list_passes(self):
     equal_to(((1, 1), (1, 1)), 1)
     equal_to(((1, 1), (1, 1)), ((1, 1), (1, 1)))
Example #7
0
    def test_list_fails(self):
        with pytest.raises(ValueError):
            equal_to([1, 1, 1, 1], 0)

        with pytest.raises(ValueError):
            equal_to([1, 1, 1, 1], [0, 0, 0, 0])
Example #8
0
 def test_list_passes(self):
     equal_to([1, 1, 1, 1], 1)
     equal_to([1, 1, 1, 1], [1, 1, 1, 1])
Example #9
0
 def test_scalar_passes(self):
     equal_to(1, 1)
     equal_to(0, 0)
     equal_to(-1, -1)