예제 #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