Пример #1
0
def test_equality():
    v1 = Vector([1, 2, 3])
    v2 = Vector([1, 2, 3])
    assert v1 == v2
Пример #2
0
def test_scalar_sum():
    v = Vector([1, 2, 3, 4, 5])
    assert v + 1 == Vector([2, 3, 4, 5, 6])
Пример #3
0
def test_scalar_rsum():
    v = Vector([1, 2, 3, 4, 5])
    assert 1 + v == Vector([2, 3, 4, 5, 6])
Пример #4
0
def test_dot_product():
    v1 = Vector([2, 3, 4])
    v2 = Vector([-2, 1, -3])
    assert v1 @ v2 == -13
Пример #5
0
def test_length():
    v = Vector([1, 2, 3, 4, 5])
    assert len(v) == 5
Пример #6
0
def test_scalar_rdifference():
    v = Vector([1, 2, 3, 4, 5])
    assert 1 - v == Vector([0, -1, -2, -3, -4])
Пример #7
0
def test_product():
    v = Vector([1, 2, 3])
    assert v * 3 == Vector([3, 6, 9])
Пример #8
0
def test_modification_with_wrong_value():
    v = Vector([1, 2, 3])
    with pytest.raises(ValueError):
        v[1] = 'abc'
Пример #9
0
def test_vector_sum():
    v1 = Vector([1, 2, 3, 4])
    v2 = Vector([3, 2, 4, 1])
    assert v1 + v2 == Vector([4, 4, 7, 5])
Пример #10
0
def test_index_error():
    v = Vector([1, 2, 3])
    with pytest.raises(IndexError):
        v[10]
Пример #11
0
def test_not_number():
    with pytest.raises(ValueError):
        Vector([1, 2, 'a'])
Пример #12
0
def test_string_representation():
    v = Vector([3, 2, 1])
    assert str(v) == '[3, 2, 1]'
Пример #13
0
def test_index_modification():
    v = Vector([4, 3, 0, 2, -1])
    v[3] = 5
    assert v[3] == 5
Пример #14
0
def test_index_access():
    v = Vector([4, 3, 0, 2, -1])
    assert v[3] == 2
Пример #15
0
def test_rsum_with_not_numerical_input():
    v = Vector([1, 2, 3, 4, 5])
    with pytest.raises(ValueError):
        'a' + v
Пример #16
0
def test_different_lengths_for_dot_product():
    v1 = Vector([1, 2, 3, 4])
    v2 = Vector([1, 2, 3])
    with pytest.raises(ValueError):
        v1 @ v2
Пример #17
0
def test_scalar_difference():
    v = Vector([1, 2, 3, 4, 5])
    assert v - 1 == Vector([0, 1, 2, 3, 4])
Пример #18
0
def test_different_lengths_for_difference():
    v1 = Vector([1, 2, 3, 4])
    v2 = Vector([1, 2, 3])
    with pytest.raises(ValueError):
        v1 - v2
Пример #19
0
def test_rdifference_with_not_numerical_input():
    v = Vector([1, 2, 3, 4, 5])
    with pytest.raises(ValueError):
        'a' - v
Пример #20
0
def test_norm():
    v = Vector([3, 4])
    assert v.norm() == 5
Пример #21
0
def test_rproduct():
    v = Vector([1, 2, 3])
    assert 3 * v == Vector([3, 6, 9])
Пример #22
0
def test_vector_difference():
    v1 = Vector([1, 2, 3, 4])
    v2 = Vector([3, 2, 4, 1])
    assert v1 - v2 == Vector([-2, 0, -1, 3])
Пример #23
0
def test_dot_product_with_not_numerical_input():
    v = Vector([1, 2, 3])
    with pytest.raises(ValueError):
        v @ 'a'
Пример #24
0
def test_inequality_with_not_vector():
    assert Vector() != 5