예제 #1
0
def test_problem1_7_scalar(xs, n, expected):
    v = Vector(*xs)
    assert v * n == Vector(*expected)
예제 #2
0
def test_problem1_6(xs, ys, expected):
    u, v = Vector(*xs), Vector(*ys)
    assert u - v == Vector(*expected)
예제 #3
0
def test_problem1_6_invalid():
    u, v = Vector(1, 2), Vector(1, 2, 3)
    with pytest.raises(ValueError):
        w = u - v
예제 #4
0
def test_problem1_4(xs, expected):
    v = Vector(*xs)
    assert -v == Vector(*expected)
    assert -(-v) == Vector(*xs)
예제 #5
0
def test_problem1_1(n):
    v = Vector(*list(range(n)))
예제 #6
0
def test_problem1_2(xs, expected):
    v = Vector(*xs)
    assert str(v) == expected
예제 #7
0
def test_problem1_3(n):
    v = Vector(*list(range(n)))
    assert len(v) == n
예제 #8
0
def test_problem1_8_invalid():
    u, v = Vector(1, 2), Vector(1, 2, 3)
    with pytest.raises(TypeError):
        w = u / v
    with pytest.raises(TypeError):
        w = u // v
예제 #9
0
def test_problem1_8_floordiv(xs, n, expected):
    v = Vector(*xs)
    assert v // n == Vector(*expected)
예제 #10
0
def test_problem1_8_truediv(xs, n, expected):
    v = Vector(*xs)
    assert v / n == Vector(*expected)
예제 #11
0
def test_problem1_7_dot_product(xs, ys, expected):
    u, v = Vector(*xs), Vector(*ys)
    assert u * v == expected
예제 #12
0
def test_problem1_1_invalid():
    with pytest.raises(ValueError):
        v = Vector()
    with pytest.raises(ValueError):
        v = Vector(1)